--- loncom/interface/createaccount.pm 2008/03/08 04:17:11 1.3 +++ loncom/interface/createaccount.pm 2008/03/24 05:15:14 1.4 @@ -3,7 +3,7 @@ # institutional log-in ID (institutional authentication required - localauth # or kerberos) or an e-mail address. # -# $Id: createaccount.pm,v 1.3 2008/03/08 04:17:11 raeburn Exp $ +# $Id: createaccount.pm,v 1.4 2008/03/24 05:15:14 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -57,6 +57,7 @@ sub handler { my $contact_email = $r->dir_config('lonSupportEMail'); my $lonhost = $r->dir_config('lonHostID'); my $include = $r->dir_config('lonIncludes'); + my $start_page; &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['token','courseid']); &Apache::lonacc::get_posted_cgi($r); @@ -64,7 +65,7 @@ sub handler { my $handle = &Apache::lonnet::check_for_valid_session($r); if ($handle ne '') { - my $start_page = + $start_page = &Apache::loncommon::start_page('Already logged in'); my $end_page = &Apache::loncommon::end_page(); @@ -73,7 +74,14 @@ sub handler { '

'.&mt('Problems?').'

'.$end_page); return OK; } - + $start_page = + &Apache::loncommon::start_page('Create a user account in LON-CAPA','', + {'no_inline_link' => 1,}); + if ($env{'form.phase'} eq 'username_activation') { + if ($env{'form.udom'} ne '') { + $domain = $env{'form.udom'}; + } + } my $cancreate; my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$domain); if (ref($domconfig{'usercreation'}) eq 'HASH') { @@ -84,10 +92,6 @@ sub handler { } } - my $start_page = - &Apache::loncommon::start_page('Create a user account in LON-CAPA','', - { - 'no_inline_link' => 1,}); if (!$cancreate) { &print_header($r,$start_page); my $output = &mt('Creation of a new user account using an e-mail address as username or a loginID from your institution is not permitted in the domain: [_1] ([_2]).',$domain,$domdesc); @@ -96,12 +100,12 @@ sub handler { return OK; } - my $token = $env{'form.token'}; my ($output,$nostart,$noend); + my $token = $env{'form.token'}; if ($token) { ($output,$nostart,$noend) = &process_mailtoken($r,$token,$contact_name,$contact_email,$domain, - $domain,$domdesc,$lonhost,$include,$start_page); + $domdesc,$lonhost,$include,$start_page); if ($nostart) { if ($noend) { return OK; @@ -425,15 +429,14 @@ sub process_mailtoken { if (($data{'time'} =~ /^\d+$/) && ($data{'domain'} ne '') && ($data{'username'} =~ /^[^\@]+\@[^\@]+\.[^\@\.]+$/)) { - my $reqtime = localtime($data{'time'}); if ($now - $data{'time'} < 7200) { if ($env{'form.phase'} eq 'createaccount') { my ($result,$output) = &create_account($r,$domain,$lonhost, $data{'username'},$domdesc); if ($result eq 'ok') { $msg = $output; - my $now = localtime(time); - 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,$now,$ENV{'REMOTE_ADDR'},$contact_name,$contact_email)."\n"; + my $shownow = localtime($now); + 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"; my $mailresult = &Apache::resetpw::send_mail($domdesc,$data{'email'}, $mailmsg,$contact_name, $contact_email); @@ -458,9 +461,9 @@ sub process_mailtoken { } } else { $msg = &mt('Sorry, the token generated when you requested creation of an account has expired. Please submit a new request, and follow the link to the web page included in the new e-mail that will be sent to you, to allow you to create the account.'); - } + } } else { - $msg .= &mt('Sorry, the URL generated when you requested creation of an accountcontained incomplete information. Please submit a new request for creation of an account, and use the new URL that will be sent to your e-mail address to complete the process.'); + $msg .= &mt('Sorry, the URL generated when you requested creation of an account contained incomplete information. Please submit a new request for creation of an account, and use the new URL that will be sent to your e-mail address to complete the process.'); } return ($msg,$nostart,$noend); } @@ -647,42 +650,7 @@ sub username_validation { $authok = 'non_authorized'; } if ($authok eq 'authorized') { - my (%rulematch,%inst_results,$newuser,%alerts,%curr_rules,%got_rules); - $newuser = 1; - my $checkhash; - my $checks = { 'username' => 1 }; - $checkhash->{$username.':'.$domain} = { 'newuser' => $newuser }; - &Apache::loncommon::user_rule_check($checkhash,$checks, - \%alerts,\%rulematch,\%inst_results,\%curr_rules,\%got_rules); - if (ref($alerts{'username'}) eq 'HASH') { - if (ref($alerts{'username'}{$domain}) eq 'HASH') { - if ($alerts{'username'}{$domain}{$username}) { - my $userchkmsg; - if (ref($curr_rules{$domain}) eq 'HASH') { - $userchkmsg = - &Apache::loncommon::instrule_disallow_msg('username', - $domdesc,1). - &Apache::loncommon::user_rule_formats($domain, - $domdesc,$curr_rules{$domain}{'username'}, - 'username'); - } - return $userchkmsg; - } - } - } - my $submit_text = &mt('Create LON-CAPA account'); - # FIXME need a cookie to confirm credentials were validated. - $output = - '
'. - &Apache::loncreateuser::personal_data_display($username,$domain,1, - undef,$inst_results{$username.':'.$domain}). - '

'. - ''; - if ($courseid ne '') { - $output .= ''; - } - $output .= '
'; + $output = &username_check($username,$domain,$domdesc,$courseid); } else { $output = &mt('Not authenticated').' '.&mt('Please check the username and password'); } @@ -690,6 +658,45 @@ sub username_validation { return $output; } +sub username_check { + my ($username,$domain,$domdesc,$courseid) = @_; + my (%rulematch,%inst_results,$newuser,%alerts,%curr_rules,%got_rules); + $newuser = 1; + my $checkhash; + my $checks = { 'username' => 1 }; + $checkhash->{$username.':'.$domain} = { 'newuser' => $newuser }; + &Apache::loncommon::user_rule_check($checkhash,$checks,\%alerts,\%rulematch, + \%inst_results,\%curr_rules,\%got_rules); + if (ref($alerts{'username'}) eq 'HASH') { + if (ref($alerts{'username'}{$domain}) eq 'HASH') { + if ($alerts{'username'}{$domain}{$username}) { + my $userchkmsg; + if (ref($curr_rules{$domain}) eq 'HASH') { + $userchkmsg = + &Apache::loncommon::instrule_disallow_msg('username',$domdesc,1). + &Apache::loncommon::user_rule_formats($domain,$domdesc, + $curr_rules{$domain}{'username'},'username'); + } + return $userchkmsg; + } + } + } + my $submit_text = &mt('Create LON-CAPA account'); + # FIXME need a cookie to confirm credentials were validated. + my $output = '
'. + &Apache::loncreateuser::personal_data_display($username,$domain,1, + undef,$inst_results{$username.':'.$domain}). + '

'."\n". + ''."\n". + ''; + if ($courseid ne '') { + $output .= ''; + } + $output .= '
'; + return $output; +} + sub username_activation { my ($r,$username,$domain,$domdesc,$lonhost,$courseid) = @_; my $output;