Diff for /loncom/interface/createaccount.pm between versions 1.49 and 1.51

version 1.49, 2012/05/17 17:41:48 version 1.51, 2012/05/18 04:31:05
Line 121  sub handler { Line 121  sub handler {
             &print_footer($r);              &print_footer($r);
             return OK;              return OK;
         } else {          } else {
             $start_page =               $start_page = &Apache::loncommon::start_page($title,$js); 
                 &Apache::loncommon::start_page($title,$js);  
             &print_header($r,$start_page,$courseid);              &print_header($r,$start_page,$courseid);
             $r->print($output);              $r->print($output);
             &print_footer($r);                  &print_footer($r);    
             return OK;              return OK;
         }          }
     }      }
     $start_page =      $start_page = &Apache::loncommon::start_page($title,$js);
         &Apache::loncommon::start_page($title,$js);  
   
     my %domconfig =       my %domconfig = 
         &Apache::lonnet::get_dom('configuration',['usercreation'],$domain);          &Apache::lonnet::get_dom('configuration',['usercreation'],$domain);
Line 191  sub handler { Line 189  sub handler {
     if ($env{'form.phase'} eq 'username_activation') {      if ($env{'form.phase'} eq 'username_activation') {
         (my $result,$output,$nostart) =           (my $result,$output,$nostart) = 
             &username_activation($r,$env{'form.uname'},$domain,$domdesc,              &username_activation($r,$env{'form.uname'},$domain,$domdesc,
                                  $lonhost,$courseid);                                   $courseid);
         if ($result eq 'ok') {          if ($result eq 'ok') {
             if ($nostart) {              if ($nostart) {
                 return OK;                  return OK;
Line 621  sub process_mailtoken { Line 619  sub process_mailtoken {
         ($data{'username'}  =~ /^[^\@]+\@[^\@]+\.[^\@\.]+$/)) {          ($data{'username'}  =~ /^[^\@]+\@[^\@]+\.[^\@\.]+$/)) {
         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,$uhome) = 
                                                        $data{'username'},$domdesc);                      &create_account($r,$domain,$data{'username'},$domdesc);
                 if ($result eq 'ok') {                  if ($result eq 'ok') {
                     $msg = $output;                       $msg = $output; 
                     my $shownow = &Apache::lonlocal::locallocaltime($now);                      my $shownow = &Apache::lonlocal::locallocaltime($now);
Line 635  sub process_mailtoken { Line 633  sub process_mailtoken {
                     } else {                      } else {
                         $msg .= &mt('An error occurred when sending e-mail to [_1] confirming creation of your LON-CAPA account.',$data{'username'});                          $msg .= &mt('An error occurred when sending e-mail to [_1] confirming creation of your LON-CAPA account.',$data{'username'});
                     }                      }
                     &start_session($r, $data{'username'}, $domain, $lonhost,                      &start_session($r,$data{'username'},$domain,$uhome,
                         $data{'courseid'}, $token);                                     $data{'courseid'},$token);
                     $nostart = 1;                      $nostart = 1;
                     $noend = 1;                      $noend = 1;
                 } else {                  } else {
Line 663  sub process_mailtoken { Line 661  sub process_mailtoken {
 }  }
   
 sub start_session {  sub start_session {
     my ($r, $username, $domain, $lonhost, $courseid, $token) = @_;      my ($r,$username,$domain,$uhome,$courseid,$token) = @_;
   
     if ($r->dir_config('lonBalancer') eq 'yes') {      if ($r->dir_config('lonBalancer') eq 'yes') {
         Apache::lonauth::success($r, $username, $domain, $lonhost,          Apache::lonauth::success($r, $username, $domain, $uhome,
             'noredirect', undef, {});              'noredirect', undef, {});
   
         Apache::lonnet::tmpdel($token) if $token;          Apache::lonnet::tmpdel($token) if $token;
Line 675  sub start_session { Line 673  sub start_session {
     } else {      } else {
         $courseid = Apache::lonnet::is_course($courseid);           $courseid = Apache::lonnet::is_course($courseid); 
   
         Apache::lonauth::success($r, $username, $domain, $lonhost,          Apache::lonauth::success($r, $username, $domain, $uhome,
             ($courseid ? "/adm/selfenroll?courseid=$courseid" : '/adm/roles'),              ($courseid ? "/adm/selfenroll?courseid=$courseid" : '/adm/roles'),
             undef, {});               undef, {}); 
     }      }
Line 683  sub start_session { Line 681  sub start_session {
     return;      return;
 }  }
   
   #
   # The screen that the user gets to create his or her account
   # Desired username, desired password, etc
   # Stores token to store DES-key and stage during creation session
   #
 sub print_dataentry_form {  sub print_dataentry_form {
     my ($r,$domain,$lonhost,$include,$mailtoken,$now,$username,$start_page) = @_;      my ($r,$domain,$lonhost,$include,$mailtoken,$now,$username,$start_page) = @_;
     my ($error,$output);      my ($error,$output);
Line 763  ENDSERVERFORM Line 765  ENDSERVERFORM
     return $output;      return $output;
 }  }
   
   #
   # Retrieve rules for generating accounts from domain configuration
   # Can the user make a new account or just self-enroll?
   
 sub get_creation_controls {  sub get_creation_controls {
     my ($domain,$usercreation) = @_;      my ($domain,$usercreation) = @_;
     my (@cancreate,@statustocreate);      my (@cancreate,@statustocreate);
Line 801  sub get_creation_controls { Line 807  sub get_creation_controls {
 }  }
   
 sub create_account {  sub create_account {
     my ($r,$domain,$lonhost,$username,$domdesc) = @_;      my ($r,$domain,$username,$domdesc) = @_;
   # Get the token info
     my ($retrieved,$output,$upass) = &process_credentials($env{'form.logtoken'},      my ($retrieved,$output,$upass) = &process_credentials($env{'form.logtoken'},
                                                           $env{'form.serverid'});                                                             $env{'form.serverid'}); 
   # $retrieved is 'ok' if things worked
   # $output is user error output
   # $upass is the decrypted password
     # Error messages      # Error messages
     my $error     = '<span class="LC_error">'.&mt('Error:').' ';      my $error     = '<span class="LC_error">'.&mt('Error:').' ';
     my $end       = '</span><br /><br />';      my $end       = '</span><br /><br />';
Line 812  sub create_account { Line 822  sub create_account {
                     &Apache::loncommon::end_page();                      &Apache::loncommon::end_page();
     if ($retrieved eq 'ok') {      if ($retrieved eq 'ok') {
         if ($env{'form.courseid'} ne '') {          if ($env{'form.courseid'} ne '') {
   # See if we are allowed to use this username per domain rules (number of characters, etc)
             my ($result,$userchkmsg) = &check_id($username,$domain,$domdesc);              my ($result,$userchkmsg) = &check_id($username,$domain,$domdesc);
             if ($result eq 'fail') {              if ($result eq 'fail') {
                 $output = $error.&mt('Invalid ID format').$end.                  $output = $error.&mt('Invalid ID format').$end.
Line 822  sub create_account { Line 833  sub create_account {
     } else {      } else {
         return ('fail',$error.$output.$end.$rtnlink);          return ('fail',$error.$output.$end.$rtnlink);
     }      }
     # Call modifyuser      # Yes! We can do this. Valid token, valid username format
       # Create an internally authenticated account with password $upass 
       # if the account does not exist yet
       # Assign student/staff number $env{'form.cid'}, first name, last name, etc
     my $result =       my $result = 
         &Apache::lonnet::modifyuser($domain,$username,$env{'form.cid'},          &Apache::lonnet::modifyuser($domain,$username,$env{'form.cid'},
                                     'internal',$upass,$env{'form.cfirstname'},                                      'internal',$upass,$env{'form.cfirstname'},
                                     $env{'form.cmiddlename'},$env{'form.clastname'},                                      $env{'form.cmiddlename'},$env{'form.clastname'},
                                     $env{'form.cgeneration'},undef,undef,$username);                                      $env{'form.cgeneration'},undef,undef,$username);
     $output = &mt('Generating user: [_1]',$result);      $output = &mt('Generating user: [_1]',$result);
       # Now that the user exists, we can have a homeserver
     my $uhome = &Apache::lonnet::homeserver($username,$domain);      my $uhome = &Apache::lonnet::homeserver($username,$domain);
     $output .= '<br />'.&mt('Home server: [_1]',$uhome).' '.      $output .= '<br />'.&mt('Home server: [_1]',$uhome).' '.
               &Apache::lonnet::hostname($uhome).'<br /><br />';                &Apache::lonnet::hostname($uhome).'<br /><br />';
     return ('ok',$output);      return ('ok',$output,$uhome);
 }  }
   
 sub username_validation {  sub username_validation {
Line 858  sub username_validation { Line 873  sub username_validation {
     if ($uhome ne 'no_host') {      if ($uhome ne 'no_host') {
         my $result = &Apache::lonnet::authenticate($username,$upass,$domain);          my $result = &Apache::lonnet::authenticate($username,$upass,$domain);
         if ($result ne 'no_host') {           if ($result ne 'no_host') { 
             &start_session($r, $username, $domain, $lonhost, $courseid);              &start_session($r,$username,$domain,$uhome,$courseid);
             $output = '<br /><br />'.&mt('A LON-CAPA account already exists for username [_1] at this institution ([_2]).','<tt>'.$username.'</tt>',$domdesc).'<br />'.&mt('The password entered was also correct so you have been logged in.');              $output = '<br /><br />'.&mt('A LON-CAPA account already exists for username [_1] at this institution ([_2]).','<tt>'.$username.'</tt>',$domdesc).'<br />'.&mt('The password entered was also correct so you have been logged in.');
             return ('existingaccount',$output);              return ('existingaccount',$output);
         } else {          } else {
Line 1012  sub username_check { Line 1027  sub username_check {
 }  }
   
 sub username_activation {  sub username_activation {
     my ($r,$username,$domain,$domdesc,$lonhost,$courseid) = @_;      my ($r,$username,$domain,$domdesc,$courseid) = @_;
     my $output;      my $output;
     my $error     = '<span class="LC_error">'.&mt('Error:').' ';      my $error     = '<span class="LC_error">'.&mt('Error:').' ';
     my $end       = '</span><br /><br />';      my $end       = '</span><br /><br />';
Line 1082  sub username_activation { Line 1097  sub username_activation {
         if ($result eq 'ok') {          if ($result eq 'ok') {
             my $delete = &Apache::lonnet::tmpdel($env{'form.authtoken'});              my $delete = &Apache::lonnet::tmpdel($env{'form.authtoken'});
             $output = &mt('A LON-CAPA account has been created for username: [_1] in domain: [_2].',$username,$domain);              $output = &mt('A LON-CAPA account has been created for username: [_1] in domain: [_2].',$username,$domain);
             &start_session($r, $username, $domain, $lonhost, $courseid);              my $uhome=&Apache::lonnet::homeserver($username,$domain,'true');
               &start_session($r,$username,$domain,$uhome,$courseid);
             my $nostart = 1;              my $nostart = 1;
             return ('ok',$output,$nostart);              return ('ok',$output,$nostart);
         } else {          } else {
Line 1098  sub username_activation { Line 1114  sub username_activation {
 sub check_id {  sub check_id {
     my ($username,$domain,$domdesc) = @_;      my ($username,$domain,$domdesc) = @_;
     # Check ID format      # Check ID format
       # Is $username in an okay format for $domain 
       # (right number of characters, special characters, etc - follow domain rules)?
       # $domdesc is just used for user error messages
     my (%alerts,%rulematch,%inst_results,%curr_rules,%checkhash);      my (%alerts,%rulematch,%inst_results,%curr_rules,%checkhash);
     my %checks = ('id' => 1);      my %checks = ('id' => 1);
     %{$checkhash{$username.':'.$domain}} = (      %{$checkhash{$username.':'.$domain}} = (

Removed from v.1.49  
changed lines
  Added in v.1.51


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