Diff for /loncom/interface/createaccount.pm between versions 1.3 and 1.4

version 1.3, 2008/03/08 04:17:11 version 1.4, 2008/03/24 05:15:14
Line 57  sub handler { Line 57  sub handler {
     my $contact_email =  $r->dir_config('lonSupportEMail');      my $contact_email =  $r->dir_config('lonSupportEMail');
     my $lonhost = $r->dir_config('lonHostID');      my $lonhost = $r->dir_config('lonHostID');
     my $include = $r->dir_config('lonIncludes');      my $include = $r->dir_config('lonIncludes');
       my $start_page;
   
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['token','courseid']);      &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['token','courseid']);
     &Apache::lonacc::get_posted_cgi($r);      &Apache::lonacc::get_posted_cgi($r);
Line 64  sub handler { Line 65  sub handler {
   
     my $handle = &Apache::lonnet::check_for_valid_session($r);      my $handle = &Apache::lonnet::check_for_valid_session($r);
     if ($handle ne '') {      if ($handle ne '') {
         my $start_page =          $start_page =
             &Apache::loncommon::start_page('Already logged in');              &Apache::loncommon::start_page('Already logged in');
         my $end_page =          my $end_page =
             &Apache::loncommon::end_page();              &Apache::loncommon::end_page();
Line 73  sub handler { Line 74  sub handler {
                   '</p><p><a href="/adm/loginproblems.html">'.&mt('Problems?').'</a></p>'.$end_page);                    '</p><p><a href="/adm/loginproblems.html">'.&mt('Problems?').'</a></p>'.$end_page);
        return OK;         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 $cancreate;
     my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$domain);      my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$domain);
     if (ref($domconfig{'usercreation'}) eq 'HASH') {      if (ref($domconfig{'usercreation'}) eq 'HASH') {
Line 84  sub handler { Line 92  sub handler {
         }          }
     }      }
   
     my $start_page =  
         &Apache::loncommon::start_page('Create a user account in LON-CAPA','',  
                                            {  
                                              'no_inline_link'   => 1,});  
     if (!$cancreate) {      if (!$cancreate) {
         &print_header($r,$start_page);          &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);          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);
Line 96  sub handler { Line 100  sub handler {
         return OK;          return OK;
     }      }
   
     my $token = $env{'form.token'};  
     my ($output,$nostart,$noend);      my ($output,$nostart,$noend);
       my $token = $env{'form.token'};
     if ($token) {      if ($token) {
         ($output,$nostart,$noend) =           ($output,$nostart,$noend) = 
             &process_mailtoken($r,$token,$contact_name,$contact_email,$domain,              &process_mailtoken($r,$token,$contact_name,$contact_email,$domain,
                                $domain,$domdesc,$lonhost,$include,$start_page);                                 $domdesc,$lonhost,$include,$start_page);
         if ($nostart) {          if ($nostart) {
             if ($noend) {              if ($noend) {
                 return OK;                  return OK;
Line 425  sub process_mailtoken { Line 429  sub process_mailtoken {
     if (($data{'time'} =~ /^\d+$/) &&      if (($data{'time'} =~ /^\d+$/) &&
         ($data{'domain'} ne '') &&          ($data{'domain'} ne '') &&
         ($data{'username'}  =~ /^[^\@]+\@[^\@]+\.[^\@\.]+$/)) {          ($data{'username'}  =~ /^[^\@]+\@[^\@]+\.[^\@\.]+$/)) {
         my $reqtime = localtime($data{'time'});  
         if ($now - $data{'time'} < 7200) {          if ($now - $data{'time'} < 7200) {
             if ($env{'form.phase'} eq 'createaccount') {              if ($env{'form.phase'} eq 'createaccount') {
                 my ($result,$output) = &create_account($r,$domain,$lonhost,                  my ($result,$output) = &create_account($r,$domain,$lonhost,
                                                        $data{'username'},$domdesc);                                                         $data{'username'},$domdesc);
                 if ($result eq 'ok') {                  if ($result eq 'ok') {
                     $msg = $output;                       $msg = $output; 
                     my $now = localtime(time);                      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,$now,$ENV{'REMOTE_ADDR'},$contact_name,$contact_email)."\n";                      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'},                      my $mailresult = &Apache::resetpw::send_mail($domdesc,$data{'email'},
                                                                  $mailmsg,$contact_name,                                                                   $mailmsg,$contact_name,
                                                                  $contact_email);                                                                   $contact_email);
Line 458  sub process_mailtoken { Line 461  sub process_mailtoken {
             }              }
         } else {          } else {
             $msg = &mt('Sorry, the token generated when you requested creation of an account has expired. Please submit a <a href="/adm/createaccount">new request</a>, 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.');              $msg = &mt('Sorry, the token generated when you requested creation of an account has expired. Please submit a <a href="/adm/createaccount">new request</a>, 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 {      } else {
         $msg .= &mt('Sorry, the URL generated when you requested creation of an accountcontained incomplete information. Please submit a <a href="/adm/createaccount">new request</a> 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 <a href="/adm/createaccount">new request</a> 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);      return ($msg,$nostart,$noend);
 }  }
Line 647  sub username_validation { Line 650  sub username_validation {
             $authok = 'non_authorized';              $authok = 'non_authorized';
         }          }
         if ($authok eq 'authorized') {          if ($authok eq 'authorized') {
             my (%rulematch,%inst_results,$newuser,%alerts,%curr_rules,%got_rules);              $output = &username_check($username,$domain,$domdesc,$courseid);            
             $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 =  
                 '<form method="post" action="/adm/createaccount">'.  
                 &Apache::loncreateuser::personal_data_display($username,$domain,1,  
                                        undef,$inst_results{$username.':'.$domain}).  
                 '<br /><br /><input type="hidden" name="uname" value="'.$username.'" />'.  
                 '<input type="hidden" name="phase" value="username_activation" />';  
             if ($courseid ne '') {  
                 $output .= '<input type="hidden" name="courseid" value="'.$courseid.'" />';   
             }  
             $output .= '<input type="submit" name="newaccount" value="'.   
                        $submit_text.'" /></form>';  
         } else {          } else {
             $output = &mt('Not authenticated').' '.&mt('Please check the username and password');               $output = &mt('Not authenticated').' '.&mt('Please check the username and password'); 
         }          }
Line 690  sub username_validation { Line 658  sub username_validation {
     return $output;      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 = '<form method="post" action="/adm/createaccount">'.
                    &Apache::loncreateuser::personal_data_display($username,$domain,1,
                                       undef,$inst_results{$username.':'.$domain}).
                   '<br /><br /><input type="hidden" name="uname" value="'.$username.'" />'."\n".
                   '<input type="hidden" name="udom" value="'.$domain.'" />'."\n".
                   '<input type="hidden" name="phase" value="username_activation" />';
       if ($courseid ne '') {
           $output .= '<input type="hidden" name="courseid" value="'.$courseid.'" />';
       }
       $output .= '<input type="submit" name="newaccount" value="'.
                  $submit_text.'" /></form>';
       return $output;
   }
   
 sub username_activation {  sub username_activation {
     my ($r,$username,$domain,$domdesc,$lonhost,$courseid) = @_;      my ($r,$username,$domain,$domdesc,$lonhost,$courseid) = @_;
     my $output;      my $output;

Removed from v.1.3  
changed lines
  Added in v.1.4


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>