Annotation of loncom/interface/createaccount.pm, revision 1.8
1.1 raeburn 1: # The LearningOnline Network
2: # Allow visitors to create a user account with the username being either an
3: # institutional log-in ID (institutional authentication required - localauth
4: # or kerberos) or an e-mail address.
5: #
1.8 ! raeburn 6: # $Id: createaccount.pm,v 1.7 2008/07/01 16:41:57 bisitz Exp $
1.1 raeburn 7: #
8: # Copyright Michigan State University Board of Trustees
9: #
10: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
11: #
12: # LON-CAPA is free software; you can redistribute it and/or modify
13: # it under the terms of the GNU General Public License as published by
14: # the Free Software Foundation; either version 2 of the License, or
15: # (at your option) any later version.
16: #
17: # LON-CAPA is distributed in the hope that it will be useful,
18: # but WITHOUT ANY WARRANTY; without even the implied warranty of
19: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20: # GNU General Public License for more details.
21: #
22: # You should have received a copy of the GNU General Public License
23: # along with LON-CAPA; if not, write to the Free Software
24: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25: #
26: # /home/httpd/html/adm/gpl.txt
27: #
28: # http://www.lon-capa.org/
29: #
30: #
31: package Apache::createaccount;
32:
33: use strict;
34: use Apache::Constants qw(:common);
35: use Apache::lonacc;
36: use Apache::lonnet;
37: use Apache::loncommon;
38: use Apache::lonlocal;
1.3 raeburn 39: use Apache::lonauth;
1.1 raeburn 40: use Apache::resetpw;
41: use Authen::Captcha;
42: use DynaLoader; # for Crypt::DES version
43: use Crypt::DES;
1.3 raeburn 44: use LONCAPA qw(:DEFAULT :match);
1.8 ! raeburn 45: use HTML::Entities;
1.1 raeburn 46:
47: sub handler {
48: my $r = shift;
49: &Apache::loncommon::content_type($r,'text/html');
50: $r->send_http_header;
51: if ($r->header_only) {
52: return OK;
53: }
1.5 raeburn 54:
55: my $domain;
1.3 raeburn 56:
1.5 raeburn 57: my $sso_username = $r->subprocess_env->get('REDIRECT_SSOUserUnknown');
58: my $sso_domain = $r->subprocess_env->get('REDIRECT_SSOUserDomain');
59:
60: if ($sso_username ne '' && $sso_domain ne '') {
61: $domain = $sso_domain;
62: } else {
63: $domain = &Apache::lonnet::default_login_domain();
64: }
1.1 raeburn 65: my $domdesc = &Apache::lonnet::domain($domain,'description');
66: my $contact_name = &mt('LON-CAPA helpdesk');
67: my $contact_email = $r->dir_config('lonSupportEMail');
68: my $lonhost = $r->dir_config('lonHostID');
69: my $include = $r->dir_config('lonIncludes');
1.4 raeburn 70: my $start_page;
1.3 raeburn 71:
72: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['token','courseid']);
1.1 raeburn 73: &Apache::lonacc::get_posted_cgi($r);
74: &Apache::lonlocal::get_language_handle($r);
1.3 raeburn 75:
76: my $handle = &Apache::lonnet::check_for_valid_session($r);
77: if ($handle ne '') {
1.4 raeburn 78: $start_page =
1.3 raeburn 79: &Apache::loncommon::start_page('Already logged in');
80: my $end_page =
81: &Apache::loncommon::end_page();
82: $r->print($start_page."\n".'<h2>'.&mt('You are already logged in').'</h2>'.
83: '<p>'.&mt('Please either [_1]continue the current session[_2] or [_3]logout[_4].','<a href="/adm/roles">','</a>','<a href="/adm/logout">','</a>').
1.6 bisitz 84: '</p><p><a href="/adm/loginproblems.html">'.&mt('Login problems?').'</a></p>'.$end_page);
1.3 raeburn 85: return OK;
86: }
1.4 raeburn 87: $start_page =
88: &Apache::loncommon::start_page('Create a user account in LON-CAPA','',
89: {'no_inline_link' => 1,});
90: if ($env{'form.phase'} eq 'username_activation') {
91: if ($env{'form.udom'} ne '') {
92: $domain = $env{'form.udom'};
93: }
94: }
1.5 raeburn 95: my @cancreate;
1.1 raeburn 96: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$domain);
97: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.3 raeburn 98: if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
1.5 raeburn 99: if (ref($domconfig{'usercreation'}{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
100: @cancreate = @{$domconfig{'usercreation'}{'cancreate'}{'selfcreate'}};
101: } elsif (($domconfig{'usercreation'}{'cancreate'}{'selfcreate'} ne 'none') &&
102: ($domconfig{'usercreation'}{'cancreate'}{'selfcreate'} ne '')) {
103: @cancreate = ($domconfig{'usercreation'}{'cancreate'}{'selfcreate'});
1.1 raeburn 104: }
105: }
106: }
1.3 raeburn 107:
1.5 raeburn 108: if (@cancreate == 0) {
1.3 raeburn 109: &print_header($r,$start_page);
1.7 bisitz 110: my $output = &mt('Creation of a new user account using an e-mail address or an institutional log-in ID as username is not permitted in the domain: [_1] ([_2]).',$domain,$domdesc);
1.3 raeburn 111: $r->print($output);
112: $r->print(&Apache::loncommon::end_page());
113: return OK;
114: }
115:
1.5 raeburn 116: my $courseid;
117: if (defined($env{'form.courseid'})) {
118: $courseid = &validate_course($env{'form.courseid'});
119: }
120:
121: if ($sso_username ne '') {
122: &print_header($r,$start_page);
123: my ($output,$msg);
124: if (grep(/^sso$/,@cancreate)) {
125: $msg = &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 in this domain.");
1.8 ! raeburn 126: ($output, my $checkfail) = &username_check($sso_username,$domain,
! 127: $domdesc,$courseid,
! 128: $lonhost,$contact_email);
! 129: if ($checkfail eq 'username') {
1.5 raeburn 130: $msg .= &mt('A LON-CAPA account may not be created with the username you use.');
1.8 ! raeburn 131: } elsif ($checkfail eq 'authtoken') {
! 132: $msg .= &mt('Error creating token.');
1.5 raeburn 133: } else {
134: $msg .= &mt('To create one, use the table below to provide information about yourself (if appropriate), then click the "Create LON-CAPA account" button.');
135: }
136: } else {
137: $msg = &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 in this domain, and you are not permitted to create one.");
138: }
139: $r->print('<h4>'.$msg.'</h4>'.$output);
140: $r->print(&Apache::loncommon::end_page());
141: return OK;
142: }
143:
1.4 raeburn 144: my ($output,$nostart,$noend);
1.3 raeburn 145: my $token = $env{'form.token'};
146: if ($token) {
147: ($output,$nostart,$noend) =
148: &process_mailtoken($r,$token,$contact_name,$contact_email,$domain,
1.4 raeburn 149: $domdesc,$lonhost,$include,$start_page);
1.3 raeburn 150: if ($nostart) {
151: if ($noend) {
152: return OK;
153: } else {
154: $r->print($output);
155: $r->print(&Apache::loncommon::end_page());
156: return OK;
157: }
158: } else {
159: &print_header($r,$start_page);
160: $r->print($output);
161: $r->print(&Apache::loncommon::end_page());
162: return OK;
163: }
164: }
165:
166: if ($env{'form.phase'} eq 'username_activation') {
167: (my $result,$output,$nostart) =
168: &username_activation($r,$env{'form.uname'},$domain,$domdesc,
169: $lonhost,$courseid);
170: if ($result eq 'ok') {
171: if ($nostart) {
172: return OK;
173: }
174: }
175: &print_header($r,$start_page);
176: $r->print($output);
177: $r->print(&Apache::loncommon::end_page());
178: return OK;
179: }
180:
181: &print_header($r,$start_page);
182: if ($env{'form.create_with_email'}) {
1.1 raeburn 183: $output = &process_email_request($env{'form.useremail'},$domain,$domdesc,
1.5 raeburn 184: $contact_name,$contact_email,\@cancreate,
1.3 raeburn 185: $lonhost,$domconfig{'usercreation'},
186: $courseid);
1.1 raeburn 187: } elsif ($env{'form.phase'} eq 'username_validation') {
188: $output = &username_validation($env{'form.uname'},$domain,$domdesc,
1.8 ! raeburn 189: $contact_name,$contact_email,$courseid,
! 190: $lonhost);
1.3 raeburn 191: } elsif (!$token) {
1.1 raeburn 192: my $now=time;
1.5 raeburn 193: if (grep(/^login$/,@cancreate)) {
1.1 raeburn 194: my $jsh=Apache::File->new($include."/londes.js");
195: $r->print(<$jsh>);
196: $r->print(&javascript_setforms($now));
197: }
1.5 raeburn 198: $output = &print_username_form($domain,$domdesc,\@cancreate,$now,$lonhost,
1.3 raeburn 199: $courseid);
1.1 raeburn 200: }
201: $r->print($output);
202: $r->print(&Apache::loncommon::end_page());
203: return OK;
204: }
205:
1.3 raeburn 206: sub print_header {
207: my ($r,$start_page) = @_;
208: $r->print($start_page);
209: &Apache::lonhtmlcommon::clear_breadcrumbs();
210: &Apache::lonhtmlcommon::add_breadcrumb
211: ({href=>"/adm/createuser",
212: text=>"New username"});
213: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Create account'));
214: return;
215: }
216:
217: sub validate_course {
218: my ($courseid) = @_;
219: my ($cdom,$cnum) = ($courseid =~ /^($match_domain)_($match_courseid)$/);
220: if (($cdom ne '') && ($cnum ne '')) {
221: if (&Apache::lonnet::is_course($cdom,$cnum)) {
222: return ($courseid);
223: }
224: }
225: return;
226: }
227:
1.1 raeburn 228: sub javascript_setforms {
229: my ($now) = @_;
230: my $js = <<ENDSCRIPT;
231: <script language="JavaScript">
232: function send() {
233: this.document.server.elements.uname.value = this.document.client.elements.uname.value;
234: uextkey=this.document.client.elements.uextkey.value;
235: lextkey=this.document.client.elements.lextkey.value;
236: initkeys();
237:
238: this.document.server.elements.upass.value
239: = crypted(this.document.client.elements.upass$now.value);
240:
241: this.document.client.elements.uname.value='';
242: this.document.client.elements.upass$now.value='';
243:
244: this.document.server.submit();
245: return false;
246: }
247: </script>
248: ENDSCRIPT
249: return $js;
250: }
251:
252: sub javascript_checkpass {
253: my ($now) = @_;
1.7 bisitz 254: my $nopass = &mt('You must enter a password.');
1.1 raeburn 255: my $mismatchpass = &mt('The passwords you entered did not match.').'\\n'.
256: &mt('Please try again.');
257: my $js = <<"ENDSCRIPT";
258: <script type="text/javascript" language="JavaScript">
259: function checkpass() {
260: var upass = this.document.client.elements.upass$now.value;
261: var upasscheck = this.document.client.elements.upasscheck$now.value;
262: if (upass == '') {
263: alert("$nopass");
264: return;
265: }
266: if (upass == upasscheck) {
267: this.document.client.elements.upasscheck$now.value='';
268: send();
269: return;
270: } else {
271: alert("$mismatchpass");
272: return;
273: }
274: }
275: </script>
276: ENDSCRIPT
277: return $js;
278: }
279:
280: sub print_username_form {
1.3 raeburn 281: my ($domain,$domdesc,$cancreate,$now,$lonhost,$courseid) = @_;
1.1 raeburn 282: my %lt = &Apache::lonlocal::texthash(
283: unam => 'username',
284: udom => 'domain',
285: uemail => 'Email address in LON-CAPA',
286: proc => 'Proceed');
287: my $output;
1.5 raeburn 288: if (ref($cancreate) eq 'ARRAY') {
289: if (grep(/^login$/,@{$cancreate})) {
290: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
291: if ((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth')) {
292: $output = '<div class="LC_left_float"><h3>'.&mt('Create account with a username provided by your institution').'</h3>';
1.7 bisitz 293: $output .= &mt('If you already have a log-in ID at your institution, you may be able to use it for LON-CAPA.').'<br />'.&mt('Type in your log-in ID and password to find out.').'<br /><br />';
1.5 raeburn 294: my ($lkey,$ukey) = &Apache::lonpreferences::des_keys();
295: my ($lextkey,$uextkey) = &getkeys($lkey,$ukey);
296: my $logtoken=Apache::lonnet::reply('tmpput:'.$ukey.$lkey.'&createaccount',
297: $lonhost);
298: $output .= &serverform($logtoken,$lonhost,undef,$courseid);
299: my $unameform = '<input type="text" name="uname" size="10" value="" />';
300: my $upassform = '<input type="password" name="upass'.$now.'" size="10" />';
301: my $submit_text = &mt('Create LON-CAPA account');
302: $output .= '<form name="client" method="post" action="/adm/createaccount">'."\n".
303: &Apache::lonhtmlcommon::start_pick_box()."\n".
304: &Apache::lonhtmlcommon::row_title(&mt('Log-in ID'),
1.1 raeburn 305: 'LC_pick_box_title')."\n".
1.5 raeburn 306: $unameform."\n".
307: &Apache::lonhtmlcommon::row_closure(1)."\n".
308: &Apache::lonhtmlcommon::row_title(&mt('Password'),
1.1 raeburn 309: 'LC_pick_box_title')."\n".
1.5 raeburn 310: $upassform."\n".'<br /><br />'."\n".
311: '<input type="button" name="username_validation" value="'.
312: $submit_text.'" onclick="javascript:send()" />'."\n".
313: &Apache::lonhtmlcommon::row_closure(1)."\n".
314: &Apache::lonhtmlcommon::end_pick_box().'<br /><br />'."\n".
315: '<input type="hidden" name="lextkey" value="'.$lextkey.'">'."\n".
316: '<input type="hidden" name="uextkey" value="'.$uextkey.'">'."\n".
317: '</form></div>';
318: }
319: }
320: if (grep(/^email$/,@{$cancreate})) {
321: $output .= '<div class="LC_left_float"><h3>'.&mt('Create account with an e-mail address as your username').'</h3>';
322: if (grep(/^login$/,@{$cancreate})) {
1.7 bisitz 323: $output .= &mt('Provide your e-mail address to request a LON-CAPA account if you do not have a log-in ID at your institution.').'<br /><br />';
1.5 raeburn 324: } else {
325: $output .= '<br />';
326: }
327: my $emailform = '<input type="text" name="useremail" size="25" value="" />';
328: my $captchaform = &create_captcha();
329: my $submit_text = &mt('Request LON-CAPA account');
330: $output .= '<form name="createaccount" method="post" onsubmit="validate_email();" action="/adm/createaccount">'.
331: &Apache::lonhtmlcommon::start_pick_box()."\n".
332: &Apache::lonhtmlcommon::row_title(&mt('E-mail address'),
333: 'LC_pick_box_title')."\n".
334: $emailform."\n".
335: &Apache::lonhtmlcommon::row_closure(1).
336: &Apache::lonhtmlcommon::row_title(&mt('Validation'),
337: 'LC_pick_box_title')."\n".
338: $captchaform."\n".'<br /><br />';
339: if ($courseid ne '') {
340: $output .= '<input type="hidden" name="courseid" value="'.$courseid.'"/>'."\n";
341: }
342: $output .= '<input type="submit" name="create_with_email" value="'.
343: $submit_text.'" />'.
344: &Apache::lonhtmlcommon::row_closure(1).
345: &Apache::lonhtmlcommon::end_pick_box().'<br /><br /></form>'.
346: '</div>';
1.3 raeburn 347: }
1.1 raeburn 348: }
349: if ($output eq '') {
1.7 bisitz 350: $output = &mt('Creation of a new user account using an e-mail address or an institutional log-in ID as your username is not permitted in the domain: [_1] ([_2])',$domain,$domdesc);
1.1 raeburn 351: } else {
352: $output .= '<div class="LC_clear_float_footer"></div>';
353: }
354: return $output;
355: }
356:
357: sub process_email_request {
358: my ($useremail,$domain,$domdesc,$contact_name,$contact_email,$cancreate,
1.3 raeburn 359: $server,$settings,$courseid) = @_;
1.1 raeburn 360: my $useremail = $env{'form.useremail'};
361: my $output;
1.5 raeburn 362: if (ref($cancreate) eq 'ARRAY') {
363: if (!grep(/^email$/,@{$cancreate})) {
364: $output = &invalid_state('noemails',$domdesc,
365: $contact_name,$contact_email);
366: return $output;
367: } elsif ($useremail !~ /^[^\@]+\@[^\@]+\.[^\@\.]+$/) {
368: $output = &invalid_state('baduseremail',$domdesc,
1.1 raeburn 369: $contact_name,$contact_email);
370: return $output;
371: } else {
1.5 raeburn 372: my $uhome = &Apache::lonnet::homeserver($useremail,$domain);
373: if ($uhome ne 'no_host') {
374: $output = &invalid_state('existinguser',$domdesc,
375: $contact_name,$contact_email);
1.1 raeburn 376: return $output;
1.5 raeburn 377: } else {
378: my $code = $env{'form.code'};
379: my $md5sum = $env{'form.crypt'};
380: my %captcha_params = &captcha_settings();
381: my $captcha = Authen::Captcha->new(
382: output_folder => $captcha_params{'output_dir'},
383: data_folder => $captcha_params{'db_dir'},
384: );
385: my $captcha_chk = $captcha->check_code($code,$md5sum);
386: my %captcha_hash = (
387: 0 => 'Code not checked (file error)',
388: -1 => 'Failed: code expired',
389: -2 => 'Failed: invalid code (not in database)',
390: -3 => 'Failed: invalid code (code does not match crypt)',
391: );
392: if ($captcha_chk != 1) {
393: $output = &invalid_state('captcha',$domdesc,$contact_name,
394: $contact_email,$captcha_hash{$captcha_chk});
395: return $output;
396: }
397: my (%rulematch,%inst_results,%curr_rules,%got_rules,%alerts);
398: my $uhome=&Apache::lonnet::homeserver($useremail,$domain);
399: if ($uhome eq 'no_host') {
400: my $checkhash;
401: my $checks = { 'username' => 1 };
402: $checkhash->{$useremail.':'.$domain} = { 'newuser' => 1, };
403: &Apache::loncommon::user_rule_check($checkhash,$checks,
404: \%alerts,\%rulematch,\%inst_results,\%curr_rules,
405: \%got_rules);
406: if (ref($alerts{'useremail'}) eq 'HASH') {
407: if (ref($alerts{'useremail'}{$domain}) eq 'HASH') {
408: if ($alerts{'username'}{$domain}{$useremail}) {
409: $output = &invalid_state('userrules',$domdesc,
410: $contact_name,$contact_email);
411: return $output;
412: }
1.1 raeburn 413: }
414: }
1.5 raeburn 415: my $format_msg =
416: &guest_format_check($useremail,$domain,$cancreate,
417: $settings);
418: if ($format_msg) {
419: $output = &invalid_state('userformat',$domdesc,$contact_name,
420: $contact_email,$format_msg);
421: return $output;
422: }
1.1 raeburn 423: }
424: }
425: }
1.5 raeburn 426: $output = &send_token($domain,$useremail,$server,$domdesc,$contact_name,
427: $contact_email,$courseid);
1.1 raeburn 428: }
429: return $output;
430: }
431:
432: sub send_token {
1.3 raeburn 433: my ($domain,$email,$server,$domdesc,$contact_name,$contact_email,$courseid) = @_;
1.1 raeburn 434: my $msg = &mt('Thank you for your request to create a new LON-CAPA account.').'<br /><br />';
435: my $now = time;
436: my %info = ('ip' => $ENV{'REMOTE_ADDR'},
437: 'time' => $now,
438: 'domain' => $domain,
1.3 raeburn 439: 'username' => $email,
440: 'courseid' => $courseid);
1.1 raeburn 441: my $token = &Apache::lonnet::tmpput(\%info,$server);
442: if ($token !~ /^error/ && $token ne 'no_such_host') {
443: my $esc_token = &escape($token);
444: my $mailmsg = &mt('A request was submitted on [_1] for creation of a LON-CAPA account in the [_2] domain.',localtime(time),$domdesc).' '.
1.7 bisitz 445: &mt('To complete this process please open a web browser and enter the following'
446: .' URL in the address/location box: [_1]'
447: ,&Apache::lonnet::absolute_url().'/adm/createaccount?token=$esc_token');
1.1 raeburn 448: my $result = &Apache::resetpw::send_mail($domdesc,$email,$mailmsg,$contact_name,
449: $contact_email);
450: if ($result eq 'ok') {
451: $msg .= &mt('A message has been sent to the e-mail address you provided.').'<br />'.&mt('The message includes the web address for the link you will use to complete the account creation process.').'<br />'.&mt("The link included in the message will be valid for the next [_1]two[_2] hours.",'<b>','</b>');
452: } else {
1.7 bisitz 453: $msg .= &mt('An error occurred when sending a message to the e-mail address you provided.')
454: .' '.&mt('Please contact the [_1] ([_2]) for assistance.',$contact_name,$contact_email);
1.1 raeburn 455: }
456: } else {
1.7 bisitz 457: $msg .= &mt('An error occurred creating a token required for the account creation process.')
458: .' '.&mt('Please contact the [_1] ([_2]) for assistance.',$contact_name,$contact_email);
1.1 raeburn 459: }
460: return $msg;
461: }
462:
463: sub process_mailtoken {
1.3 raeburn 464: my ($r,$token,$contact_name,$contact_email,$domain,$domdesc,$lonhost,
465: $include,$start_page) = @_;
466: my ($msg,$nostart,$noend);
1.1 raeburn 467: my %data = &Apache::lonnet::tmpget($token);
468: my $now = time;
469: if (keys(%data) == 0) {
1.7 bisitz 470: $msg = &mt('Sorry, the URL you provided to complete creation of a new LON-CAPA account was invalid. Either the token included in the URL has been deleted or the URL you provided was invalid.')
471: .' '.&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.','<a href="/adm/createaccount">','</a>');
1.1 raeburn 472: return $msg;
473: }
474: if (($data{'time'} =~ /^\d+$/) &&
475: ($data{'domain'} ne '') &&
476: ($data{'username'} =~ /^[^\@]+\@[^\@]+\.[^\@\.]+$/)) {
477: if ($now - $data{'time'} < 7200) {
478: if ($env{'form.phase'} eq 'createaccount') {
1.3 raeburn 479: my ($result,$output) = &create_account($r,$domain,$lonhost,
1.1 raeburn 480: $data{'username'},$domdesc);
481: if ($result eq 'ok') {
482: $msg = $output;
1.4 raeburn 483: my $shownow = localtime($now);
484: my $mailmsg = &mt('A LON-CAPA account in the [_1] domain 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";
1.1 raeburn 485: my $mailresult = &Apache::resetpw::send_mail($domdesc,$data{'email'},
486: $mailmsg,$contact_name,
487: $contact_email);
488: if ($mailresult eq 'ok') {
489: $msg .= &mt('An e-mail confirming creation of your new LON-CAPA account has been sent to [_1].',$data{'username'});
490: } else {
491: $msg .= &mt('An error occurred when sending e-mail to [_1] confirming creation of your LON-CAPA account.',$data{'username'});
492: }
1.3 raeburn 493: my %form = &start_session($r,$data{'username'},$domain,
494: $lonhost,$data{'courseid'},
495: $token);
496: $nostart = 1;
497: $noend = 1;
1.1 raeburn 498: } else {
1.7 bisitz 499: $msg .= &mt('A problem occurred when attempting to create your new LON-CAPA account.')
500: .'<br />'.$output
501: # .&mt('Please contact the [_1] ([_2]) for assistance.',$contact_name,'<a href="mailto:'.$contact_email.'">'.$contact_email.'</a>');
502: .&mt('Please contact the [_1] ([_2]) for assistance.',$contact_name,$contact_email);
1.1 raeburn 503: }
1.3 raeburn 504: my $delete = &Apache::lonnet::tmpdel($token);
1.1 raeburn 505: } else {
1.3 raeburn 506: $msg .= &mt('Please provide user information and a password for your new account.').'<br />'.&mt('Your password, which must contain at least seven characters, will be sent to the LON-CAPA server in an encrypted form.').'<br />';
507: $msg .= &print_dataentry_form($r,$domain,$lonhost,$include,$token,$now,$data{'username'},$start_page);
508: $nostart = 1;
1.1 raeburn 509: }
510: } else {
1.7 bisitz 511: $msg = &mt('Sorry, the token generated when you requested creation of an account has expired.')
512: .' '.&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 513: }
1.1 raeburn 514: } else {
1.7 bisitz 515: $msg .= &mt('Sorry, the URL generated when you requested creation of an account contained incomplete information.')
516: .' '.&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 517: }
1.3 raeburn 518: return ($msg,$nostart,$noend);
519: }
520:
521: sub start_session {
522: my ($r,$username,$domain,$lonhost,$courseid,$token) = @_;
523: my %form = (
524: uname => $username,
525: udom => $domain,
526: );
527: my $firsturl = '/adm/roles';
528: if (defined($courseid)) {
529: $courseid = &validate_course($courseid);
530: if ($courseid ne '') {
531: $form{'courseid'} = $courseid;
532: $firsturl = '/adm/selfenroll?cid='.$courseid;
533: }
534: }
535: if ($r->dir_config('lonBalancer') eq 'yes') {
536: &Apache::lonauth::success($r,$form{'uname'},$form{'udom'},
537: $lonhost,'noredirect',undef,\%form);
538: my $delete = &Apache::lonnet::tmpdel($token);
539: $r->internal_redirect('/adm/switchserver');
540: } else {
541: &Apache::lonauth::success($r,$form{'uname'},$form{'udom'},
542: $lonhost,$firsturl,undef,\%form);
543: }
544: return %form;
1.1 raeburn 545: }
546:
1.3 raeburn 547:
1.1 raeburn 548: sub print_dataentry_form {
1.3 raeburn 549: my ($r,$domain,$lonhost,$include,$mailtoken,$now,$username,$start_page) = @_;
1.1 raeburn 550: my ($error,$output);
1.3 raeburn 551: &print_header($r,$start_page);
1.1 raeburn 552: if (open(my $jsh,"<$include/londes.js")) {
553: while(my $line = <$jsh>) {
554: $r->print($line);
555: }
556: close($jsh);
1.3 raeburn 557: $output .= &javascript_setforms($now)."\n".&javascript_checkpass($now);
1.1 raeburn 558: my ($lkey,$ukey) = &Apache::lonpreferences::des_keys();
559: my ($lextkey,$uextkey) = &getkeys($lkey,$ukey);
560: my $logtoken=Apache::lonnet::reply('tmpput:'.$ukey.$lkey.'&createaccount',
561: $lonhost);
562: my @userinfo = ('firstname','middlename','lastname','generation','id',
563: 'permanentemail');
564: my %lt=&Apache::lonlocal::texthash(
565: 'pd' => "Personal Data",
566: 'firstname' => "First Name",
567: 'middlename' => "Middle Name",
568: 'lastname' => "Last Name",
569: 'generation' => "Generation",
570: 'permanentemail' => "Permanent e-mail address",
571: 'id' => "ID/Student Number",
572: 'lg' => "Login Data"
573: );
574: my %textboxsize = (
575: firstname => '15',
576: middlename => '15',
577: lastname => '15',
578: generation => '5',
579: id => '15',
580: );
581: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
1.3 raeburn 582: $output .= '<div class="LC_left_float"><h3>'.$lt{'pd'}.'</h3>'.
583: '<form name="server" method="post" target="_top" action="/adm/createaccount">'.
1.1 raeburn 584: &Apache::lonhtmlcommon::start_pick_box();
585: foreach my $item (@userinfo) {
586: my $rowtitle = $lt{$item};
587: if ($item eq 'generation') {
588: $rowtitle = $genhelp.$rowtitle;
589: }
590: $output .= &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
591: if ($item eq 'permanentemail') {
592: $output .= $username;
593: } else {
594: $output .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
595: }
596: $output .= &Apache::lonhtmlcommon::row_closure(1);
597: }
598: $output .= &Apache::lonhtmlcommon::end_pick_box();
599: $output .= <<"ENDSERVERFORM";
600: <input type="hidden" name="logtoken" value="$logtoken" />
601: <input type="hidden" name="token" value="$mailtoken" />
602: <input type="hidden" name="serverid" value="$lonhost" />
603: <input type="hidden" name="uname" value="" />
604: <input type="hidden" name="upass" value="" />
605: <input type="hidden" name="phase" value="createaccount" />
606: </form></div>
607: ENDSERVERFORM
608: my $upassone = '<input type="password" name="upass'.$now.'" size="10" />';
609: my $upasstwo = '<input type="password" name="upasscheck'.$now.'" size="10" />';
610: my $submit_text = &mt('Create LON-CAPA account');
611: $output .= '<div class="LC_left_float"><h3>'.$lt{'lg'}.'</h3>'."\n".
612: '<form name="client" method="post" />'."\n".
613: &Apache::lonhtmlcommon::start_pick_box()."\n".
614: &Apache::lonhtmlcommon::row_title(&mt('Username'),
615: 'LC_pick_box_title')."\n".
616: $username."\n".
617: &Apache::lonhtmlcommon::row_closure(1)."\n".
618: &Apache::lonhtmlcommon::row_title(&mt('Password'),
619: 'LC_pick_box_title')."\n".
620: $upassone."\n".
621: &Apache::lonhtmlcommon::row_closure(1)."\n".
622: &Apache::lonhtmlcommon::row_title(&mt('Confirm password'),
623: 'LC_pick_box_title')."\n".
624: $upasstwo."\n".
625: &Apache::lonhtmlcommon::row_closure(1)."\n".
626: &Apache::lonhtmlcommon::end_pick_box()."\n".
627: '<input type="hidden" name="uname" value="'.$username.'">'."\n".
628: '<input type="hidden" name="lextkey" value="'.$lextkey.'">'."\n".
629: '<input type="hidden" name="uextkey" value="'.$uextkey.'">'."\n".
630: '</form></div>'."\n".
631: '<div class="LC_clear_float_footer"><br /><br />'."\n".
632: '<form name="buttonform">'."\n".
633: '<input type="button" name="createaccount" value="'.
634: $submit_text.'" onclick="javascript:checkpass();" /></form></div>';
635: } else {
1.7 bisitz 636: $output = &mt('Could not load javascript file [_1]','<tt>londes.js</tt>');
1.1 raeburn 637: }
1.3 raeburn 638: return $output;
1.1 raeburn 639: }
640:
641: sub create_account {
1.3 raeburn 642: my ($r,$domain,$lonhost,$username,$domdesc) = @_;
1.1 raeburn 643: my ($retrieved,$output,$upass) = &process_credentials($env{'form.logtoken'},
644: $env{'form.serverid'});
645: # Error messages
1.7 bisitz 646: my $error = '<span class="LC_error">'.&mt('Error:').' ';
1.1 raeburn 647: my $end = '</span><br /><br />';
648: my $rtnlink = '<a href="javascript:history.back();" />'.
649: &mt('Return to previous page').'</a>'.
650: &Apache::loncommon::end_page();
651: if ($retrieved eq 'ok') {
652: if ($env{'form.cid'} ne '') {
653: my ($result,$userchkmsg) = &check_id($username,$domain,$domdesc);
654: if ($result eq 'fail') {
655: $output = $error.&mt('Invalid ID format').$end.
656: $userchkmsg.$rtnlink;
657: return ('fail',$output);
658: }
659: }
660: } else {
661: return ('fail',$error.$output.$end.$rtnlink);
662: }
663: # Call modifyuser
664: my $result =
665: &Apache::lonnet::modifyuser($domain,$username,$env{'form.cid'},
666: 'internal',$upass,$env{'form.cfirstname'},
667: $env{'form.cmiddlename'},$env{'form.clastname'},
668: $env{'form.cgeneration'},undef,undef,$username);
1.7 bisitz 669: $output = &mt('Generating user: [_1]',$result);
1.1 raeburn 670: my $uhome = &Apache::lonnet::homeserver($username,$domain);
1.7 bisitz 671: $output .= '<br />'.&mt('Home server: [_1]',$uhome).' '.
1.1 raeburn 672: &Apache::lonnet::hostname($uhome).'<br /><br />';
673: return ('ok',$output);
674: }
675:
676: sub username_validation {
1.8 ! raeburn 677: my ($username,$domain,$domdesc,$contact_name,$contact_email,$courseid,$lonhost) = @_;
1.1 raeburn 678: my ($retrieved,$output,$upass);
679:
680: $username= &LONCAPA::clean_username($username);
681: $domain = &LONCAPA::clean_domain($domain);
682: my $uhome = &Apache::lonnet::homeserver($username,$domain);
683:
684: if ($uhome ne 'no_host') {
685: $output = &invalid_state('existinguser',$domdesc,
686: $contact_name,$contact_email);
687: return $output;
688: }
689: ($retrieved,$output,$upass) = &process_credentials($env{'form.logtoken'},
690: $env{'form.serverid'});
691: if ($retrieved eq 'ok') {
692: my $primlibserv = &Apache::lonnet::domain($domain,'primary');
693: my $authok;
694: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
695: if ((($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth')) {
696: my $checkdefauth = 1;
697: $authok =
698: &Apache::lonnet::reply("encrypt:auth:$domain:$username:$upass:$checkdefauth",$primlibserv);
699: } else {
700: $authok = 'non_authorized';
701: }
702: if ($authok eq 'authorized') {
1.8 ! raeburn 703: ($output,undef) = &username_check($username,$domain,$domdesc,
! 704: $courseid,$lonhost,$contact_email);
1.4 raeburn 705: } else {
1.6 bisitz 706: $output = '<div class="LC_warning">'
707: .&mt('Username and/or password could not be authenticated.')
708: .'</div>'
709: .&mt('Please check the username and password.');
1.4 raeburn 710: }
711: }
712: return $output;
713: }
714:
715: sub username_check {
1.8 ! raeburn 716: my ($username,$domain,$domdesc,$courseid,$lonhost,$contact_email) = @_;
1.4 raeburn 717: my (%rulematch,%inst_results,$newuser,%alerts,%curr_rules,%got_rules);
718: $newuser = 1;
719: my $checkhash;
720: my $checks = { 'username' => 1 };
721: $checkhash->{$username.':'.$domain} = { 'newuser' => $newuser };
722: &Apache::loncommon::user_rule_check($checkhash,$checks,\%alerts,\%rulematch,
723: \%inst_results,\%curr_rules,\%got_rules);
724: if (ref($alerts{'username'}) eq 'HASH') {
725: if (ref($alerts{'username'}{$domain}) eq 'HASH') {
726: if ($alerts{'username'}{$domain}{$username}) {
1.5 raeburn 727: my ($userchkmsg,$checkfail);
1.4 raeburn 728: if (ref($curr_rules{$domain}) eq 'HASH') {
729: $userchkmsg =
730: &Apache::loncommon::instrule_disallow_msg('username',$domdesc,1).
731: &Apache::loncommon::user_rule_formats($domain,$domdesc,
732: $curr_rules{$domain}{'username'},'username');
1.5 raeburn 733: if ($userchkmsg) {
1.8 ! raeburn 734: $checkfail = 'username';
1.5 raeburn 735: }
1.1 raeburn 736: }
1.5 raeburn 737: return ($userchkmsg,$checkfail);
1.1 raeburn 738: }
1.4 raeburn 739: }
740: }
741: my $submit_text = &mt('Create LON-CAPA account');
742: my $output = '<form method="post" action="/adm/createaccount">'.
743: &Apache::loncreateuser::personal_data_display($username,$domain,1,
744: undef,$inst_results{$username.':'.$domain}).
745: '<br /><br /><input type="hidden" name="uname" value="'.$username.'" />'."\n".
746: '<input type="hidden" name="udom" value="'.$domain.'" />'."\n".
1.3 raeburn 747: '<input type="hidden" name="phase" value="username_activation" />';
1.8 ! raeburn 748: my $now = time;
! 749: my %info = ('ip' => $ENV{'REMOTE_ADDR'},
! 750: 'time' => $now,
! 751: 'domain' => $domain,
! 752: 'username' => $username);
! 753: my $authtoken = &Apache::lonnet::tmpput(\%info,$lonhost);
! 754: if ($authtoken !~ /^error/ && $authtoken ne 'no_such_host') {
! 755: $output .= '<input type="hidden" name="authtoken" value="'.&HTML::Entities::encode($authtoken,'&<>"').'" />';
! 756: } else {
! 757: $output = &mt('An error occurred when storing a token').'<br />'.
! 758: &mt('You will not be able to proceed to the next stage of account creation').
! 759: &linkto_email_help($contact_email,$domdesc);
! 760: return($output,'authtoken');
! 761: }
1.4 raeburn 762: if ($courseid ne '') {
763: $output .= '<input type="hidden" name="courseid" value="'.$courseid.'" />';
1.1 raeburn 764: }
1.4 raeburn 765: $output .= '<input type="submit" name="newaccount" value="'.
766: $submit_text.'" /></form>';
1.5 raeburn 767: return ($output,'');
1.1 raeburn 768: }
769:
770: sub username_activation {
1.3 raeburn 771: my ($r,$username,$domain,$domdesc,$lonhost,$courseid) = @_;
1.1 raeburn 772: my $output;
1.7 bisitz 773: my $error = '<span class="LC_error">'.&mt('Error:').' ';
1.1 raeburn 774: my $end = '</span><br /><br />';
775: my $rtnlink = '<a href="javascript:history.back();" />'.
776: &mt('Return to previous page').'</a>'.
777: &Apache::loncommon::end_page();
778: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
1.8 ! raeburn 779: my %data = &Apache::lonnet::tmpget($env{'form.authtoken'});
! 780: my $now = time;
! 781: my $earlyout;
! 782: my $timeout = 300;
! 783: if (keys(%data) == 0) {
! 784: $output = &mt('Sorry, your authentication has expired.');
! 785: $earlyout = 'fail';
! 786: }
! 787: if (($data{'time'} !~ /^\d+$/) ||
! 788: ($data{'domain'} ne $domain) ||
! 789: ($data{'username'} ne $username)) {
! 790: $earlyout = 'fail';
! 791: $output = &mt('The credentials you provided could not be verified.');
! 792: } elsif ($now - $data{'time'} > $timeout) {
! 793: $earlyout = 'fail';
! 794: $output = &mt('Sorry, your authentication has expired.');
! 795: }
! 796: if ($earlyout ne '') {
! 797: $output .= '<br />'.&mt('Please [_1]start again[_2].','<a href="/adm/createaccount">','</a>');
! 798: return($earlyout,$output);
! 799: }
1.3 raeburn 800: if ((($domdefaults{'auth_def'} =~/^krb(4|5)$/) &&
801: ($domdefaults{'auth_arg_def'} ne '')) ||
802: ($domdefaults{'auth_def'} eq 'localauth')) {
1.1 raeburn 803: if ($env{'form.cid'} ne '') {
804: my ($result,$userchkmsg) = &check_id($username,$domain,$domdesc);
805: if ($result eq 'fail') {
806: $output = $error.&mt('Invalid ID format').$end.
807: $userchkmsg.$rtnlink;
808: return ('fail',$output);
809: }
810: }
811: # Call modifyuser
812: my $result =
813: &Apache::lonnet::modifyuser($domain,$username,$env{'form.cid'},
814: $domdefaults{'auth_def'},
815: $domdefaults{'auth_arg_def'},$env{'form.cfirstname'},
816: $env{'form.cmiddlename'},$env{'form.clastname'},
817: $env{'form.cgeneration'},undef,undef,
818: $env{'form.cpermanentemail'});
1.3 raeburn 819: if ($result eq 'ok') {
1.8 ! raeburn 820: my $delete = &Apache::lonnet::tmpdel($env{'form.authtoken'});
1.3 raeburn 821: $output = &mt('A LON-CAPA account has been created for username: [_1] in domain: [_2].',$username,$domain);
822: my %form = &start_session($r,$username,$domain,$lonhost,$courseid);
823: my $nostart = 1;
824: return ('ok',$output,$nostart);
825: } else {
826: $output = &mt('Account creation failed for username: [_1] in domain: [_2].',$username,$domain).'<br /><span class="LC_error">'.&mt('Error: [_1]',$result).'</span>';
827: return ('fail',$output);
828: }
1.1 raeburn 829: } else {
1.7 bisitz 830: $output = &mt('User account creation is not available for the current default authentication type.')."\n";
1.1 raeburn 831: return('fail',$output);
832: }
833: }
834:
835: sub check_id {
836: my ($username,$domain,$domdesc) = @_;
837: # Check ID format
838: my (%alerts,%rulematch,%inst_results,%curr_rules,%checkhash);
839: my %checks = ('id' => 1);
840: %{$checkhash{$username.':'.$domain}} = (
841: 'newuser' => 1,
842: 'id' => $env{'form.cid'},
843: );
844: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
845: \%rulematch,\%inst_results,\%curr_rules);
846: if (ref($alerts{'id'}) eq 'HASH') {
847: if (ref($alerts{'id'}{$domain}) eq 'HASH') {
848: if ($alerts{'id'}{$domain}{$env{'form.cid'}}) {
849: my $userchkmsg;
850: if (ref($curr_rules{$domain}) eq 'HASH') {
851: $userchkmsg =
852: &Apache::loncommon::instrule_disallow_msg('id',
853: $domdesc,1).
854: &Apache::loncommon::user_rule_formats($domain,
855: $domdesc,$curr_rules{$domain}{'id'},'id');
856: }
857: return ('fail',$userchkmsg);
858: }
859: }
860: }
861: return;
862: }
863:
864: sub invalid_state {
865: my ($error,$domdesc,$contact_name,$contact_email,$msgtext) = @_;
866: my $msg;
867: if ($error eq 'baduseremail') {
868: $msg = &mt('The e-mail address you provided does not appear to be a valid address.');
869: } elsif ($error eq 'existinguser') {
870: $msg = &mt('The e-mail address you provided is already in use as a username in this LON-CAPA domain.');
871: } elsif ($error eq 'userrules') {
872: $msg = &mt('Username rules for this LON-CAPA domain do not allow the e-mail address you provided to be used as a username.');
873: } elsif ($error eq 'userformat') {
874: $msg = &mt('The e-mail address you provided may not be used as a username in this LON-CAPA domain.');
875: } elsif ($error eq 'captcha') {
876: $msg = &mt('Validation of the code your entered failed.');
877: } elsif ($error eq 'noemails') {
878: $msg = &mt('Creation of a new user account using an e-mail address as username is not permitted in this LON-CAPA domain.');
879: }
880: if ($msgtext) {
881: $msg .= '<br />'.$msgtext;
882: }
1.8 ! raeburn 883: $msg .= &linkto_email_help($contact_email,$domdesc);
! 884: return $msg;
! 885: }
! 886:
! 887: sub linkto_email_help {
! 888: my ($contact_email,$domdesc) = @_;
! 889: my $msg;
1.1 raeburn 890: if ($contact_email ne '') {
891: my $escuri = &HTML::Entities::encode('/adm/createaccount','&<>"');
1.7 bisitz 892: $msg .= '<br />'.&mt('You may wish to contact the [_1]LON-CAPA helpdesk[_2] for the [_3] domain.','<a href="/adm/helpdesk?origurl='.$escuri.'">','</a>',$domdesc);
1.1 raeburn 893: } else {
1.7 bisitz 894: $msg .= '<br />'.&mt('You may wish to send an e-mail to the server administrator: [_1] for the [_2] domain.',$Apache::lonnet::perlvar{'AdminEmail'},$domdesc);
1.1 raeburn 895: }
896: return $msg;
897: }
898:
899: sub create_captcha {
900: my ($output_dir,$db_dir) = @_;
901: my %captcha_params = &captcha_settings();
902: my $captcha = Authen::Captcha->new(
903: output_folder => $captcha_params{'output_dir'},
904: data_folder => $captcha_params{'db_dir'},
905: );
906: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
907: my $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
908: &mt('Type in the letters/numbers shown below').' '.
909: '<input type="text" size="5" name="code" value="" /><br />'.
910: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png">';
911: return $output;
912: }
913:
914: sub captcha_settings {
915: my %captcha_params = (
916: output_dir => "/home/httpd/html/captcha",
917: www_output_dir => "/captcha",
918: db_dir => "/home/www/captchadb",
919: numchars => '5',
920: );
921: return %captcha_params;
922: }
923:
924: sub getkeys {
925: my ($lkey,$ukey) = @_;
926: my $lextkey=hex($lkey);
927: if ($lextkey>2147483647) { $lextkey-=4294967296; }
928:
929: my $uextkey=hex($ukey);
930: if ($uextkey>2147483647) { $uextkey-=4294967296; }
931: return ($lextkey,$uextkey);
932: }
933:
934: sub serverform {
1.3 raeburn 935: my ($logtoken,$lonhost,$mailtoken,$courseid) = @_;
1.1 raeburn 936: my $output .= <<ENDSERVERFORM;
937: <form name="server" method="post" target="_top">
938: <input type="hidden" name="logtoken" value="$logtoken" />
939: <input type="hidden" name="token" value="$mailtoken" />
940: <input type="hidden" name="serverid" value="$lonhost" />
941: <input type="hidden" name="uname" value="" />
942: <input type="hidden" name="upass" value="" />
943: <input type="hidden" name="phase" value="username_validation" />
1.3 raeburn 944: <input type="hidden" name="courseid" value="$courseid" />
1.1 raeburn 945: </form>
946: ENDSERVERFORM
947: return $output;
948: }
949:
950: sub process_credentials {
951: my ($logtoken,$lonhost) = @_;
952: my $tmpinfo=Apache::lonnet::reply('tmpget:'.$logtoken,$lonhost);
953: my ($retrieved,$output,$upass);
954: if (($tmpinfo=~/^error/) || ($tmpinfo eq 'con_lost')) {
1.7 bisitz 955: $output = &mt('Information needed to verify your login information is missing, inaccessible or expired.')
956: .'<br />'.&mt('You may need to reload the previous page to obtain a new token.');
1.1 raeburn 957: return ($retrieved,$output,$upass);
958: } else {
959: my $reply = &Apache::lonnet::reply('tmpdel:'.$logtoken,$lonhost);
960: if ($reply eq 'ok') {
961: $retrieved = 'ok';
962: } else {
963: $output = &mt('Session could not be opened.');
964: }
965: }
966: my ($key,$caller)=split(/&/,$tmpinfo);
967: if ($caller eq 'createaccount') {
968: $upass = &Apache::lonpreferences::des_decrypt($key,$env{'form.upass'});
969: } else {
970: $output = &mt('Unable to retrieve your log-in information - unexpected context');
971: }
972: return ($retrieved,$output,$upass);
973: }
974:
975: sub guest_format_check {
976: my ($useremail,$domain,$cancreate,$settings) = @_;
977: my ($login,$format_match,$format_msg,@user_rules);
978: if (ref($settings) eq 'HASH') {
979: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
980: push(@user_rules,@{$settings->{'email_rule'}});
981: }
982: }
983: if (@user_rules > 0) {
984: my %rule_check =
985: &Apache::lonnet::inst_rulecheck($domain,$useremail,undef,
1.2 raeburn 986: 'selfcreate',\@user_rules);
1.1 raeburn 987: if (keys(%rule_check) > 0) {
988: foreach my $item (keys(%rule_check)) {
989: if ($rule_check{$item}) {
990: $format_match = 1;
991: last;
992: }
993: }
994: }
995: }
996: if ($format_match) {
997: ($login) = ($useremail =~ /^([^\@]+)\@/);
998: $format_msg = '<br />'.&mt("Your e-mail address uses the same internet domain as your institution's LON-CAPA service.").'<br />'.&mt('Creation of a LON-CAPA account with this type of e-mail address as username is not permitted.').'<br />';
1.5 raeburn 999: if (ref($cancreate) eq 'ARRAY') {
1000: if (grep(/^login$/,@{$cancreate})) {
1.7 bisitz 1001: $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 1002: }
1.1 raeburn 1003: }
1004: }
1005: return $format_msg;
1006: }
1007:
1008: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>