| 1 | ################################################################################ |
1 | ################################################################################ |
| 2 | # WeBWorK Online Homework Delivery System |
2 | # WeBWorK Online Homework Delivery System |
| 3 | # Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/ |
3 | # Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/ |
| 4 | # $CVSHeader: webwork-modperl/lib/WeBWorK/Authen.pm,v 1.20 2003/12/09 01:12:30 sh002i Exp $ |
4 | # $CVSHeader: webwork-modperl/lib/WeBWorK/Authen.pm,v 1.22 2003/12/23 06:03:33 sh002i Exp $ |
| 5 | # |
5 | # |
| 6 | # This program is free software; you can redistribute it and/or modify it under |
6 | # This program is free software; you can redistribute it and/or modify it under |
| 7 | # the terms of either: (a) the GNU General Public License as published by the |
7 | # the terms of either: (a) the GNU General Public License as published by the |
| 8 | # Free Software Foundation; either version 2, or (at your option) any later |
8 | # Free Software Foundation; either version 2, or (at your option) any later |
| 9 | # version, or (b) the "Artistic License" which comes with this package. |
9 | # version, or (b) the "Artistic License" which comes with this package. |
| … | |
… | |
| 133 | |
133 | |
| 134 | my $user = $r->param('user'); |
134 | my $user = $r->param('user'); |
| 135 | my $passwd = $r->param('passwd'); |
135 | my $passwd = $r->param('passwd'); |
| 136 | my $key = $r->param('key'); |
136 | my $key = $r->param('key'); |
| 137 | my $force_passwd_authen = $r->param('force_passwd_authen'); |
137 | my $force_passwd_authen = $r->param('force_passwd_authen'); |
| 138 | |
138 | my $login_practice_user = $r->param('login_practice_user'); |
|
|
139 | my $send_cookie = $r->param("send_cookie"); |
| 139 | my $error; |
140 | my $error; |
| 140 | my $failWithoutError = 0; |
141 | my $failWithoutError = 0; |
| 141 | |
142 | |
| 142 | VERIFY: { |
143 | VERIFY: { |
| 143 | # This block is here so we can "last" out of it when we've |
144 | # This block is here so we can "last" out of it when we've |
| 144 | # decided whether we're going to succeed or fail. |
145 | # decided whether we're going to succeed or fail. |
|
|
146 | |
|
|
147 | if ($login_practice_user) { |
|
|
148 | # ignore everything else, find an unused practice user |
|
|
149 | my $found = 0; |
|
|
150 | foreach my $userID (sort grep m/^$practiceUserPrefix/, $db->listUsers) { |
|
|
151 | if (not $self->unexpiredKeyExists($userID)) { |
|
|
152 | my $Key = $self->generateKey($userID); |
|
|
153 | $db->addKey($Key); |
|
|
154 | $r->param("user", $userID); |
|
|
155 | $r->param("key", $Key->key); |
|
|
156 | $found = 1; |
|
|
157 | last; |
|
|
158 | } |
|
|
159 | } |
|
|
160 | unless ($found) { |
|
|
161 | $error = "No practice users are available. Please try again in a few minutes."; |
|
|
162 | } |
|
|
163 | last VERIFY; |
|
|
164 | } |
| 145 | |
165 | |
| 146 | # no authentication data was given. this is OK. |
166 | # no authentication data was given. this is OK. |
| 147 | unless (defined $user or defined $passwd or defined $key) { |
167 | unless (defined $user or defined $passwd or defined $key) { |
| 148 | # check to see if a cookie was sent by the browser. if so, use the |
168 | # check to see if a cookie was sent by the browser. if so, use the |
| 149 | # user and key from the cookie for authentication. note that the |
169 | # user and key from the cookie for authentication. note that the |
| 150 | # cookie is only used if no credentials are sent as parameters. |
170 | # cookie is only used if no credentials are sent as parameters. |
| 151 | my ($cookieUser, $cookieKey) = $self->checkCookie; |
171 | my ($cookieUser, $cookieKey) = $self->checkCookie; |
| 152 | if ($cookieUser and $cookieKey) { |
172 | if ($cookieUser and $cookieKey) { |
| 153 | $r->param("user", $cookieUser); |
|
|
| 154 | $r->param("key", $cookieKey); |
|
|
| 155 | $user = $cookieUser; |
173 | $user = $cookieUser; |
| 156 | $key = $cookieKey; |
174 | $key = $cookieKey; |
|
|
175 | $r->param("user", $user); |
|
|
176 | $r->param("key", $key); |
| 157 | } else { |
177 | } else { |
| 158 | $failWithoutError = 1; |
178 | $failWithoutError = 1; |
| 159 | last VERIFY; |
179 | last VERIFY; |
| 160 | } |
180 | } |
| 161 | } |
181 | } |
| … | |
… | |
| 271 | # authentication failed, but not in a bad way |
291 | # authentication failed, but not in a bad way |
| 272 | return 0; |
292 | return 0; |
| 273 | } else { |
293 | } else { |
| 274 | # autentication succeeded! |
294 | # autentication succeeded! |
| 275 | # send a cookie with the user and key that were accepted. |
295 | # send a cookie with the user and key that were accepted. |
| 276 | if ($r->param("send_cookie")) { |
296 | if ($send_cookie and not $login_practice_user) { |
| 277 | $self->sendCookie($r->param("user"), $r->param("key")); |
297 | $self->sendCookie($r->param("user"), $r->param("key")); |
| 278 | } |
298 | } |
| 279 | return 1; |
299 | return 1; |
| 280 | } |
300 | } |
| 281 | |
301 | |