Annotation of loncom/interface/createaccount.pm, revision 1.77
1.1 raeburn 1: # The LearningOnline Network
2: # Allow visitors to create a user account with the username being either an
1.58 raeburn 3: # institutional log-in ID (institutional authentication required - localauth,
4: # kerberos, or SSO) or an e-mail address. Requests to use an e-mail address as
5: # username may be processed automatically, or may be queued for approval.
1.1 raeburn 6: #
1.77 ! raeburn 7: # $Id: createaccount.pm,v 1.76 2017/11/12 20:42:52 raeburn Exp $
1.1 raeburn 8: #
9: # Copyright Michigan State University Board of Trustees
10: #
11: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
12: #
13: # LON-CAPA is free software; you can redistribute it and/or modify
14: # it under the terms of the GNU General Public License as published by
15: # the Free Software Foundation; either version 2 of the License, or
16: # (at your option) any later version.
17: #
18: # LON-CAPA is distributed in the hope that it will be useful,
19: # but WITHOUT ANY WARRANTY; without even the implied warranty of
20: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21: # GNU General Public License for more details.
22: #
23: # You should have received a copy of the GNU General Public License
24: # along with LON-CAPA; if not, write to the Free Software
25: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26: #
27: # /home/httpd/html/adm/gpl.txt
28: #
29: # http://www.lon-capa.org/
30: #
31: #
32: package Apache::createaccount;
33:
34: use strict;
35: use Apache::Constants qw(:common);
36: use Apache::lonacc;
37: use Apache::lonnet;
38: use Apache::loncommon;
1.12 raeburn 39: use Apache::lonhtmlcommon;
1.77 ! raeburn 40: use Apache::lonuserutils;
1.1 raeburn 41: use Apache::lonlocal;
1.3 raeburn 42: use Apache::lonauth;
1.1 raeburn 43: use Apache::resetpw;
44: use DynaLoader; # for Crypt::DES version
45: use Crypt::DES;
1.3 raeburn 46: use LONCAPA qw(:DEFAULT :match);
1.8 raeburn 47: use HTML::Entities;
1.1 raeburn 48:
49: sub handler {
50: my $r = shift;
51: &Apache::loncommon::content_type($r,'text/html');
52: $r->send_http_header;
53: if ($r->header_only) {
54: return OK;
55: }
1.22 raeburn 56:
1.5 raeburn 57: my $domain;
1.3 raeburn 58:
1.57 raeburn 59: my $sso_username = $r->subprocess_env->get('SSOUserUnknown');
60: my $sso_domain = $r->subprocess_env->get('SSOUserDomain');
1.5 raeburn 61:
1.56 raeburn 62: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.61 raeburn 63: ['token','courseid','domain','type']);
1.27 raeburn 64: &Apache::lonacc::get_posted_cgi($r);
65: &Apache::lonlocal::get_language_handle($r);
66:
1.5 raeburn 67: if ($sso_username ne '' && $sso_domain ne '') {
68: $domain = $sso_domain;
1.27 raeburn 69: } else {
1.56 raeburn 70: ($domain, undef) = Apache::lonnet::is_course($env{'form.courseid'});
71: unless ($domain) {
72: if ($env{'form.phase'} =~ /^username_(activation|validation)$/) {
73: if (($env{'form.udom'} =~ /^$match_domain$/) &&
74: (&Apache::lonnet::domain($env{'form.udom'}) ne '')) {
75: $domain = $env{'form.udom'};
76: } else {
77: $domain = &Apache::lonnet::default_login_domain();
78: }
79: } elsif (($env{'form.phase'} eq '') &&
80: ($env{'form.domain'} =~ /^$match_domain$/) &&
81: (&Apache::lonnet::domain($env{'form.domain'}) ne '')) {
82: $domain = $env{'form.domain'};
83: } else {
84: $domain = &Apache::lonnet::default_login_domain();
85: }
86: }
1.5 raeburn 87: }
1.1 raeburn 88: my $domdesc = &Apache::lonnet::domain($domain,'description');
89: my $contact_name = &mt('LON-CAPA helpdesk');
1.15 raeburn 90: my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
91: my $contacts =
92: &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',
93: $domain,$origmail);
94: my ($contact_email) = split(',',$contacts);
1.1 raeburn 95: my $lonhost = $r->dir_config('lonHostID');
96: my $include = $r->dir_config('lonIncludes');
1.4 raeburn 97: my $start_page;
1.3 raeburn 98:
99: my $handle = &Apache::lonnet::check_for_valid_session($r);
1.30 raeburn 100: if (($handle ne '') && ($handle !~ /^publicuser_\d+$/)) {
1.4 raeburn 101: $start_page =
1.3 raeburn 102: &Apache::loncommon::start_page('Already logged in');
103: my $end_page =
104: &Apache::loncommon::end_page();
105: $r->print($start_page."\n".'<h2>'.&mt('You are already logged in').'</h2>'.
1.58 raeburn 106: '<p>'.&mt('Please either [_1]continue the current session[_2] or [_3]log out[_4].',
107: '<a href="/adm/roles">','</a>','<a href="/adm/logout">','</a>').
1.6 bisitz 108: '</p><p><a href="/adm/loginproblems.html">'.&mt('Login problems?').'</a></p>'.$end_page);
1.20 raeburn 109: return OK;
110: }
111:
1.22 raeburn 112: my ($js,$courseid,$title);
1.48 droeschl 113: $courseid = Apache::lonnet::is_course($env{'form.courseid'});
1.22 raeburn 114: if ($courseid ne '') {
115: $js = &catreturn_js();
116: $title = 'Self-enroll in a LON-CAPA course';
117: } else {
118: $title = 'Create a user account in LON-CAPA';
119: }
1.20 raeburn 120: if ($env{'form.phase'} eq 'selfenroll_login') {
1.22 raeburn 121: $title = 'Self-enroll in a LON-CAPA course';
1.4 raeburn 122: if ($env{'form.udom'} ne '') {
123: $domain = $env{'form.udom'};
124: }
1.35 raeburn 125:
126: my %domconfig =
127: &Apache::lonnet::get_dom('configuration',['usercreation'],$domain);
1.73 raeburn 128: my ($cancreate,$statustocreate) =
1.35 raeburn 129: &get_creation_controls($domain,$domconfig{'usercreation'});
130:
1.20 raeburn 131: my ($result,$output) =
132: &username_validation($r,$env{'form.uname'},$domain,$domdesc,
133: $contact_name,$contact_email,$courseid,
1.35 raeburn 134: $lonhost,$statustocreate);
1.58 raeburn 135: if ($result eq 'redirect') {
136: $r->internal_redirect('/adm/switchserver');
137: return OK;
138: } elsif ($result eq 'existingaccount') {
1.20 raeburn 139: $r->print($output);
1.22 raeburn 140: &print_footer($r);
1.20 raeburn 141: return OK;
142: } else {
1.51 raeburn 143: $start_page = &Apache::loncommon::start_page($title,$js);
1.22 raeburn 144: &print_header($r,$start_page,$courseid);
145: $r->print($output);
146: &print_footer($r);
1.20 raeburn 147: return OK;
148: }
1.4 raeburn 149: }
1.3 raeburn 150:
1.73 raeburn 151: my %domconfig =
1.35 raeburn 152: &Apache::lonnet::get_dom('configuration',['usercreation'],$domain);
1.73 raeburn 153: my ($cancreate,$statustocreate,$statusforemail,$emailusername,
1.74 raeburn 154: $emailoptions,$verification,$emaildomain,$types,$usertypes,$othertitle) =
1.58 raeburn 155: &get_creation_controls($domain,$domconfig{'usercreation'});
1.73 raeburn 156: my ($additems,$pagetitle);
157: if (ref($cancreate) eq 'ARRAY') {
158: unless (($env{'form.token'}) || ($sso_username ne '') || ($env{'form.phase'}) ||
159: ($env{'form.create_with_email'})) {
160: if ((grep(/^email$/,@{$cancreate})) && (ref($statusforemail) eq 'ARRAY')) {
161: my $usertype = &get_usertype($domain);
1.74 raeburn 162: if ((($usertype eq '') || (!grep(/^\Q$usertype\E$/,@{$statusforemail}))) &&
163: (@{$statusforemail} > 0)) {
1.73 raeburn 164: $js .= &setelements_js($statusforemail,$types,$usertypes,$othertitle);
165: $additems = {'add_entries' => { 'onload' => "setElements();"} };
1.74 raeburn 166: if ((@{$cancreate} == 1) && (@{$statusforemail} > 0)) {
1.73 raeburn 167: $pagetitle = 'Select affiliation';
168: }
1.74 raeburn 169: } else {
170: $js .= &username_js();
1.73 raeburn 171: }
172: }
173: }
174: }
175: $start_page = &Apache::loncommon::start_page($title,$js,$additems);
1.35 raeburn 176: if (@{$cancreate} == 0) {
1.73 raeburn 177: &print_header($r,$start_page,$courseid,$pagetitle);
1.14 raeburn 178: my $output = '<h3>'.&mt('Account creation unavailable').'</h3>'.
179: '<span class="LC_warning">'.
1.73 raeburn 180: &mt('Creation of a new user account using an institutional log-in ID or e-mail verification is not permitted for: [_1].',$domdesc).
1.58 raeburn 181: '</span><br /><br />';
1.3 raeburn 182: $r->print($output);
1.22 raeburn 183: &print_footer($r);
1.3 raeburn 184: return OK;
185: }
186:
1.5 raeburn 187: if ($sso_username ne '') {
1.22 raeburn 188: &print_header($r,$start_page,$courseid);
1.18 raeburn 189: my ($msg,$sso_logout);
190: $sso_logout = &sso_logout_frag($r,$domain);
1.35 raeburn 191: if (grep(/^sso$/,@{$cancreate})) {
1.14 raeburn 192: $msg = '<h3>'.&mt('Account creation').'</h3>'.
1.17 raeburn 193: &mt("Although your username and password were authenticated by your institution's Single Sign On system, you do not currently have a LON-CAPA account at this institution.").'<br />';
1.65 raeburn 194: my $shibenv;
195: if (($r->dir_config('lonOtherAuthen') eq 'yes') &&
196: ($r->dir_config('lonOtherAuthenType') eq 'Shibboleth')) {
197: if (ref($domconfig{'usercreation'}) eq 'HASH') {
198: if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
199: if (ref($domconfig{'usercreation'}{'cancreate'}{'shibenv'}) eq 'HASH') {
200: my @possfields = ('firstname','middlename','lastname','generation',
201: 'permanentemail','id');
202: $shibenv= {};
203: foreach my $key (keys(%{$domconfig{'usercreation'}{'cancreate'}{'shibenv'}})) {
204: if ($key eq 'inststatus') {
205: if (ref($usertypes) eq 'HASH') {
206: if ($domconfig{'usercreation'}{'cancreate'}{'shibenv'}{$key} ne '') {
207: if (exists($usertypes->{$domconfig{'usercreation'}{'cancreate'}{'shibenv'}{$key}})) {
208: $shibenv->{$key} = $domconfig{'usercreation'}{'cancreate'}{'shibenv'}{$key};
209: }
210: }
211: }
212: } elsif (grep(/^\Q$key\E/,@possfields)) {
213: if ($domconfig{'usercreation'}{'cancreate'}{'shibenv'}{$key} ne '') {
214: $shibenv->{$key} = $domconfig{'usercreation'}{'cancreate'}{'shibenv'}{$key};
215: }
216: }
217: }
218: }
219: }
220: }
221: }
1.18 raeburn 222: $msg .= &username_check($sso_username,$domain,$domdesc,$courseid,
1.35 raeburn 223: $lonhost,$contact_email,$contact_name,
1.65 raeburn 224: $sso_logout,$statustocreate,$shibenv);
1.5 raeburn 225: } else {
1.17 raeburn 226: $msg = '<h3>'.&mt('Account creation unavailable').'</h3>'.
227: '<span class="LC_warning">'.&mt("Although your username and password were authenticated by your institution's Single Sign On system, you do not currently have a LON-CAPA account at this institution, and you are not permitted to create one.").'</span><br /><br />'.&mt('Please contact the [_1] ([_2]) for assistance.',$contact_name,$contact_email).'<hr />'.
1.18 raeburn 228: $sso_logout;
1.5 raeburn 229: }
1.17 raeburn 230: $r->print($msg);
1.22 raeburn 231: &print_footer($r);
1.5 raeburn 232: return OK;
233: }
234:
1.58 raeburn 235: my ($output,$nostart,$noend,$redirect);
1.3 raeburn 236: my $token = $env{'form.token'};
237: if ($token) {
1.58 raeburn 238: ($output,$nostart,$noend,$redirect) =
1.3 raeburn 239: &process_mailtoken($r,$token,$contact_name,$contact_email,$domain,
1.58 raeburn 240: $domdesc,$lonhost,$include,$start_page,$cancreate,
1.73 raeburn 241: $domconfig{'usercreation'},$types);
1.58 raeburn 242: if ($redirect) {
243: $r->internal_redirect('/adm/switchserver');
244: return OK;
245: } elsif ($nostart) {
1.3 raeburn 246: if ($noend) {
247: return OK;
248: } else {
249: $r->print($output);
1.22 raeburn 250: &print_footer($r);
1.3 raeburn 251: return OK;
252: }
253: } else {
1.22 raeburn 254: &print_header($r,$start_page,$courseid);
1.3 raeburn 255: $r->print($output);
1.22 raeburn 256: &print_footer($r);
1.3 raeburn 257: return OK;
258: }
259: }
1.74 raeburn 260: my ($usernameset,$condition,$excluded,$hascustom);
1.73 raeburn 261: if ((grep(/^email$/,@{$cancreate})) && (($env{'form.create_with_email'}) ||
262: ((!$token) && ($env{'form.phase'} eq '')))) {
263: my $usertype = &get_usertype($domain);
1.74 raeburn 264: if ($usertype eq '') {
265: $usertype = 'default';
266: }
1.73 raeburn 267: if (ref($verification) eq 'HASH') {
1.74 raeburn 268: if ($verification->{$usertype} =~ /^(free|first)$/) {
269: $usernameset = $verification->{$usertype};
270: }
271: }
272: if (ref($emailoptions) eq 'HASH') {
273: if ($emailoptions->{$usertype} =~ /^(inst|noninst)$/) {
274: my $chosen = $1;
1.73 raeburn 275: if (ref($emaildomain) eq 'HASH') {
1.74 raeburn 276: if (ref($emaildomain->{$usertype}) eq 'HASH') {
277: if ($chosen eq 'inst') {
278: $condition = $emaildomain->{$usertype}->{$chosen};
279: } else {
280: $excluded = $emaildomain->{$usertype}->{$chosen};
281: }
1.73 raeburn 282: }
283: }
1.74 raeburn 284: } elsif ($emailoptions->{$usertype} eq 'custom') {
285: $hascustom = 1;
1.73 raeburn 286: }
287: }
288: }
1.3 raeburn 289: if ($env{'form.phase'} eq 'username_activation') {
290: (my $result,$output,$nostart) =
291: &username_activation($r,$env{'form.uname'},$domain,$domdesc,
1.51 raeburn 292: $courseid);
1.58 raeburn 293: if ($result eq 'redirect') {
294: $r->internal_redirect('/adm/switchserver');
295: return OK;
296: } elsif ($result eq 'ok') {
1.3 raeburn 297: if ($nostart) {
298: return OK;
299: }
300: }
1.22 raeburn 301: &print_header($r,$start_page,$courseid);
1.3 raeburn 302: $r->print($output);
1.22 raeburn 303: &print_footer($r);
1.3 raeburn 304: return OK;
1.19 raeburn 305: } elsif ($env{'form.phase'} eq 'username_validation') {
306: (my $result,$output) =
307: &username_validation($r,$env{'form.uname'},$domain,$domdesc,
308: $contact_name,$contact_email,$courseid,
1.35 raeburn 309: $lonhost,$statustocreate);
1.19 raeburn 310: if ($result eq 'existingaccount') {
311: $r->print($output);
1.22 raeburn 312: &print_footer($r);
1.19 raeburn 313: return OK;
314: } else {
1.22 raeburn 315: &print_header($r,$start_page,$courseid);
1.19 raeburn 316: }
317: } elsif ($env{'form.create_with_email'}) {
1.22 raeburn 318: &print_header($r,$start_page,$courseid);
1.61 raeburn 319: my $usertype = &get_usertype($domain);
1.74 raeburn 320: if ($usertype eq '') {
321: $usertype = 'default';
322: }
1.58 raeburn 323: $output = &process_email_request($env{'form.uname'},$domain,$domdesc,
1.35 raeburn 324: $contact_name,$contact_email,$cancreate,
1.3 raeburn 325: $lonhost,$domconfig{'usercreation'},
1.73 raeburn 326: $emailusername,$courseid,$usertype,
1.74 raeburn 327: $usernameset,$condition,$excluded,$hascustom);
1.3 raeburn 328: } elsif (!$token) {
1.73 raeburn 329: &print_header($r,$start_page,$courseid,$pagetitle);
1.1 raeburn 330: my $now=time;
1.68 raeburn 331: if ((grep(/^login$/,@{$cancreate})) && (!grep(/^email$/,@{$cancreate}))) {
1.76 raeburn 332: if (open(my $jsh,"<","$include/londes.js")) {
1.58 raeburn 333: while(my $line = <$jsh>) {
334: $r->print($line);
335: }
336: close($jsh);
337: $r->print(&javascript_setforms($now));
338: }
1.1 raeburn 339: }
1.64 raeburn 340: if (grep(/^email$/,@{$cancreate})) {
1.74 raeburn 341: $r->print(&javascript_validmail($condition));
1.12 raeburn 342: }
1.61 raeburn 343: my $usertype = &get_usertype($domain);
1.58 raeburn 344: $output = &print_username_form($r,$domain,$domdesc,$cancreate,$now,$lonhost,
1.73 raeburn 345: $include,$courseid,$emailusername,
346: $statusforemail,$usernameset,$condition,
1.74 raeburn 347: $excluded,$usertype,$types,$usertypes,$othertitle);
1.1 raeburn 348: }
349: $r->print($output);
1.22 raeburn 350: &print_footer($r);
1.1 raeburn 351: return OK;
352: }
353:
1.3 raeburn 354: sub print_header {
1.73 raeburn 355: my ($r,$start_page,$courseid,$pagetitle) = @_;
1.3 raeburn 356: $r->print($start_page);
357: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.73 raeburn 358: my $url = '/adm/createaccount';
359: if ($pagetitle eq '') {
360: $pagetitle = 'New username';
361: }
1.22 raeburn 362: if ($courseid ne '') {
363: my %coursehash = &Apache::lonnet::coursedescription($courseid);
364: &selfenroll_crumbs($r,$courseid,$coursehash{'description'});
365: }
1.73 raeburn 366: if ($env{'form.reportedtype'}) {
367: &Apache::lonhtmlcommon::add_breadcrumb
368: ({href=>$url,
369: text=>"Select affiliation"});
370: }
1.3 raeburn 371: &Apache::lonhtmlcommon::add_breadcrumb
1.73 raeburn 372: ({href=>$url,
373: text=>$pagetitle});
1.3 raeburn 374: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Create account'));
375: return;
376: }
377:
1.22 raeburn 378: sub print_footer {
379: my ($r) = @_;
380: if ($env{'form.courseid'} ne '') {
381: $r->print('<form name="backupcrumbs" method="post" action="">'.
382: &Apache::lonhtmlcommon::echo_form_input(['backto','logtoken',
383: 'token','serverid','uname','upass','phase','create_with_email',
1.72 raeburn 384: 'code','crypt','cfirstname','clastname','g-recaptcha-response',
1.59 raeburn 385: 'recaptcha_challenge_field','recaptcha_response_field',
1.23 raeburn 386: 'cmiddlename','cgeneration','cpermanentemail','cid']).
1.22 raeburn 387: '</form>');
388: }
389: $r->print(&Apache::loncommon::end_page());
390: }
391:
1.61 raeburn 392: sub get_usertype {
393: my ($domain) = @_;
1.73 raeburn 394: my $usertype;
1.61 raeburn 395: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($domain);
396: if (ref($types) eq 'ARRAY') {
397: push(@{$types},'default');
398: my $posstype = $env{'form.type'};
399: $posstype =~ s/^\s+|\s$//g;
400: if (grep(/^\Q$posstype\E$/,@{$types})) {
401: $usertype = $posstype;
402: }
403: }
404: return $usertype;
405: }
406:
1.22 raeburn 407: sub selfenroll_crumbs {
408: my ($r,$courseid,$desc) = @_;
409: &Apache::lonhtmlcommon::add_breadcrumb
410: ({href=>"javascript:ToCatalog('backupcrumbs','')",
1.37 bisitz 411: text=>"Course/Community Catalog"});
1.22 raeburn 412: if ($env{'form.coursenum'} ne '') {
413: &Apache::lonhtmlcommon::add_breadcrumb
414: ({href=>"javascript:ToCatalog('backupcrumbs','details')",
415: text=>"Course details"});
416: }
417: my $last_crumb;
418: if ($desc ne '') {
1.62 raeburn 419: $last_crumb = &mt("Self-enroll in [_1]","'$desc'");
1.22 raeburn 420: } else {
421: $last_crumb = &mt('Self-enroll');
422: }
423: &Apache::lonhtmlcommon::add_breadcrumb
424: ({href=>"javascript:ToSelfenroll('backupcrumbs')",
425: text=>$last_crumb,
426: no_mt=>"1"});
427: return;
428: }
429:
1.1 raeburn 430: sub javascript_setforms {
1.74 raeburn 431: my ($now,$emailusername,$captcha,$usertype,$recaptchaversion,$usernameset,$condition,$excluded) = @_;
1.61 raeburn 432: my ($setuserinfo,@required,$requiredchk);
1.58 raeburn 433: if (ref($emailusername) eq 'HASH') {
1.61 raeburn 434: if (ref($emailusername->{$usertype}) eq 'HASH') {
435: foreach my $key (sort(keys(%{$emailusername->{$usertype}}))) {
436: if ($emailusername->{$usertype}{$key} eq 'required') {
437: push(@required,$key);
438: }
439: $setuserinfo .= ' server.elements.'.$key.'.value=client.elements.'.$key.'.value;'."\n";
440: }
441: $setuserinfo .= ' server.elements.type.value=client.elements.type.value;'."\n";
1.58 raeburn 442: }
1.59 raeburn 443: if ($captcha eq 'original') {
1.61 raeburn 444: $setuserinfo .= ' server.elements.code.value=client.elements.code.value;'."\n".
445: ' server.elements.crypt.value=client.elements.crypt.value;'."\n";
1.59 raeburn 446: } elsif ($captcha eq 'recaptcha') {
1.72 raeburn 447: if ($recaptchaversion ne '2') {
448: $setuserinfo .=
1.61 raeburn 449: ' server.elements.recaptcha_challenge_field.value=client.elements.recaptcha_challenge_field.value;'."\n".
450: ' server.elements.recaptcha_response_field.value=client.elements.recaptcha_response_field.value;'."\n";
1.72 raeburn 451: }
1.59 raeburn 452: }
1.74 raeburn 453: if ($usernameset eq 'free') {
1.73 raeburn 454: $setuserinfo .=
455: ' server.elements.username.value=client.elements.username.value;'."\n";
456: }
1.58 raeburn 457: }
1.61 raeburn 458: if (@required) {
459: my $missprompt = &mt('One or more required fields are currently blank.');
1.70 damieng 460: &js_escape(\$missprompt);
1.61 raeburn 461: my $reqstr = join("','",@required);
462: $requiredchk = <<"ENDCHK";
463: var requiredfields = new Array('$reqstr');
464: missing = 0;
465: for (var i=0; i<requiredfields.length; i++) {
466: try {
467: eval("client.elements."+requiredfields[i]+".value");
468: }
469: catch(err) {
470: continue;
471: }
472: if (eval("client.elements."+requiredfields[i]+".value") == '') {
473: missing ++;
474: }
475: }
476: if (missing > 0) {
477: alert("$missprompt");
478: return false;
479: }
480:
481: ENDCHK
482: }
1.1 raeburn 483: my $js = <<ENDSCRIPT;
1.58 raeburn 484: <script type="text/javascript">
485: // <![CDATA[
486: function send(one,two,context) {
487: var server;
488: var client;
489: if (document.forms[one]) {
490: server = document.forms[one];
491: if (document.forms[two]) {
492: client = document.forms[two];
1.61 raeburn 493: $requiredchk
1.58 raeburn 494: server.elements.uname.value = client.elements.uname.value;
495: server.elements.udom.value = client.elements.udom.value;
1.1 raeburn 496:
1.58 raeburn 497: uextkey=client.elements.uextkey.value;
498: lextkey=client.elements.lextkey.value;
499: initkeys();
500: server.elements.upass.value
1.71 raeburn 501: = getCrypted(client.elements.upass$now.value);
1.58 raeburn 502: client.elements.uname.value='';
503: client.elements.upass$now.value='';
1.60 raeburn 504: if (context == 'email') {
1.61 raeburn 505: $setuserinfo
1.60 raeburn 506: client.elements.upasscheck$now.value='';
507: }
1.58 raeburn 508: server.submit();
509: }
510: }
1.1 raeburn 511: return false;
512: }
1.71 raeburn 513:
1.58 raeburn 514: // ]]>
515: </script>
1.1 raeburn 516: ENDSCRIPT
1.72 raeburn 517: if (($captcha eq 'recaptcha') && ($recaptchaversion eq '2')) {
518: $js .= "\n".'<script src="https://www.google.com/recaptcha/api.js"></script>'."\n";
519: }
1.1 raeburn 520: return $js;
521: }
522:
523: sub javascript_checkpass {
1.77 ! raeburn 524: my ($now,$context,$domain) = @_;
1.7 bisitz 525: my $nopass = &mt('You must enter a password.');
1.70 damieng 526: my $mismatchpass = &mt('The passwords you entered did not match.')."\n".
1.1 raeburn 527: &mt('Please try again.');
1.77 ! raeburn 528: my ($numrules,$intargjs) =
! 529: &Apache::lonuserutils::passwd_validation_js('upass',$domain);
1.70 damieng 530: &js_escape(\$nopass);
531: &js_escape(\$mismatchpass);
1.1 raeburn 532: my $js = <<"ENDSCRIPT";
1.58 raeburn 533: <script type="text/javascript">
534: // <![CDATA[
535: function checkpass(one,two) {
536: var client;
537: if (document.forms[two]) {
538: client = document.forms[two];
539: var upass = client.elements.upass$now.value;
540: var upasscheck = client.elements.upasscheck$now.value;
541: if (upass == '') {
542: alert("$nopass");
543: return false;
544: }
545: if (upass == upasscheck) {
1.77 ! raeburn 546: var numrules = $numrules;
! 547: if (numrules > 0) {
! 548: $intargjs
! 549: }
1.58 raeburn 550: client.elements.upasscheck$now.value='';
551: if (validate_email(client)) {
552: send(one,two,'$context');
553: }
554: return false;
555: } else {
556: alert("$mismatchpass");
557: return false;
558: }
1.32 raeburn 559: }
1.58 raeburn 560: return false;
1.1 raeburn 561: }
1.58 raeburn 562: // ]]>
1.1 raeburn 563: </script>
564: ENDSCRIPT
565: return $js;
566: }
567:
1.12 raeburn 568: sub javascript_validmail {
1.74 raeburn 569: my ($condition) = @_;
1.70 damieng 570: my %js_lt = &Apache::lonlocal::texthash (
1.12 raeburn 571: email => 'The e-mail address you entered',
572: notv => 'is not a valid e-mail address',
1.74 raeburn 573: avae => 'A valid e-mail address is not formed when the value you entered',
574: isco => 'is combined with the required domain',
1.12 raeburn 575: );
576: my $output = "\n".'<script type="text/javascript">'."\n".
1.58 raeburn 577: '// <![CDATA['."\n".
1.12 raeburn 578: &Apache::lonhtmlcommon::javascript_valid_email()."\n";
1.70 damieng 579: &js_escape(\%js_lt);
1.12 raeburn 580: $output .= <<"ENDSCRIPT";
1.58 raeburn 581: function validate_email(client) {
582: field = client.uname;
1.74 raeburn 583: var condition = '$condition';
584: if (validmail(field,condition) == false) {
585: if ((condition != undefined) && (condition != '')) {
586: alert("$js_lt{'avae'}: "+field.value+" $js_lt{'isco'}: "+condition);
587: } else {
588: alert("$js_lt{'email'}: "+field.value+" $js_lt{'notv'}.");
589: }
1.12 raeburn 590: return false;
591: }
592: return true;
593: }
594: ENDSCRIPT
1.58 raeburn 595: $output .= "\n".'// ]]>'."\n".'</script>'."\n";
1.12 raeburn 596: return $output;
597: }
598:
1.1 raeburn 599: sub print_username_form {
1.68 raeburn 600: my ($r,$domain,$domdesc,$cancreate,$now,$lonhost,$include,$courseid,$emailusername,
1.74 raeburn 601: $statusforemail,$usernameset,$condition,$excluded,$usertype,$types,$usertypes,
1.73 raeburn 602: $othertitle) = @_;
1.59 raeburn 603: my %lt = &Apache::lonlocal::texthash (
604: crac => 'Create account with a username provided by this institution',
605: clca => 'Create LON-CAPA account',
606: type => 'Type in your log-in ID and password to find out.',
607: plse => 'Please provide a password for your new account.',
608: info => 'Please provide user information and a password for your new account.',
609: yopw => 'Your password will be encrypted when sent (and stored).',
1.73 raeburn 610: crae => 'Create account using e-mail address verification',
1.59 raeburn 611: );
1.1 raeburn 612: my $output;
1.5 raeburn 613: if (ref($cancreate) eq 'ARRAY') {
614: if (grep(/^login$/,@{$cancreate})) {
615: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
616: if ((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth')) {
1.59 raeburn 617: $output = '<div class="LC_left_float"><h3>'.$lt{'crac'}.'</h3>';
618: $output .= &mt('If you already have a log-in ID at this institution [_1]you may be able to use it for LON-CAPA.','<br />').
1.58 raeburn 619: '<br /><br />'.
1.59 raeburn 620: $lt{'type'}.
1.58 raeburn 621: '<br /><br />';
1.59 raeburn 622: $output .= &login_box($now,$lonhost,$courseid,$lt{'clca'},
1.22 raeburn 623: $domain,'createaccount').'</div>';
1.5 raeburn 624: }
625: }
1.64 raeburn 626: if (grep(/^email$/,@{$cancreate})) {
1.73 raeburn 627: $output .= '<div class="LC_left_float"><h3>'.$lt{'crae'}.'</h3>';
628: if ($usertype ne '') {
1.74 raeburn 629: if ((ref($statusforemail) eq 'ARRAY') && (@{$statusforemail} > 0)) {
1.73 raeburn 630: unless (grep(/^\Q$usertype\E$/,@{$statusforemail})) {
631: undef($usertype);
632: }
1.74 raeburn 633: } elsif ($usertype ne 'default') {
634: undef($usertype);
1.73 raeburn 635: }
636: }
637: if (($usertype eq '') && (ref($statusforemail) eq 'ARRAY') &&
1.74 raeburn 638: (@{$statusforemail} > 0) && (ref($types) eq 'ARRAY') && (@{$types} > 0)) {
1.73 raeburn 639: my @posstypes = @{$types};
640: unless (grep(/^default$/,@posstypes)) {
641: push(@posstypes,'default');
642: }
643: $output .= '<p>'.&mt('Choose your affiliation at [_1]',$domdesc).'</p>'."\n".
1.75 raeburn 644: '<form name="reportstatus" id="LC_reportstatus" action="/adm/createaccount" method="post" '.
1.73 raeburn 645: 'onsubmit="return checkVerification();"><p>';
646: foreach my $type (@posstypes) {
647: my $name;
648: if ($type eq 'default') {
649: $name = $othertitle;
650: } else {
651: $name = $type;
652: if (ref($usertypes) eq 'HASH') {
653: if (exists($usertypes->{$type})) {
654: $name = $usertypes->{$type};
655: }
656: }
657: }
1.75 raeburn 658: my $checked;
659: if ($env{'form.type'} eq $type) {
660: $checked = ' checked="checked"';
661: }
662: $output .= '<label><input type="radio" name="type" value="'.$type.'"'.$checked.' />'.
1.73 raeburn 663: $name.'</label>'.(' 'x2);
664: }
665: if ($env{'form.courseid'} =~ /^$match_domain\_$match_courseid$/) {
666: $output .= "\n".'<input type="hidden" name="courseid" value="'.$env{'form.courseid'}.'" />';
667: }
668: $output .= '</p>'."\n".'<p><input type="submit" name="reportedtype" value="'.&mt('Submit').'" /></p></form>';
1.52 raeburn 669: } else {
1.73 raeburn 670: my ($captchaform,$error,$captcha,$recaptchaversion) =
671: &Apache::loncommon::captcha_display('usercreation',$lonhost);
672: if ($error) {
673: my $helpdesk = '/adm/helpdesk?origurl=%2fadm%2fcreateaccount';
674: if ($courseid ne '') {
675: $helpdesk .= '&courseid='.$courseid;
676: }
677: $output .= '<span class="LC_error">'.
678: &mt('An error occurred generating the validation code[_1] required for use of an e-mail address to request a LON-CAPA account.','<br />').
679: '</span><br /><br />'.
680: &mt('[_1]Contact the helpdesk[_2] or [_3]reload[_2] the page and try again.',
681: '<a href="'.$helpdesk.'">','</a>','<a href="javascript:window.location.reload()">');
1.28 raeburn 682: } else {
1.73 raeburn 683: if (grep(/^login$/,@{$cancreate})) {
684: $output .= &mt('If you do not have a log-in ID at your institution, [_1]provide your e-mail address to request a LON-CAPA account.','<br />').'<br /><br />'.
685: $lt{'plse'}.'<br />'.
686: $lt{'yopw'}.'<br />';
687: } else {
688: my $prompt = $lt{'plse'};
689: if (ref($emailusername) eq 'HASH') {
690: if (ref($emailusername->{$usertype}) eq 'HASH') {
691: if (keys(%{$emailusername->{$usertype}}) > 0) {
692: $prompt = $lt{'info'};
693: }
1.59 raeburn 694: }
695: }
1.73 raeburn 696: $output .= $prompt.'<br />'.
697: $lt{'yopw'}.'<br />';
1.59 raeburn 698: }
1.74 raeburn 699: if ($usertype eq '') {
700: $usertype = 'default';
1.75 raeburn 701: } elsif (ref($usertypes) eq 'HASH') {
702: my $usertitle;
703: if ($usertype eq 'default') {
704: $usertitle = $othertitle;
705: } elsif (exists($usertypes->{$usertype})) {
706: $usertitle = $usertypes->{$usertype};
707: }
708: if ($usertitle ne '') {
709: $output .= &mt('Self-reported affiliation: [_1]',
710: '<span style="font-style: italic;">'.$usertitle.'</span>').
711: '<br />';
712: }
1.74 raeburn 713: }
1.73 raeburn 714: $output .= &print_dataentry_form($r,$domain,$lonhost,$include,$now,$captchaform,
715: $courseid,$emailusername,$captcha,$usertype,
1.74 raeburn 716: $recaptchaversion,$usernameset,$condition,$excluded);
1.28 raeburn 717: }
1.5 raeburn 718: }
1.28 raeburn 719: $output .= '</div>';
1.3 raeburn 720: }
1.1 raeburn 721: }
722: if ($output eq '') {
1.73 raeburn 723: $output = &mt('Creation of a new LON-CAPA user account using an institutional log-in ID or verification by e-mail is not permitted at [_1].',$domdesc);
1.1 raeburn 724: } else {
725: $output .= '<div class="LC_clear_float_footer"></div>';
726: }
727: return $output;
728: }
729:
1.20 raeburn 730: sub login_box {
731: my ($now,$lonhost,$courseid,$submit_text,$domain,$context) = @_;
732: my $output;
733: my %titles = &Apache::lonlocal::texthash(
734: createaccount => 'Log-in ID',
735: selfenroll => 'Username',
736: );
1.58 raeburn 737: my ($lkey,$ukey) = &Apache::loncommon::des_keys();
1.20 raeburn 738: my ($lextkey,$uextkey) = &getkeys($lkey,$ukey);
1.41 raeburn 739: my $logtoken=Apache::lonnet::reply('tmpput:'.$ukey.$lkey.'&createaccount:createaccount',
1.20 raeburn 740: $lonhost);
741: $output = &serverform($logtoken,$lonhost,undef,$courseid,$context);
1.59 raeburn 742: my $unameform = '<input type="text" name="uname" size="20" value="" autocomplete="off" />';
743: my $upassform = '<input type="password" name="upass'.$now.'" size="20" autocomplete="off" />';
1.58 raeburn 744: $output .= '<form name="client" method="post" action="" onsubmit="return(send('."'server','client'".'));">'."\n".
1.32 raeburn 745: &Apache::lonhtmlcommon::start_pick_box()."\n".
746: &Apache::lonhtmlcommon::row_title($titles{$context},
1.31 bisitz 747: 'LC_pick_box_title')."\n".
748: $unameform."\n".
749: &Apache::lonhtmlcommon::row_closure(1)."\n".
750: &Apache::lonhtmlcommon::row_title(&mt('Password'),
751: 'LC_pick_box_title')."\n".
752: $upassform;
1.20 raeburn 753: if ($context eq 'selfenroll') {
1.32 raeburn 754: my $udomform = '<input type="text" name="udom" size="10" value="'.
1.20 raeburn 755: $domain.'" />';
1.31 bisitz 756: $output .= &Apache::lonhtmlcommon::row_closure(1)."\n".
757: &Apache::lonhtmlcommon::row_title(&mt('Domain'),
1.20 raeburn 758: 'LC_pick_box_title')."\n".
1.31 bisitz 759: $udomform."\n";
1.32 raeburn 760: } else {
761: $output .= '<input type="hidden" name="udom" value="'.$domain.'" />';
1.20 raeburn 762: }
1.32 raeburn 763: $output .= &Apache::lonhtmlcommon::row_closure(1).
1.31 bisitz 764: &Apache::lonhtmlcommon::row_title().
1.32 raeburn 765: '<br /><input type="submit" name="username_validation" value="'.
766: $submit_text.'" />'."\n";
767: if ($context eq 'selfenroll') {
768: $output .= '<br /><br /><table width="100%"><tr><td align="right">'.
769: '<span class="LC_fontsize_medium">'.
770: '<a href="/adm/resetpw">'.&mt('Forgot password?').'</a>'.
771: '</span></td></tr></table>'."\n";
772: }
773: $output .= &Apache::lonhtmlcommon::row_closure(1)."\n".
774: &Apache::lonhtmlcommon::end_pick_box().'<br />'."\n";
1.34 bisitz 775: $output .= '<input type="hidden" name="lextkey" value="'.$lextkey.'" />'."\n".
776: '<input type="hidden" name="uextkey" value="'.$uextkey.'" />'."\n".
1.22 raeburn 777: '</form>';
1.20 raeburn 778: return $output;
779: }
780:
1.1 raeburn 781: sub process_email_request {
782: my ($useremail,$domain,$domdesc,$contact_name,$contact_email,$cancreate,
1.73 raeburn 783: $server,$settings,$emailusername,$courseid,$usertype,$usernameset,
1.74 raeburn 784: $condition,$excluded,$hascustom) = @_;
1.73 raeburn 785: my ($output,$uname);
1.5 raeburn 786: if (ref($cancreate) eq 'ARRAY') {
1.64 raeburn 787: if (!grep(/^email$/,@{$cancreate})) {
1.5 raeburn 788: $output = &invalid_state('noemails',$domdesc,
789: $contact_name,$contact_email);
790: return $output;
1.74 raeburn 791: } elsif ((($condition ne '') && ($useremail !~ /^[^\@]+$/)) ||
792: (($condition eq '') && ($useremail !~ /^[^\@]+\@[^\@]+\.[^\@\.]+$/))) {
1.5 raeburn 793: $output = &invalid_state('baduseremail',$domdesc,
1.1 raeburn 794: $contact_name,$contact_email);
795: return $output;
796: } else {
1.58 raeburn 797: $useremail =~ s/^\s+|\s+$//g;
1.73 raeburn 798: my $possuname;
1.74 raeburn 799: if ($condition ne '') {
800: if ($usernameset eq 'first') {
801: $possuname = $useremail;
802: }
803: $useremail .= $condition;
804: } elsif ($excluded ne '') {
805: if ($useremail =~ /^[^\@]+\Q$excluded\E$/) {
806: $output = &invalid_state('userrules',$domdesc,
807: $contact_name,$contact_email);
808: return $output;
809: }
810: }
811: if (($usernameset eq 'free') && ($env{'form.username'} ne '')) {
1.73 raeburn 812: $possuname = $env{'form.username'};
1.74 raeburn 813: } elsif (($usernameset eq 'first') && ($condition eq '')) {
814: if ($condition eq '') {
815: ($possuname) = ($useremail =~ /^([^\@]+)\@/);
816: }
817: }
818: if ($possuname ne '') {
1.73 raeburn 819: $possuname =~ s/^\s+|\s+$//g;
1.74 raeburn 820: if ($possuname ne '') {
821: $uname=&LONCAPA::clean_username($possuname);
822: if ($uname ne $possuname) {
823: $output = &invalid_state('badusername',$domdesc,
1.73 raeburn 824: $contact_name,$contact_email);
825: return $output;
826: }
827: }
1.74 raeburn 828: }
829: if ($possuname eq '') {
1.73 raeburn 830: $uname=&LONCAPA::clean_username($useremail);
831: if ($useremail ne $uname) {
832: $output = &invalid_state('badusername',$domdesc,
833: $contact_name,$contact_email);
834: return $output;
835: }
1.58 raeburn 836: }
1.73 raeburn 837: my $uhome = &Apache::lonnet::homeserver($uname,$domain);
1.5 raeburn 838: if ($uhome ne 'no_host') {
839: $output = &invalid_state('existinguser',$domdesc,
840: $contact_name,$contact_email);
1.1 raeburn 841: return $output;
1.5 raeburn 842: } else {
1.52 raeburn 843: my ($captcha_chk,$captcha_error) = &Apache::loncommon::captcha_response('usercreation',$server);
1.5 raeburn 844: if ($captcha_chk != 1) {
845: $output = &invalid_state('captcha',$domdesc,$contact_name,
1.52 raeburn 846: $contact_email,$captcha_error);
1.5 raeburn 847: return $output;
848: }
1.58 raeburn 849: my (%rulematch,%inst_results,%curr_rules,%got_rules,%alerts);
1.73 raeburn 850: &call_rulecheck($uname,$domain,\%alerts,\%rulematch,
1.58 raeburn 851: \%inst_results,\%curr_rules,\%got_rules,'username');
852: if (ref($alerts{'username'}) eq 'HASH') {
853: if (ref($alerts{'username'}{$domain}) eq 'HASH') {
1.73 raeburn 854: if ($alerts{'username'}{$domain}{$uname}) {
1.58 raeburn 855: $output = &invalid_state('userrules',$domdesc,
856: $contact_name,$contact_email);
857: return $output;
1.1 raeburn 858: }
859: }
1.58 raeburn 860: }
1.74 raeburn 861: if ($hascustom) {
1.73 raeburn 862: my $format_msg =
863: &guest_format_check($useremail,$domain,$cancreate,
1.74 raeburn 864: $settings,$usertype);
1.73 raeburn 865: if ($format_msg) {
866: $output = &invalid_state('userformat',$domdesc,$contact_name,
867: $contact_email,$format_msg);
868: return $output;
869: }
1.1 raeburn 870: }
871: }
872: }
1.5 raeburn 873: $output = &send_token($domain,$useremail,$server,$domdesc,$contact_name,
1.73 raeburn 874: $contact_email,$courseid,$emailusername,$usertype,
875: $uname);
1.1 raeburn 876: }
877: return $output;
878: }
879:
1.23 raeburn 880: sub call_rulecheck {
881: my ($uname,$udom,$alerts,$rulematch,$inst_results,$curr_rules,
882: $got_rules,$tocheck) = @_;
883: my ($checkhash,$checks);
884: $checkhash->{$uname.':'.$udom} = { 'newuser' => 1, };
885: if ($tocheck eq 'username') {
886: $checks = { 'username' => 1 };
887: }
888: &Apache::loncommon::user_rule_check($checkhash,$checks,
889: $alerts,$rulematch,$inst_results,$curr_rules,
890: $got_rules);
891: return;
892: }
893:
1.1 raeburn 894: sub send_token {
1.61 raeburn 895: my ($domain,$email,$server,$domdesc,$contact_name,$contact_email,$courseid,$emailusername,
1.73 raeburn 896: $usertype,$uname) = @_;
1.14 raeburn 897: my $msg = '<h3>'.&mt('Account creation status').'</h3>'.
898: &mt('Thank you for your request to create a new LON-CAPA account.').
899: '<br /><br />';
1.1 raeburn 900: my $now = time;
1.58 raeburn 901: $env{'form.logtoken'} =~ s/(`)//g;
902: if ($env{'form.logtoken'}) {
903: my $logtoken = $env{'form.logtoken'};
904: my $tmpinfo=Apache::lonnet::reply('tmpget:'.$logtoken,$server);
905: if (($tmpinfo=~/^error/) || ($tmpinfo eq 'con_lost')) {
906: $msg = &mt('Information needed to process your request is missing, inaccessible or expired.')
907: .'<br />'.&mt('Return to the previous page to try again.');
908: } else {
909: my $reply = &Apache::lonnet::reply('tmpdel:'.$logtoken,$server);
910: unless ($reply eq 'ok') {
911: $msg .= &mt('Request could not be processed.');
912: }
913: }
914: my %info = ('ip' => $ENV{'REMOTE_ADDR'},
915: 'time' => $now,
916: 'domain' => $domain,
917: 'username' => $email,
918: 'courseid' => $courseid,
919: 'upass' => $env{'form.upass'},
920: 'serverid' => $env{'form.serverid'},
921: 'tmpinfo' => $tmpinfo);
1.73 raeburn 922: if ($uname ne '') {
923: $info{'username'} = $uname;
924: $info{'email'} = $email;
925: }
1.58 raeburn 926: if (ref($emailusername) eq 'HASH') {
1.61 raeburn 927: if (ref($emailusername->{$usertype}) eq 'HASH') {
928: foreach my $item (keys(%{$emailusername->{$usertype}})) {
929: $info{$item} = $env{'form.'.$item};
930: $info{$item} =~ s/(`)//g;
931: }
1.58 raeburn 932: }
933: }
1.73 raeburn 934: if ($usertype ne '') {
935: $info{'usertype'} = $usertype;
936: }
1.58 raeburn 937: my $token = &Apache::lonnet::tmpput(\%info,$server,'createaccount');
938: if ($token !~ /^error/ && $token ne 'no_such_host') {
939: my $esc_token = &escape($token);
940: my $showtime = localtime(time);
941: my $mailmsg = &mt('A request was submitted on [_1] for creation of a LON-CAPA account at the following institution: [_2].',$showtime,$domdesc).' '.
942: &mt('To complete this process please open a web browser and enter the following URL in the address/location box: [_1]',
943: &Apache::lonnet::absolute_url().'/adm/createaccount?token='.$esc_token);
944: my $result = &Apache::resetpw::send_mail($domdesc,$email,$mailmsg,$contact_name,
945: $contact_email);
946: if ($result eq 'ok') {
947: $msg .= &mt('A message has been sent to the e-mail address you provided.').'<br />'.
948: &mt('The message includes the web address for the link you will use to complete the account creation process.').'<br />'.
949: &mt("The link included in the message will be valid for the next [_1]two[_2] hours.",'<b>','</b>');
950: } else {
951: $msg .= '<span class="LC_error">'.
952: &mt('An error occurred when sending a message to the e-mail address you provided.').'</span><br />'.
953: ' '.&mt('Please contact the [_1] ([_2]) for assistance.',$contact_name,$contact_email);
954: }
1.1 raeburn 955: } else {
1.14 raeburn 956: $msg .= '<span class="LC_error">'.
1.58 raeburn 957: &mt('An error occurred creating a token required for the account creation process.').'</span><br />'.
1.14 raeburn 958: ' '.&mt('Please contact the [_1] ([_2]) for assistance.',$contact_name,$contact_email);
1.1 raeburn 959: }
960: } else {
1.58 raeburn 961: $msg .= $msg = &mt('Information needed to process your request is missing, inaccessible or expired.')
962: .'<br />'.&mt('Return to the previous page to try again.');
963:
1.1 raeburn 964: }
965: return $msg;
966: }
967:
968: sub process_mailtoken {
1.3 raeburn 969: my ($r,$token,$contact_name,$contact_email,$domain,$domdesc,$lonhost,
1.73 raeburn 970: $include,$start_page,$cancreate,$settings,$types) = @_;
1.58 raeburn 971: my ($msg,$nostart,$noend,$redirect);
1.1 raeburn 972: my %data = &Apache::lonnet::tmpget($token);
973: my $now = time;
974: if (keys(%data) == 0) {
1.9 raeburn 975: $msg = &mt('Sorry, the URL you provided to complete creation of a new LON-CAPA account was invalid.')
976: .' '.&mt('Either the token included in the URL has been deleted or the URL you provided was invalid.')
1.58 raeburn 977: .' '.&mt('Please submit a [_1]new request[_2] for account creation and follow the new link page included in the e-mail that will be sent to you.',
978: '<a href="/adm/createaccount">','</a>');
1.1 raeburn 979: return $msg;
980: }
981: if (($data{'time'} =~ /^\d+$/) &&
982: ($data{'domain'} ne '') &&
1.73 raeburn 983: ((($data{'email'} =~ /^[^\@]+\@[^\@]+\.[^\@\.]+$/) && ($data{'username'} =~ /^$match_username$/)) ||
984: ($data{'username'} =~ /^[^\@]+\@[^\@]+\.[^\@\.]+$/))) {
1.1 raeburn 985: if ($now - $data{'time'} < 7200) {
1.58 raeburn 986: # Check if request should be queued.
987: if (ref($cancreate) eq 'ARRAY') {
1.73 raeburn 988: my ($disposition,$usertype);
1.58 raeburn 989: if (grep(/^email$/,@{$cancreate})) {
1.73 raeburn 990: if (exists($data{'usertype'})) {
991: $usertype = $data{'usertype'};
992: my @posstypes;
993: if (ref($types) eq 'ARRAY') {
994: @posstypes = @{$types};
995: if (@posstypes) {
996: unless (grep(/^default$/,@posstypes)) {
997: push(@posstypes,'default');
998: }
999: }
1000: if (grep(/\Q$usertype\E/,@posstypes)) {
1001: unless ($usertype eq 'default') {
1002: $data{'inststatus'} = $usertype;
1003: }
1004: } else {
1.74 raeburn 1005: $disposition = 'approval';
1.73 raeburn 1006: }
1007: }
1008: delete($data{'usertype'});
1009: }
1.64 raeburn 1010: if (ref($settings) eq 'HASH') {
1011: if (ref($settings->{'cancreate'}) eq 'HASH') {
1012: if (ref($settings->{'cancreate'}{'selfcreateprocessing'}) eq 'HASH') {
1.74 raeburn 1013: if ($usertype ne '') {
1014: $disposition = $settings->{'cancreate'}{'selfcreateprocessing'}{$usertype};
1015: unless ($disposition =~ /^(approval|automatic)$/) {
1016: $disposition = 'approval';
1017: }
1018: }
1.64 raeburn 1019: }
1.58 raeburn 1020: }
1.64 raeburn 1021: }
1022: if ($disposition eq 'approval') {
1023: $msg = &store_request($domain,$data{'username'},'approval',\%data,$settings);
1024: my $delete = &Apache::lonnet::tmpdel($token);
1.1 raeburn 1025: } else {
1.64 raeburn 1026: my ($result,$output,$uhome) =
1027: &create_account($r,$domain,$domdesc,\%data);
1028: if ($result eq 'ok') {
1029: $msg = $output;
1030: my $shownow = &Apache::lonlocal::locallocaltime($now);
1031: my $mailmsg = &mt('A LON-CAPA account for the institution: [_1] has been created [_2] from IP address: [_3]. If you did not perform this action or authorize it, please contact the [_4] ([_5]).',$domdesc,$shownow,$ENV{'REMOTE_ADDR'},$contact_name,$contact_email)."\n";
1032: my $mailresult = &Apache::resetpw::send_mail($domdesc,$data{'email'},
1033: $mailmsg,$contact_name,
1034: $contact_email);
1035: if ($mailresult eq 'ok') {
1036: $msg .= &mt('An e-mail confirming creation of your new LON-CAPA account has been sent to [_1].',$data{'username'});
1037: } else {
1038: $msg .= &mt('An error occurred when sending e-mail to [_1] confirming creation of your LON-CAPA account.',$data{'username'});
1039: }
1040: $redirect = &start_session($r,$data{'username'},$domain,$uhome,
1041: $data{'courseid'},$token);
1042: $nostart = 1;
1043: $noend = 1;
1044: } else {
1045: $msg .= &mt('A problem occurred when attempting to create your new LON-CAPA account.')
1046: .'<br />'.$output;
1047: if (($contact_name ne '') && ($contact_email ne '')) {
1048: $msg .= &mt('Please contact the [_1] ([_2]) for assistance.',$contact_name,$contact_email);
1049: }
1.58 raeburn 1050: }
1.64 raeburn 1051: my $delete = &Apache::lonnet::tmpdel($token);
1.1 raeburn 1052: }
1053: } else {
1.58 raeburn 1054: $msg = &invalid_state('noemails',$domdesc,$contact_name,$contact_email);
1.1 raeburn 1055: }
1056: } else {
1.58 raeburn 1057: $msg = &invalid_state('noemails',$domdesc,$contact_name,$contact_email);
1.1 raeburn 1058: }
1059: } else {
1.7 bisitz 1060: $msg = &mt('Sorry, the token generated when you requested creation of an account has expired.')
1061: .' '.&mt('Please submit a [_1]new request[_2] for account creation and follow the new link included in the e-mail that will be sent to you.','<a href="/adm/createaccount">','</a>');
1.4 raeburn 1062: }
1.1 raeburn 1063: } else {
1.7 bisitz 1064: $msg .= &mt('Sorry, the URL generated when you requested creation of an account contained incomplete information.')
1065: .' '.&mt('Please submit a [_1]new request[_2] for account creation and follow the new link included in the e-mail that will be sent to you.','<a href="/adm/createaccount">','</a>');
1.1 raeburn 1066: }
1.58 raeburn 1067: return ($msg,$nostart,$noend,$redirect);
1.3 raeburn 1068: }
1069:
1070: sub start_session {
1.51 raeburn 1071: my ($r,$username,$domain,$uhome,$courseid,$token) = @_;
1.69 raeburn 1072: my ($is_balancer) = &Apache::lonnet::check_loadbalancing($username,$domain);
1073: if ($is_balancer) {
1.51 raeburn 1074: Apache::lonauth::success($r, $username, $domain, $uhome,
1.48 droeschl 1075: 'noredirect', undef, {});
1076:
1077: Apache::lonnet::tmpdel($token) if $token;
1078:
1.58 raeburn 1079: return 'redirect';
1.3 raeburn 1080: } else {
1.48 droeschl 1081: $courseid = Apache::lonnet::is_course($courseid);
1082:
1.51 raeburn 1083: Apache::lonauth::success($r, $username, $domain, $uhome,
1.48 droeschl 1084: ($courseid ? "/adm/selfenroll?courseid=$courseid" : '/adm/roles'),
1085: undef, {});
1.3 raeburn 1086: }
1.48 droeschl 1087: return;
1.1 raeburn 1088: }
1089:
1.50 www 1090: #
1091: # The screen that the user gets to create his or her account
1092: # Desired username, desired password, etc
1093: # Stores token to store DES-key and stage during creation session
1094: #
1.1 raeburn 1095: sub print_dataentry_form {
1.68 raeburn 1096: my ($r,$domain,$lonhost,$include,$now,$captchaform,$courseid,$emailusername,$captcha,
1.74 raeburn 1097: $usertype,$recaptchaversion,$usernameset,$condition,$excluded) = @_;
1.1 raeburn 1098: my ($error,$output);
1.76 raeburn 1099: if (open(my $jsh,"<","$include/londes.js")) {
1.68 raeburn 1100: while(my $line = <$jsh>) {
1101: $r->print($line);
1102: }
1103: close($jsh);
1.73 raeburn 1104: $output = &javascript_setforms($now,$emailusername,$captcha,$usertype,$recaptchaversion,
1.74 raeburn 1105: $usernameset,$condition,$excluded).
1.77 ! raeburn 1106: "\n".&javascript_checkpass($now,'email',$domain);
1.58 raeburn 1107: my ($lkey,$ukey) = &Apache::loncommon::des_keys();
1.1 raeburn 1108: my ($lextkey,$uextkey) = &getkeys($lkey,$ukey);
1.41 raeburn 1109: my $logtoken=Apache::lonnet::reply('tmpput:'.$ukey.$lkey.'&createaccount:createaccount',
1.1 raeburn 1110: $lonhost);
1.58 raeburn 1111: $output .=
1112: '<form name="createaccount" method="post" target="_top" action="/adm/createaccount">';
1113: if ($courseid ne '') {
1114: $output .= '<input type="hidden" name="courseid" value="'.$courseid.'"/>'."\n";
1115: }
1116: if (ref($emailusername) eq 'HASH') {
1.61 raeburn 1117: if (ref($emailusername->{$usertype}) eq 'HASH') {
1118: foreach my $field (sort(keys(%{$emailusername->{$usertype}}))) {
1119: $output .= '<input type="hidden" name="'.$field.'" value="" />'."\n";
1120: }
1.58 raeburn 1121: }
1.1 raeburn 1122: }
1.59 raeburn 1123: if ($captcha eq 'original') {
1124: $output .= '
1125: <input type="hidden" name="crypt" value="" />
1126: <input type="hidden" name="code" value="" />
1127: ';
1128: } elsif ($captcha eq 'recaptcha') {
1.72 raeburn 1129: if ($recaptchaversion eq '2') {
1130: $output .= "$captchaform\n";
1131: undef($captchaform);
1132: } else {
1133: $output .= '
1.59 raeburn 1134: <input type="hidden" name="recaptcha_challenge_field" value="" />
1135: <input type="hidden" name="recaptcha_response_field" value="" />
1136: ';
1.72 raeburn 1137: }
1.59 raeburn 1138: }
1.73 raeburn 1139: if ($usertype ne '') {
1140: $output .= '<input type="hidden" name="type" value="'.
1141: &HTML::Entities::encode($usertype,'\'<>"&').'" />'."\n";
1142: }
1.74 raeburn 1143: if ($usernameset eq 'free') {
1.73 raeburn 1144: $output .= '<input type="hidden" name="username" value="" />'."\n";
1145: }
1.1 raeburn 1146: $output .= <<"ENDSERVERFORM";
1147: <input type="hidden" name="logtoken" value="$logtoken" />
1148: <input type="hidden" name="serverid" value="$lonhost" />
1149: <input type="hidden" name="uname" value="" />
1150: <input type="hidden" name="upass" value="" />
1.32 raeburn 1151: <input type="hidden" name="udom" value="" />
1.1 raeburn 1152: <input type="hidden" name="phase" value="createaccount" />
1.58 raeburn 1153: <input type="hidden" name="create_with_email" value="1" />
1.32 raeburn 1154: </form>
1.1 raeburn 1155: ENDSERVERFORM
1.58 raeburn 1156: my $beginclientform = '<form name="newemail" method="post" action="" '.
1157: 'onsubmit="return checkpass('."'createaccount','newemail'".');">'."\n";
1158: my $endclientform = '<input type="hidden" name="udom" value="'.$domain.'" />'."\n".
1159: '<input type="hidden" name="lextkey" value="'.$lextkey.'" />'."\n".
1160: '<input type="hidden" name="uextkey" value="'.$uextkey.'" />'."\n".
1.61 raeburn 1161: '</form>'."\n".
1162: '<p class="LC_info">'.&mt('Fields marked [_1]*[_2] are required.','<b>','</b>').'</p>';
1.58 raeburn 1163: my ($datatable,$rowcount) =
1164: &Apache::loncreateuser::personal_data_display('',$domain,'email','selfcreate',
1165: '','',$now,$captchaform,
1.73 raeburn 1166: $emailusername,$usertype,
1.74 raeburn 1167: $usernameset,$condition,$excluded);
1.32 raeburn 1168: if ($rowcount) {
1.58 raeburn 1169: $output .= '<div class="LC_left_float">'.$beginclientform.$datatable.$endclientform;
1170: } else {
1171: $output .= $beginclientform.$endclientform;
1.32 raeburn 1172: }
1173: if ($rowcount) {
1174: $output .= '</div>'."\n".
1175: '<div class="LC_clear_float_footer"></div>'."\n";
1176: }
1.1 raeburn 1177: } else {
1.7 bisitz 1178: $output = &mt('Could not load javascript file [_1]','<tt>londes.js</tt>');
1.1 raeburn 1179: }
1.3 raeburn 1180: return $output;
1.1 raeburn 1181: }
1182:
1.50 www 1183: #
1184: # Retrieve rules for generating accounts from domain configuration
1185: # Can the user make a new account or just self-enroll?
1186:
1.35 raeburn 1187: sub get_creation_controls {
1188: my ($domain,$usercreation) = @_;
1.73 raeburn 1189: my (@cancreate,@statustocreate,@statusforemail,$emailusername,$processing,
1.74 raeburn 1190: $emailoptions,$verification,$emaildomain,$othertitle,$usertypes,$types);
1.35 raeburn 1191: if (ref($usercreation) eq 'HASH') {
1192: if (ref($usercreation->{'cancreate'}) eq 'HASH') {
1.73 raeburn 1193: ($othertitle,$usertypes,$types) =
1194: &Apache::loncommon::sorted_inst_types($domain);
1.35 raeburn 1195: if (ref($usercreation->{'cancreate'}{'statustocreate'}) eq 'ARRAY') {
1196: @statustocreate = @{$usercreation->{'cancreate'}{'statustocreate'}};
1.47 raeburn 1197: if (@statustocreate == 0) {
1198: if (ref($types) eq 'ARRAY') {
1199: if (@{$types} == 0) {
1200: @statustocreate = ('default');
1201: }
1202: } else {
1203: @statustocreate = ('default');
1204: }
1205: }
1.35 raeburn 1206: } else {
1207: @statustocreate = ('default');
1208: if (ref($types) eq 'ARRAY') {
1209: push(@statustocreate,@{$types});
1210: }
1211: }
1212: if (ref($usercreation->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
1213: @cancreate = @{$usercreation->{'cancreate'}{'selfcreate'}};
1214: } elsif (($usercreation->{'cancreate'}{'selfcreate'} ne 'none') &&
1215: ($usercreation->{'cancreate'}{'selfcreate'} ne '')) {
1216: @cancreate = ($usercreation->{'cancreate'}{'selfcreate'});
1217: }
1.73 raeburn 1218: if (grep(/^email$/,@cancreate)) {
1219: if (ref($usercreation->{'cancreate'}{'selfcreateprocessing'}) eq 'HASH') {
1220: $processing = $usercreation->{'cancreate'}{'selfcreateprocessing'};
1221: }
1.74 raeburn 1222: if (ref($usercreation->{'cancreate'}{'emailoptions'}) eq 'HASH') {
1223: $emailoptions = $usercreation->{'cancreate'}{'emailoptions'};
1224: }
1.73 raeburn 1225: if (ref($usercreation->{'cancreate'}{'emailverified'}) eq 'HASH') {
1226: $verification = $usercreation->{'cancreate'}{'emailverified'};
1227: }
1228: if (ref($usercreation->{'cancreate'}{'emaildomain'}) eq 'HASH') {
1229: $emaildomain = $usercreation->{'cancreate'}{'emaildomain'};
1230: }
1231: if (ref($processing)) {
1232: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
1233: my @emailtypes;
1234: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
1.74 raeburn 1235: @statusforemail = @{$domdefaults{'inststatusguest'}};
1236: unless (@statusforemail) {
1237: my @okcreate;
1238: foreach my $poss (@cancreate) {
1239: unless ($poss eq 'email') {
1240: push(@okcreate,$poss);
1.73 raeburn 1241: }
1242: }
1.74 raeburn 1243: @cancreate = @okcreate;
1.73 raeburn 1244: }
1245: }
1246: }
1247: }
1.58 raeburn 1248: if (ref($usercreation->{'cancreate'}{'emailusername'}) eq 'HASH') {
1249: $emailusername = $usercreation->{'cancreate'}{'emailusername'};
1.59 raeburn 1250: } else {
1.67 raeburn 1251: $emailusername = {
1252: default => {
1253: 'lastname' => '1',
1254: 'firstname' => 1,
1255: },
1256: };
1.58 raeburn 1257: }
1.35 raeburn 1258: }
1259: }
1.73 raeburn 1260: return (\@cancreate,\@statustocreate,\@statusforemail,$emailusername,
1.74 raeburn 1261: $emailoptions,$verification,$emaildomain,$types,$usertypes,$othertitle);
1.35 raeburn 1262: }
1263:
1.1 raeburn 1264: sub create_account {
1.58 raeburn 1265: my ($r,$domain,$domdesc,$dataref) = @_;
1266: my $error = '<span class="LC_error">'.&mt('Error:').' ';
1267: my $end = '</span><br /><br />';
1268: my $rtnlink = '<a href="javascript:history.back();">'.
1.1 raeburn 1269: &mt('Return to previous page').'</a>'.
1270: &Apache::loncommon::end_page();
1.58 raeburn 1271: my $output;
1272: if (ref($dataref) eq 'HASH') {
1273: my ($username,$encpass,$serverid,$courseid,$id,$firstname,$middlename,$lastname,
1.73 raeburn 1274: $generation,$inststatus,$permanentemail);
1.58 raeburn 1275: $username = $dataref->{'username'};
1276: $encpass = $dataref->{'upass'};
1277: $serverid = $dataref->{'serverid'};
1278: $courseid = $dataref->{'courseid'};
1279: $id = $dataref->{'id'};
1280: $firstname = $dataref->{'firstname'};
1281: $middlename = $dataref->{'middlename'};
1282: $lastname = $dataref->{'lastname'};
1283: $generation = $dataref->{'generation'};
1.63 raeburn 1284: $inststatus = $dataref->{'inststatus'};
1285:
1.73 raeburn 1286: if ($dataref->{'email'} ne '') {
1287: $permanentemail = $dataref->{'email'};
1288: } else {
1289: $permanentemail = $dataref->{'username'};
1290: }
1.58 raeburn 1291: my $currhome = &Apache::lonnet::homeserver($username,$domain);
1292: unless ($currhome eq 'no_host') {
1293: $output = &mt('User account requested for username: [_1] in domain: [_2] already exists.',$username,$domain);
1294: return ('fail',$error.$output.$end.$rtnlink);
1295: }
1296:
1297: # Split the logtoken to retrieve the DES key and decrypt the encypted password
1298:
1299: my ($key,$caller)=split(/&/,$dataref->{'tmpinfo'});
1300: if ($caller eq 'createaccount') {
1.74 raeburn 1301: my $upass;
1302: if ($encpass eq '') {
1303: $output = &mt('Password retrieved was blank.');
1304: return ('fail',$error.$output.$end.$rtnlink);
1305: } else {
1306: $upass = &Apache::loncommon::des_decrypt($key,$encpass);
1307: }
1.58 raeburn 1308:
1309: # See if we are allowed to use the proposed student/employee ID,
1310: # as per domain rules; if not, student/employee will be left blank.
1311:
1312: if ($id ne '') {
1313: my ($result,$userchkmsg) = &check_id($username,$domain,$id,$domdesc,'email');
1314: if ($result eq 'fail') {
1315: $output = $error.&mt('Invalid ID format').$end.
1316: $userchkmsg;
1317: undef($id);
1318: }
1.1 raeburn 1319: }
1.58 raeburn 1320:
1321: # Create an internally authenticated account with password $upass
1322: # if the user account does not already exist.
1323: # Assign student/employee id, first name, last name, etc.
1324:
1325: my $result =
1326: &Apache::lonnet::modifyuser($domain,$username,$id,
1327: 'internal',$upass,$firstname,$middlename,
1.73 raeburn 1328: $lastname,$generation,undef,undef,$permanentemail);
1.58 raeburn 1329: $output = &mt('Generating user: [_1]',$result);
1330:
1331: # Now that the user account exists, retrieve the homeserver, and include it in the output.
1332:
1333: my $uhome = &Apache::lonnet::homeserver($username,$domain);
1.61 raeburn 1334: unless (($inststatus eq 'default') || ($inststatus eq '')) {
1335: &Apache::lonnet::put('environment',{inststatus => $inststatus},$domain,$username);
1336: }
1.58 raeburn 1337: $output .= '<br />'.&mt('Home server: [_1]',$uhome).' '.
1338: &Apache::lonnet::hostname($uhome).'<br /><br />';
1339: return ('ok',$output,$uhome);
1340: } else {
1341: $output = &mt('Unable to retrieve your account creation information - unexpected context');
1342: undef($encpass);
1343: return ('fail',$error.$output.$end.$rtnlink);
1.1 raeburn 1344: }
1345: } else {
1.58 raeburn 1346: $output = &mt('Unable to retrieve information for your account request.');
1.1 raeburn 1347: return ('fail',$error.$output.$end.$rtnlink);
1348: }
1349: }
1350:
1351: sub username_validation {
1.19 raeburn 1352: my ($r,$username,$domain,$domdesc,$contact_name,$contact_email,$courseid,
1.35 raeburn 1353: $lonhost,$statustocreate) = @_;
1.58 raeburn 1354: # $r: request object
1.49 www 1355: # $username,$domain: for the user who needs to be validated
1356: # $domdesc: full name of the domain (for error messages)
1.58 raeburn 1357: # $contact_name, $contact_email: name and email for user assistance (for error messages in &username_check)
1358: # $courseid: ID of the course if user came to username_validation via self-enroll link,
1359: # passed to start_session()
1360: # $lonhost: LON-CAPA lonHostID
1.49 www 1361: # $statustocreate: -> inststatus in username_check ('faculty', 'staff', 'student', ...)
1362:
1.58 raeburn 1363: #
1364: # Sanitize incoming username and domain
1365: #
1.1 raeburn 1366: $username= &LONCAPA::clean_username($username);
1367: $domain = &LONCAPA::clean_domain($domain);
1.58 raeburn 1368:
1369: #
1370: # Check if LON-CAPA account already exists for $username:$domain
1371: #
1.1 raeburn 1372: my $uhome = &Apache::lonnet::homeserver($username,$domain);
1373:
1.58 raeburn 1374: my $output;
1375:
1376: # Retrieve DES key from server using logtoken
1377:
1378: my $tmpinfo=Apache::lonnet::reply('tmpget:'.$env{'form.logtoken'},$env{'form.serverid'});
1379: if (($tmpinfo=~/^error/) || ($tmpinfo eq 'con_lost')) {
1380: $output = &mt('Information needed to verify your login information is missing, inaccessible or expired.')
1381: .'<br />'.&mt('You may need to reload the previous page to obtain a new token.');
1382: return ('fail',$output);
1383: } else {
1384: my $reply = &Apache::lonnet::reply('tmpdel:'.$env{'form.logtoken'},$env{'form.serverid'});
1385: unless ($reply eq 'ok') {
1386: $output = &mt('Session could not be opened.');
1387: return ('fail',$output);
1388: }
1389: }
1390:
1391: # Split the logtoken to retrieve the DES key and decrypt the encypted password
1392:
1393: my ($key,$caller)=split(/&/,$tmpinfo);
1394: my $upass;
1395: if ($caller eq 'createaccount') {
1396: $upass = &Apache::loncommon::des_decrypt($key,$env{'form.upass'});
1397: } else {
1398: $output = &mt('Unable to retrieve your log-in information - unexpected context');
1.19 raeburn 1399: return ('fail',$output);
1400: }
1401: if ($uhome ne 'no_host') {
1402: my $result = &Apache::lonnet::authenticate($username,$upass,$domain);
1403: if ($result ne 'no_host') {
1.58 raeburn 1404: my $redirect = &start_session($r,$username,$domain,$uhome,$courseid);
1405: if ($redirect) {
1406: return ($redirect);
1407: }
1408: $output = '<br /><br />'.
1409: &mt('A LON-CAPA account already exists for username [_1] at this institution ([_2]).',
1410: '<tt>'.$username.'</tt>',$domdesc).'<br />'.
1411: &mt('The password entered was also correct so you have been logged in.');
1.19 raeburn 1412: return ('existingaccount',$output);
1413: } else {
1.22 raeburn 1414: $output = &login_failure_msg($courseid);
1.19 raeburn 1415: }
1416: } else {
1.1 raeburn 1417: my $primlibserv = &Apache::lonnet::domain($domain,'primary');
1418: my $authok;
1419: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
1.58 raeburn 1420: if ((($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) ||
1421: ($domdefaults{'auth_def'} eq 'localauth')) {
1.1 raeburn 1422: my $checkdefauth = 1;
1423: $authok =
1424: &Apache::lonnet::reply("encrypt:auth:$domain:$username:$upass:$checkdefauth",$primlibserv);
1425: } else {
1426: $authok = 'non_authorized';
1427: }
1428: if ($authok eq 'authorized') {
1.18 raeburn 1429: $output = &username_check($username,$domain,$domdesc,$courseid,$lonhost,
1.35 raeburn 1430: $contact_email,$contact_name,undef,
1431: $statustocreate);
1.4 raeburn 1432: } else {
1.22 raeburn 1433: $output = &login_failure_msg($courseid);
1.4 raeburn 1434: }
1435: }
1.19 raeburn 1436: return ('ok',$output);
1.4 raeburn 1437: }
1438:
1.22 raeburn 1439: sub login_failure_msg {
1440: my ($courseid) = @_;
1441: my $url;
1442: if ($courseid ne '') {
1443: $url = "/adm/selfenroll?courseid=".$courseid;
1444: } else {
1445: $url = "/adm/createaccount";
1446: }
1447: my $output = '<h4>'.&mt('Authentication failed').'</h4><div class="LC_warning">'.
1448: &mt('Username and/or password could not be authenticated.').
1449: '</div>'.
1450: &mt('Please check the username and password.').'<br /><br />';
1451: '<a href="'.$url.'">'.&mt('Try again').'</a>';
1452: return $output;
1453: }
1454:
1.4 raeburn 1455: sub username_check {
1.35 raeburn 1456: my ($username,$domain,$domdesc,$courseid,$lonhost,$contact_email,
1.65 raeburn 1457: $contact_name,$sso_logout,$statustocreate,$shibenv) = @_;
1.23 raeburn 1458: my (%rulematch,%inst_results,$checkfail,$rowcount,$editable,$output,$msg,
1.18 raeburn 1459: %alerts,%curr_rules,%got_rules);
1.23 raeburn 1460: &call_rulecheck($username,$domain,\%alerts,\%rulematch,
1.40 raeburn 1461: \%inst_results,\%curr_rules,\%got_rules,'username');
1.4 raeburn 1462: if (ref($alerts{'username'}) eq 'HASH') {
1463: if (ref($alerts{'username'}{$domain}) eq 'HASH') {
1464: if ($alerts{'username'}{$domain}{$username}) {
1465: if (ref($curr_rules{$domain}) eq 'HASH') {
1.18 raeburn 1466: $output =
1.17 raeburn 1467: &Apache::loncommon::instrule_disallow_msg('username',$domdesc,1,
1468: 'selfcreate').
1.4 raeburn 1469: &Apache::loncommon::user_rule_formats($domain,$domdesc,
1470: $curr_rules{$domain}{'username'},'username');
1.1 raeburn 1471: }
1.18 raeburn 1472: $checkfail = 'username';
1.1 raeburn 1473: }
1.4 raeburn 1474: }
1475: }
1.18 raeburn 1476: if (!$checkfail) {
1.35 raeburn 1477: if (ref($statustocreate) eq 'ARRAY') {
1478: $checkfail = 'inststatus';
1479: if (ref($inst_results{$username.':'.$domain}{inststatus}) eq 'ARRAY') {
1480: foreach my $inststatus (@{$inst_results{$username.':'.$domain}{inststatus}}) {
1481: if (grep(/^\Q$inststatus\E$/,@{$statustocreate})) {
1482: undef($checkfail);
1483: last;
1484: }
1485: }
1486: } elsif (grep(/^default$/,@{$statustocreate})) {
1487: undef($checkfail);
1488: }
1489: }
1490: }
1491: if (!$checkfail) {
1.18 raeburn 1492: $output = '<form method="post" action="/adm/createaccount">';
1.65 raeburn 1493: if (ref($shibenv) eq 'HASH') {
1494: foreach my $key (keys(%{$shibenv})) {
1.66 raeburn 1495: if ($ENV{$shibenv->{$key}} ne '') {
1496: $inst_results{$username.':'.$domain}{$key} = $ENV{$shibenv->{$key}};
1497: }
1.65 raeburn 1498: }
1499: }
1.18 raeburn 1500: (my $datatable,$rowcount,$editable) =
1501: &Apache::loncreateuser::personal_data_display($username,$domain,1,'selfcreate',
1502: $inst_results{$username.':'.$domain});
1503: if ($rowcount > 0) {
1504: $output .= $datatable;
1505: }
1506: $output .= '<br /><br /><input type="hidden" name="uname" value="'.$username.'" />'."\n".
1507: '<input type="hidden" name="udom" value="'.$domain.'" />'."\n".
1508: '<input type="hidden" name="phase" value="username_activation" />';
1509: my $now = time;
1510: my %info = ('ip' => $ENV{'REMOTE_ADDR'},
1511: 'time' => $now,
1512: 'domain' => $domain,
1513: 'username' => $username);
1.41 raeburn 1514: my $authtoken = &Apache::lonnet::tmpput(\%info,$lonhost,'createaccount');
1.18 raeburn 1515: if ($authtoken !~ /^error/ && $authtoken ne 'no_such_host') {
1516: $output .= '<input type="hidden" name="authtoken" value="'.&HTML::Entities::encode($authtoken,'&<>"').'" />';
1517: } else {
1518: $output = &mt('An error occurred when storing a token').'<br />'.
1519: &mt('You will not be able to proceed to the next stage of account creation').
1520: &linkto_email_help($contact_email,$domdesc);
1521: $checkfail = 'authtoken';
1522: }
1523: }
1524: if ($checkfail) {
1.47 raeburn 1525: $msg = '<br /><h4>'.&mt('Account creation unavailable').'</h4>';
1.18 raeburn 1526: if ($checkfail eq 'username') {
1527: $msg .= '<span class="LC_warning">'.
1528: &mt('A LON-CAPA account may not be created with the username you use.').
1529: '</span><br /><br />'.$output;
1530: } elsif ($checkfail eq 'authtoken') {
1531: $msg .= '<span class="LC_error">'.&mt('Error creating token.').'</span>'.
1532: '<br />'.$output;
1.35 raeburn 1533: } elsif ($checkfail eq 'inststatus') {
1534: $msg .= '<span class="LC_warning">'.
1535: &mt('You are not permitted to create a LON-CAPA account.').
1536: '</span><br /><br />'.$output;
1.18 raeburn 1537: }
1538: $msg .= &mt('Please contact the [_1] ([_2]) for assistance.',
1539: $contact_name,$contact_email).'<br /><hr />'.
1540: $sso_logout;
1541: &Apache::lonnet::logthis("ERROR: failure type of '$checkfail' when performing username check to create account for authenticated user: $username, in domain $domain");
1.8 raeburn 1542: } else {
1.18 raeburn 1543: if ($courseid ne '') {
1544: $output .= '<input type="hidden" name="courseid" value="'.$courseid.'" />';
1545: }
1546: $output .= '<input type="submit" name="newaccount" value="'.
1547: &mt('Create LON-CAPA account').'" /></form>';
1548: if ($rowcount) {
1549: if ($editable) {
1.22 raeburn 1550: if ($courseid ne '') {
1.47 raeburn 1551: $msg = '<br /><h4>'.&mt('User information').'</h4>';
1.22 raeburn 1552: }
1553: $msg .= &mt('To create one, use the table below to provide information about yourself, then click the [_1]Create LON-CAPA account[_2] button.','<span class="LC_cusr_emph">','</span>').'<br />';
1.18 raeburn 1554: } else {
1.22 raeburn 1555: if ($courseid ne '') {
1556: $msg = '<h4>'.&mt('Review user information').'</h4>';
1557: }
1558: $msg .= &mt('A user account will be created with information displayed in the table below, when you click the [_1]Create LON-CAPA account[_2] button.','<span class="LC_cusr_emph">','</span>').'<br />';
1.18 raeburn 1559: }
1560: } else {
1.22 raeburn 1561: if ($courseid ne '') {
1562: $msg = '<h4>'.&mt('Confirmation').'</h4>';
1563: }
1564: $msg .= &mt('Confirm that you wish to create an account.');
1.18 raeburn 1565: }
1566: $msg .= $output;
1567: }
1568: return $msg;
1.1 raeburn 1569: }
1570:
1571: sub username_activation {
1.51 raeburn 1572: my ($r,$username,$domain,$domdesc,$courseid) = @_;
1.1 raeburn 1573: my $output;
1.7 bisitz 1574: my $error = '<span class="LC_error">'.&mt('Error:').' ';
1.1 raeburn 1575: my $end = '</span><br /><br />';
1.54 bisitz 1576: my $rtnlink = '<a href="javascript:history.back();">'.
1.1 raeburn 1577: &mt('Return to previous page').'</a>'.
1578: &Apache::loncommon::end_page();
1579: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
1.8 raeburn 1580: my %data = &Apache::lonnet::tmpget($env{'form.authtoken'});
1581: my $now = time;
1582: my $earlyout;
1583: my $timeout = 300;
1584: if (keys(%data) == 0) {
1585: $output = &mt('Sorry, your authentication has expired.');
1586: $earlyout = 'fail';
1587: }
1588: if (($data{'time'} !~ /^\d+$/) ||
1589: ($data{'domain'} ne $domain) ||
1590: ($data{'username'} ne $username)) {
1591: $earlyout = 'fail';
1592: $output = &mt('The credentials you provided could not be verified.');
1593: } elsif ($now - $data{'time'} > $timeout) {
1594: $earlyout = 'fail';
1595: $output = &mt('Sorry, your authentication has expired.');
1596: }
1597: if ($earlyout ne '') {
1.56 raeburn 1598: my $link = '/adm/createaccount';
1599: if (&Apache::lonnet::domain($domain) ne '') {
1600: $link .= "?domain=$domain";
1601: }
1602: $output .= '<br />'.&mt('Please [_1]start again[_2].',
1603: '<a href="'.$link.'">','</a>');
1.8 raeburn 1604: return($earlyout,$output);
1605: }
1.3 raeburn 1606: if ((($domdefaults{'auth_def'} =~/^krb(4|5)$/) &&
1607: ($domdefaults{'auth_arg_def'} ne '')) ||
1608: ($domdefaults{'auth_def'} eq 'localauth')) {
1.22 raeburn 1609: if ($env{'form.courseid'} ne '') {
1.58 raeburn 1610: my $id = $env{'form.cid'};
1611: my ($result,$userchkmsg) = &check_id($username,$domain,$id,$domdesc,'institutional');
1.1 raeburn 1612: if ($result eq 'fail') {
1613: $output = $error.&mt('Invalid ID format').$end.
1614: $userchkmsg.$rtnlink;
1615: return ('fail',$output);
1616: }
1617: }
1618: # Call modifyuser
1.23 raeburn 1619: my (%rulematch,%inst_results,%curr_rules,%got_rules,%alerts,%info);
1620: &call_rulecheck($username,$domain,\%alerts,\%rulematch,
1.40 raeburn 1621: \%inst_results,\%curr_rules,\%got_rules);
1.23 raeburn 1622: my @userinfo = ('firstname','middlename','lastname','generation',
1623: 'permanentemail','id');
1624: my %canmodify =
1625: &Apache::loncreateuser::selfcreate_canmodify('selfcreate',$domain,
1626: \@userinfo,\%inst_results);
1627: foreach my $item (@userinfo) {
1628: if ($canmodify{$item}) {
1629: $info{$item} = $env{'form.c'.$item};
1630: } else {
1631: $info{$item} = $inst_results{$username.':'.$domain}{$item};
1632: }
1633: }
1634: if (ref($inst_results{$username.':'.$domain}{'inststatus'}) eq 'ARRAY') {
1635: my @inststatuses = @{$inst_results{$username.':'.$domain}{'inststatus'}};
1636: $info{'inststatus'} = join(':',map { &escape($_); } @inststatuses);
1637: }
1.1 raeburn 1638: my $result =
1.23 raeburn 1639: &Apache::lonnet::modifyuser($domain,$username,$env{'form.cid'},
1.1 raeburn 1640: $domdefaults{'auth_def'},
1.23 raeburn 1641: $domdefaults{'auth_arg_def'},$info{'firstname'},
1642: $info{'middlename'},$info{'lastname'},
1643: $info{'generation'},undef,undef,
1644: $info{'permanentemail'},$info{'inststatus'});
1.3 raeburn 1645: if ($result eq 'ok') {
1.8 raeburn 1646: my $delete = &Apache::lonnet::tmpdel($env{'form.authtoken'});
1.3 raeburn 1647: $output = &mt('A LON-CAPA account has been created for username: [_1] in domain: [_2].',$username,$domain);
1.51 raeburn 1648: my $uhome=&Apache::lonnet::homeserver($username,$domain,'true');
1.3 raeburn 1649: my $nostart = 1;
1.58 raeburn 1650: my $response = 'ok';
1651: my $redirect = &start_session($r,$username,$domain,$uhome,$courseid);
1652: if ($redirect) {
1653: $response = $redirect;
1654: }
1655: return ($response,$output,$nostart);
1.3 raeburn 1656: } else {
1657: $output = &mt('Account creation failed for username: [_1] in domain: [_2].',$username,$domain).'<br /><span class="LC_error">'.&mt('Error: [_1]',$result).'</span>';
1658: return ('fail',$output);
1659: }
1.1 raeburn 1660: } else {
1.7 bisitz 1661: $output = &mt('User account creation is not available for the current default authentication type.')."\n";
1.1 raeburn 1662: return('fail',$output);
1663: }
1664: }
1665:
1666: sub check_id {
1.58 raeburn 1667: my ($username,$domain,$id,$domdesc,$usernametype) = @_;
1668: # Check student/employee ID format
1669: # Is proposed student/employee ID acceptable according to domain's rules.
1.50 www 1670: # $domdesc is just used for user error messages
1.1 raeburn 1671: my (%alerts,%rulematch,%inst_results,%curr_rules,%checkhash);
1672: my %checks = ('id' => 1);
1673: %{$checkhash{$username.':'.$domain}} = (
1674: 'newuser' => 1,
1.58 raeburn 1675: 'id' => $id,
1.1 raeburn 1676: );
1677: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
1678: \%rulematch,\%inst_results,\%curr_rules);
1679: if (ref($alerts{'id'}) eq 'HASH') {
1680: if (ref($alerts{'id'}{$domain}) eq 'HASH') {
1681: if ($alerts{'id'}{$domain}{$env{'form.cid'}}) {
1682: my $userchkmsg;
1683: if (ref($curr_rules{$domain}) eq 'HASH') {
1.58 raeburn 1684: if ($usernametype eq 'email') {
1685: $userchkmsg = &mt('A student/employee ID has not been set because the value suggested matched the format used for institutional users in the domain, and you are using an e-mail address as username, not an institutional username.');
1686: } else {
1687: $userchkmsg =
1688: &Apache::loncommon::instrule_disallow_msg('id',
1689: $domdesc,1).
1690: &Apache::loncommon::user_rule_formats($domain,
1691: $domdesc,$curr_rules{$domain}{'id'},'id');
1692: }
1.1 raeburn 1693: }
1694: return ('fail',$userchkmsg);
1695: }
1696: }
1697: }
1698: return;
1699: }
1700:
1701: sub invalid_state {
1702: my ($error,$domdesc,$contact_name,$contact_email,$msgtext) = @_;
1.14 raeburn 1703: my $msg = '<h3>'.&mt('Account creation unavailable').'</h3><span class="LC_error">';
1.1 raeburn 1704: if ($error eq 'baduseremail') {
1.42 raeburn 1705: $msg .= &mt('The e-mail address you provided does not appear to be a valid address.');
1.58 raeburn 1706: } elsif ($error eq 'badusername') {
1707: $msg .= &mt('The e-mail address you provided contains characters which prevent its use as a username in LON-CAPA.');
1.1 raeburn 1708: } elsif ($error eq 'existinguser') {
1.42 raeburn 1709: $msg .= &mt('The e-mail address you provided is already in use as a username in LON-CAPA at this institution.');
1.1 raeburn 1710: } elsif ($error eq 'userrules') {
1.42 raeburn 1711: $msg .= &mt('Username rules at this institution do not allow the e-mail address you provided to be used as a username.');
1.1 raeburn 1712: } elsif ($error eq 'userformat') {
1.42 raeburn 1713: $msg .= &mt('The e-mail address you provided may not be used as a username at this LON-CAPA institution.');
1.1 raeburn 1714: } elsif ($error eq 'captcha') {
1.43 raeburn 1715: $msg .= &mt('Validation of the code you entered failed.');
1.1 raeburn 1716: } elsif ($error eq 'noemails') {
1.42 raeburn 1717: $msg .= &mt('Creation of a new user account using an e-mail address as username is not permitted at this LON-CAPA institution.');
1.73 raeburn 1718: } elsif ($error eq 'emailfail') {
1719: $msg .= &mt('Creation of a new user account with verification by e-mail is not permitted with the e-mail address you provided');
1.1 raeburn 1720: }
1.14 raeburn 1721: $msg .= '</span>';
1.1 raeburn 1722: if ($msgtext) {
1723: $msg .= '<br />'.$msgtext;
1724: }
1.44 raeburn 1725: $msg .= &linkto_email_help($contact_email,$domdesc,$error);
1.8 raeburn 1726: return $msg;
1727: }
1728:
1729: sub linkto_email_help {
1.44 raeburn 1730: my ($contact_email,$domdesc,$error) = @_;
1.8 raeburn 1731: my $msg;
1.44 raeburn 1732: my $href = '/adm/helpdesk';
1.1 raeburn 1733: if ($contact_email ne '') {
1734: my $escuri = &HTML::Entities::encode('/adm/createaccount','&<>"');
1.44 raeburn 1735: $href .= '?origurl='.$escuri;
1736: if ($error eq 'existinguser') {
1737: my $escemail = &HTML::Entities::encode($env{'form.useremail'});
1738: $href .= '&useremail='.$escemail.'&useraccount='.$escemail;
1739: }
1740: $msg .= '<br />'.&mt('You may wish to contact the [_1]LON-CAPA helpdesk[_2] for [_3].','<a href="'.$href.'">','</a>',$domdesc).'<br />';
1.1 raeburn 1741: } else {
1.55 raeburn 1742: $msg .= '<br />'.&mt('You may wish to send an e-mail to the server administrator: [_1] for [_2].',$Apache::lonnet::perlvar{'AdmEMail'},$domdesc).'<br />';
1.1 raeburn 1743: }
1744: return $msg;
1745: }
1746:
1747: sub getkeys {
1748: my ($lkey,$ukey) = @_;
1749: my $lextkey=hex($lkey);
1750: if ($lextkey>2147483647) { $lextkey-=4294967296; }
1751:
1752: my $uextkey=hex($ukey);
1753: if ($uextkey>2147483647) { $uextkey-=4294967296; }
1754: return ($lextkey,$uextkey);
1755: }
1756:
1757: sub serverform {
1.20 raeburn 1758: my ($logtoken,$lonhost,$mailtoken,$courseid,$context) = @_;
1.22 raeburn 1759: my $phase = 'username_validation';
1760: my $catalog_elements;
1.20 raeburn 1761: if ($context eq 'selfenroll') {
1762: $phase = 'selfenroll_login';
1763: }
1.22 raeburn 1764: if ($courseid ne '') {
1765: $catalog_elements = &Apache::lonhtmlcommon::echo_form_input(['courseid','phase']);
1766: }
1767: my $output = <<ENDSERVERFORM;
1.20 raeburn 1768: <form name="server" method="post" action="/adm/createaccount">
1.1 raeburn 1769: <input type="hidden" name="logtoken" value="$logtoken" />
1770: <input type="hidden" name="token" value="$mailtoken" />
1771: <input type="hidden" name="serverid" value="$lonhost" />
1772: <input type="hidden" name="uname" value="" />
1773: <input type="hidden" name="upass" value="" />
1.32 raeburn 1774: <input type="hidden" name="udom" value="" />
1.20 raeburn 1775: <input type="hidden" name="phase" value="$phase" />
1.3 raeburn 1776: <input type="hidden" name="courseid" value="$courseid" />
1.22 raeburn 1777: $catalog_elements
1.1 raeburn 1778: </form>
1779: ENDSERVERFORM
1780: return $output;
1781: }
1782:
1.58 raeburn 1783: sub store_request {
1784: my ($dom,$username,$val,$dataref,$settings) = @_;
1785: my $output;
1786: my $domconfiguser = &Apache::lonnet::get_domainconfiguser($dom);
1787: my $key = &escape($username);
1788: my $now = time();
1789: if (&Apache::lonnet::put('usernamequeue', { $key.'_'.$val => $now },
1790: $dom,$domconfiguser) eq 'ok') {
1791: if (ref($dataref) eq 'HASH') {
1792: my $logtoken = $dataref->{'tmpinfo'};
1793: my $serverid = $dataref->{'serverid'};
1794: if ($logtoken && $serverid) {
1795: my $tmpinfo=Apache::lonnet::reply('tmpget:'.$logtoken,$serverid);
1796: unless (($tmpinfo=~/^error/) || ($tmpinfo eq 'con_lost')) {
1797: my $reply = &Apache::lonnet::reply('tmpdel:'.$logtoken,$serverid);
1798: if ($reply eq 'ok') {
1799: my ($key,$caller)=split(/&/,$tmpinfo);
1800: $dataref->{'key'} = $key;
1801: undef($dataref->{'tmpinfo'});
1802: undef($dataref->{'serverid'});
1803: }
1804: }
1805: }
1806: }
1807: my %userrequest = ( $username => $dataref );
1808: $userrequest{$username}{timestamp} = $now;
1809: $userrequest{$username}{status} = $val;
1810: my $notifylist;
1811: if (ref($settings) eq 'HASH') {
1812: if (ref($settings->{'cancreate'}) eq 'HASH') {
1813: if (ref($settings->{'cancreate'}{'notify'}) eq 'HASH') {
1814: my $notifylist = $settings->{'cancreate'}{'notify'}{'approval'};
1815: if ($notifylist) {
1816: my $sender = $domconfiguser.':'.$dom;
1817: my $domdesc = &Apache::lonnet::domain($dom,'description');
1818: my $fullname;
1819: if (ref($dataref) eq 'HASH') {
1820: if ($dataref->{'firstname'}) {
1821: $fullname = $dataref->{'firstname'};
1822: }
1823: if ($dataref->{'lastname'}) {
1824: $fullname .= ' '.$dataref->{'lastname'};
1825: }
1826: $fullname =~ s/^\s+|\s+$//g;
1827: }
1828: &Apache::loncoursequeueadmin::send_selfserve_notification($notifylist,
1829: "$fullname ($username)",
1830: undef,$domdesc,$now,'usernamereq',$sender);
1831: }
1832: }
1833: }
1.1 raeburn 1834: }
1.58 raeburn 1835: my $userresult =
1836: &Apache::lonnet::put('nohist_requestedusernames',\%userrequest,$dom,$domconfiguser);
1837: $output = '<p class="LC_info">'.
1838: &mt('Your request for a LON-CAPA account has been submitted for approval.').
1839: '</p>'.
1840: '<p class="LC_info">'.
1841: &mt('An e-mail will be sent to [_1] when your request has been reviewed by an administrator and action has been taken.',$username).
1842: '</p>';
1.1 raeburn 1843: } else {
1.58 raeburn 1844: $output = '<span class="LC_error">'.
1845: &mt('An error occurred when attempting to save your request for a LON-CAPA account.');
1846: '</span>';
1.1 raeburn 1847: }
1.58 raeburn 1848: return $output;
1.1 raeburn 1849: }
1850:
1851: sub guest_format_check {
1.74 raeburn 1852: my ($useremail,$domain,$cancreate,$settings,$usertype) = @_;
1.1 raeburn 1853: my ($login,$format_match,$format_msg,@user_rules);
1854: if (ref($settings) eq 'HASH') {
1855: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
1856: push(@user_rules,@{$settings->{'email_rule'}});
1.74 raeburn 1857: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
1858: if (ref($settings->{'email_rule'}->{$usertype}) eq 'ARRAY') {
1859: push(@user_rules,@{$settings->{'email_rule'}->{$usertype}});
1860: }
1.1 raeburn 1861: }
1862: }
1863: if (@user_rules > 0) {
1864: my %rule_check =
1865: &Apache::lonnet::inst_rulecheck($domain,$useremail,undef,
1.2 raeburn 1866: 'selfcreate',\@user_rules);
1.1 raeburn 1867: if (keys(%rule_check) > 0) {
1868: foreach my $item (keys(%rule_check)) {
1869: if ($rule_check{$item}) {
1870: $format_match = 1;
1871: last;
1872: }
1873: }
1874: }
1875: }
1876: if ($format_match) {
1877: ($login) = ($useremail =~ /^([^\@]+)\@/);
1.58 raeburn 1878: $format_msg = '<br />'.
1879: &mt("Your e-mail address uses the same internet domain as your institution's LON-CAPA service.").'<br />'.
1880: &mt('Creation of a LON-CAPA account with this type of e-mail address as username is not permitted.').'<br />';
1.5 raeburn 1881: if (ref($cancreate) eq 'ARRAY') {
1882: if (grep(/^login$/,@{$cancreate})) {
1.7 bisitz 1883: $format_msg .= &mt('You should request creation of a LON-CAPA account for a log-in ID of "[_1]" at your institution instead.',$login).'<br />';
1.5 raeburn 1884: }
1.1 raeburn 1885: }
1886: }
1887: return $format_msg;
1888: }
1889:
1.17 raeburn 1890: sub sso_logout_frag {
1891: my ($r,$domain) = @_;
1892: my $endsessionmsg;
1893: if (defined($r->dir_config('lonSSOUserLogoutMessageFile_'.$domain))) {
1894: my $msgfile = $r->dir_config('lonSSOUserLogoutMessageFile_'.$domain);
1895: if (-e $msgfile) {
1.76 raeburn 1896: open(my $fh,"<",$msgfile);
1.17 raeburn 1897: $endsessionmsg = join('',<$fh>);
1898: close($fh);
1899: }
1900: } elsif (defined($r->dir_config('lonSSOUserLogoutMessageFile'))) {
1901: my $msgfile = $r->dir_config('lonSSOUserLogoutMessageFile');
1902: if (-e $msgfile) {
1.76 raeburn 1903: open(my $fh,"<",$msgfile);
1.17 raeburn 1904: $endsessionmsg = join('',<$fh>);
1905: close($fh);
1906: }
1907: }
1908: return $endsessionmsg;
1909: }
1910:
1.22 raeburn 1911: sub catreturn_js {
1912: return <<"ENDSCRIPT";
1913: <script type="text/javascript">
1.62 raeburn 1914: // <![CDATA[
1.22 raeburn 1915: function ToSelfenroll(formname) {
1916: var formidx = getFormByName(formname);
1917: if (formidx > -1) {
1918: document.forms[formidx].action = '/adm/selfenroll';
1919: numidx = getIndexByName(formidx,'phase');
1920: if (numidx > -1) {
1921: document.forms[formidx].elements[numidx].value = '';
1922: }
1923: numidx = getIndexByName(formidx,'context');
1924: if (numidx > -1) {
1925: document.forms[formidx].elements[numidx].value = '';
1926: }
1927: }
1928: document.forms[formidx].submit();
1929: }
1930:
1931: function ToCatalog(formname,caller) {
1932: var formidx = getFormByName(formname);
1933: if (formidx > -1) {
1934: document.forms[formidx].action = '/adm/coursecatalog';
1935: numidx = getIndexByName(formidx,'coursenum');
1936: if (numidx > -1) {
1937: if (caller != 'details') {
1938: document.forms[formidx].elements[numidx].value = '';
1939: }
1940: }
1941: }
1942: document.forms[formidx].submit();
1943: }
1944:
1945: function getIndexByName(formidx,item) {
1946: for (var i=0;i<document.forms[formidx].elements.length;i++) {
1947: if (document.forms[formidx].elements[i].name == item) {
1948: return i;
1949: }
1950: }
1951: return -1;
1952: }
1953:
1954: function getFormByName(item) {
1955: for (var i=0; i<document.forms.length; i++) {
1956: if (document.forms[i].name == item) {
1957: return i;
1958: }
1959: }
1960: return -1;
1961: }
1.62 raeburn 1962: // ]]>
1.22 raeburn 1963: </script>
1964: ENDSCRIPT
1965:
1966: }
1967:
1.73 raeburn 1968: sub setelements_js {
1969: my ($statusforemail,$types,$usertypes,$othertitle) = @_;
1970: my ($posstypes,$posstypesnames,$availabletypes);
1971: if ((ref($statusforemail) eq 'ARRAY') && (ref($types) eq 'ARRAY') &&
1972: (ref($usertypes) eq 'HASH')) {
1973: $posstypes = join("','",@{$types},'default');
1974: $posstypesnames = join("','",(map {$usertypes->{$_};} @{$types}),$othertitle);
1975: $availabletypes = join("','", @{$statusforemail});
1976: }
1977: return <<"ENDSCRIPT";
1978: <script type="text/javascript">
1979: // <![CDATA[
1980:
1981: function setElements() {
1982: if (document.getElementById('LC_reportstatus')) {
1983: var reportnum = document.reportstatus.type.length;
1984: if ((reportnum != 'undefined') && (typeof(document.reportstatus.type) != 'undefined')) {
1985: for (var i=0; i<reportnum; i++) {
1986: document.reportstatus.type[i].checked = false;
1987: }
1988: }
1989: }
1990: }
1991:
1992: function checkVerification() {
1993: var curr;
1994: var cancreate = false;
1995: var reportnum = document.reportstatus.type.length;
1996: if ((reportnum == 'undefined') && (typeof(document.reportstatus.type) != 'undefined')) {
1997: curr = document.reportstatus.type.value;
1998: } else if (document.reportstatus.type.length) {
1999: for (var i=0; i<document.reportstatus.type.length; i++) {
2000: if (document.reportstatus.type[i].checked) {
2001: curr = document.reportstatus.type[i].value;
2002: break;
2003: }
2004: }
2005: }
2006: var types = Array('$posstypes');
2007: var names = Array('$posstypesnames');
2008: var available = Array('$availabletypes');
2009: if (available.length) {
2010: for (var i=0; i<available.length; i++) {
2011: if (curr == available[i]) {
2012: cancreate = true;
2013: break;
2014: }
2015: }
2016: }
2017: if (types.length > 0) {
2018: for (var j=0; j<types.length; j++) {
2019: if (curr == types[j]) {
2020: if (!cancreate) {
2021: alert('Creation of an account via verification by e-mail unavailable for user type: "'+names[j]+'"');
1.75 raeburn 2022: setElements();
1.73 raeburn 2023: }
2024: break;
2025: }
2026: }
2027: }
2028: if (cancreate) {
2029: return true;
2030: } else {
2031: return false;
2032: }
2033: }
2034:
2035: // ]]>
2036: </script>
2037: ENDSCRIPT
2038:
2039: }
2040:
2041: sub username_js {
2042: return <<"ENDSCRIPT";
2043: <script type="text/javascript">
2044: // <![CDATA[
2045:
1.74 raeburn 2046: function toggleUsernameDisp(caller,divid) {
1.73 raeburn 2047: if (document.getElementById(divid)) {
2048: if (caller.checked) {
2049: if (caller.value == '1') {
2050: document.getElementById(divid).style.display = 'none';
2051: } else {
2052: document.getElementById(divid).style.display = 'inline';
2053: }
2054: }
2055: }
2056: }
2057: // ]]>
2058: </script>
2059: ENDSCRIPT
2060:
2061: }
2062:
1.1 raeburn 2063: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>