| … | |
… | |
| 10 | |
10 | |
| 11 | package Apache::WeBWorK; |
11 | package Apache::WeBWorK; |
| 12 | |
12 | |
| 13 | use strict; |
13 | use strict; |
| 14 | use Apache::Constants qw(:common REDIRECT); |
14 | use Apache::Constants qw(:common REDIRECT); |
|
|
15 | use Apache::Request; |
| 15 | use WeBWorK::CourseEnvironment; |
16 | use WeBWorK::CourseEnvironment; |
| 16 | use Apache::Request; |
17 | use WeBWorK::Test; |
|
|
18 | #use WeBWorK::Authen; |
| 17 | |
19 | |
| 18 | # registering discontent: wanted to call this dispatch, but mod_perl gave me lip |
20 | # registering discontent: wanted to call this dispatch, but mod_perl gave me lip |
| 19 | sub handler() { |
21 | sub handler() { |
| 20 | my $r = Apache::Request->new(shift); # have to deal with unpredictable GET or POST data ,and sift through it for the key. So use Apache::Request |
22 | my $r = Apache::Request->new(shift); # have to deal with unpredictable GET or POST data ,and sift through it for the key. So use Apache::Request |
| 21 | my $path_info = $r->path_info; |
23 | my $path_info = $r->path_info; |
| … | |
… | |
| 24 | unless ($path_info) { |
26 | unless ($path_info) { |
| 25 | $r->header_out(Location => "$current_uri/"); |
27 | $r->header_out(Location => "$current_uri/"); |
| 26 | return REDIRECT; |
28 | return REDIRECT; |
| 27 | } |
29 | } |
| 28 | |
30 | |
| 29 | $r->content_type('text/html'); |
|
|
| 30 | $r->send_http_header; |
|
|
| 31 | return OK if $r->header_only; |
31 | return OK if $r->header_only; |
| 32 | my($junk, @components) = split "/", $path_info; |
32 | my($junk, @components) = split "/", $path_info; |
| 33 | my $webwork_root = $r->dir_config('webwork_root'); # From a PerlSetVar in httpd.conf |
33 | my $webwork_root = $r->dir_config('webwork_root'); # From a PerlSetVar in httpd.conf |
| 34 | my $course = shift @components; |
34 | my $course = shift @components; |
| 35 | # catch errors in $@ |
35 | # catch errors in $@ |
| 36 | my $course_env = eval {WeBWorK::CourseEnvironment->new($webwork_root, $course);}; |
36 | my $course_env = eval {WeBWorK::CourseEnvironment->new($webwork_root, $course);}; |
| 37 | if ($@) { |
37 | if ($@) { |
| 38 | # TODO: display an error page. For now, print something mildly useful |
38 | # TODO: display an error page. For now, print something mildly useful |
| 39 | $r->print('<p><font color=red>'.$@.'</font></p>'); |
39 | return DECLINED; |
| 40 | } |
40 | } |
| 41 | |
41 | |
| 42 | # These values are part of the standard webwork form, and at least two |
42 | # if (!WeBWorK::Authen->new($r, $course_env)->authen) { |
| 43 | # of them should appear in every form on the system. Depending on when |
43 | # return WeBWorK::Login->new($r, $course_env)->go(); |
| 44 | # you are reading this, this may or may not be enforced in the code. |
44 | # } else { |
| 45 | $user = $r->param('user'); |
45 | if (1) { |
| 46 | $passwd = $r->param('passwd'); |
46 | return WeBWorK::Test->new($r, $course_env)->go(); |
| 47 | $key = $r->param('key'); |
47 | } |
|
|
48 | # } |
| 48 | |
49 | |
| 49 | |
50 | |
| 50 | |
51 | |
| 51 | $r->print(<<END); |
52 | $r->print(<<END); |
| 52 | COURSE = $course<br> |
53 | COURSE = $course<br> |