Diff for /loncom/interface/createaccount.pm between versions 1.62 and 1.68

version 1.62, 2014/03/30 23:44:50 version 1.68, 2014/06/19 23:36:54
Line 170  sub handler { Line 170  sub handler {
         if (grep(/^sso$/,@{$cancreate})) {          if (grep(/^sso$/,@{$cancreate})) {
             $msg = '<h3>'.&mt('Account creation').'</h3>'.              $msg = '<h3>'.&mt('Account creation').'</h3>'.
                    &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 />';                     &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 />';
               my $shibenv;
               if (($r->dir_config('lonOtherAuthen') eq 'yes') && 
                   ($r->dir_config('lonOtherAuthenType') eq 'Shibboleth')) {
                   if (ref($domconfig{'usercreation'}) eq 'HASH') {
                       if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
                           if (ref($domconfig{'usercreation'}{'cancreate'}{'shibenv'}) eq 'HASH') {
                               my @possfields = ('firstname','middlename','lastname','generation',
                                                 'permanentemail','id');
                               my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($domain);
                               $shibenv= {};
                               foreach my $key (keys(%{$domconfig{'usercreation'}{'cancreate'}{'shibenv'}})) {
                                   if ($key eq 'inststatus') {
                                       if (ref($usertypes) eq 'HASH') {
                                           if ($domconfig{'usercreation'}{'cancreate'}{'shibenv'}{$key} ne '') {
                                               if (exists($usertypes->{$domconfig{'usercreation'}{'cancreate'}{'shibenv'}{$key}})) {
                                                   $shibenv->{$key} = $domconfig{'usercreation'}{'cancreate'}{'shibenv'}{$key};
                                                }
                                           }
                                       }
                                   } elsif (grep(/^\Q$key\E/,@possfields)) {
                                       if ($domconfig{'usercreation'}{'cancreate'}{'shibenv'}{$key} ne '') {
                                           $shibenv->{$key} = $domconfig{'usercreation'}{'cancreate'}{'shibenv'}{$key};
                                       }
                                   }
                               }
                           }
                       }
                   }
               }
             $msg .= &username_check($sso_username,$domain,$domdesc,$courseid,               $msg .= &username_check($sso_username,$domain,$domdesc,$courseid, 
                                     $lonhost,$contact_email,$contact_name,                                      $lonhost,$contact_email,$contact_name,
                                     $sso_logout,$statustocreate);                                      $sso_logout,$statustocreate,$shibenv);
         } else {          } else {
             $msg = '<h3>'.&mt('Account creation unavailable').'</h3>'.              $msg = '<h3>'.&mt('Account creation unavailable').'</h3>'.
                    '<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 />'.                     '<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 />'.
Line 187  sub handler { Line 215  sub handler {
     my ($output,$nostart,$noend,$redirect);      my ($output,$nostart,$noend,$redirect);
     my $token = $env{'form.token'};      my $token = $env{'form.token'};
     if ($token) {      if ($token) {
           my $usertype = &get_usertype($domain);
         ($output,$nostart,$noend,$redirect) =           ($output,$nostart,$noend,$redirect) = 
             &process_mailtoken($r,$token,$contact_name,$contact_email,$domain,              &process_mailtoken($r,$token,$contact_name,$contact_email,$domain,
                                $domdesc,$lonhost,$include,$start_page,$cancreate,                                 $domdesc,$lonhost,$include,$start_page,$cancreate,
                                $domconfig{'usercreation'});                                 $domconfig{'usercreation'},$usertype);
         if ($redirect) {          if ($redirect) {
             $r->internal_redirect('/adm/switchserver');              $r->internal_redirect('/adm/switchserver');
             return OK;              return OK;
Line 248  sub handler { Line 277  sub handler {
     } elsif (!$token) {      } elsif (!$token) {
         &print_header($r,$start_page,$courseid);          &print_header($r,$start_page,$courseid);
         my $now=time;          my $now=time;
         my $gotlondes;          if ((grep(/^login$/,@{$cancreate})) && (!grep(/^email$/,@{$cancreate}))) {
         if (grep(/^login$/,@{$cancreate})) {  
             if (open(my $jsh,"<$include/londes.js")) {              if (open(my $jsh,"<$include/londes.js")) {
                 while(my $line = <$jsh>) {                  while(my $line = <$jsh>) {
                     $r->print($line);                      $r->print($line);
                 }                  }
                 close($jsh);                  close($jsh);
                 $r->print(&javascript_setforms($now));                  $r->print(&javascript_setforms($now));
                 $gotlondes = 1;  
             }              }
         }          }
         if (grep(/^email(|approval)$/,@{$cancreate})) {          if (grep(/^email$/,@{$cancreate})) {
             $r->print(&javascript_validmail());              $r->print(&javascript_validmail());
         }          }
         my $usertype = &get_usertype($domain);          my $usertype = &get_usertype($domain);
         $output = &print_username_form($r,$domain,$domdesc,$cancreate,$now,$lonhost,          $output = &print_username_form($r,$domain,$domdesc,$cancreate,$now,$lonhost,
                                        $include,$courseid,$gotlondes,$emailusername,                                         $include,$courseid,$emailusername,$usertype);
                                        $usertype);  
     }      }
     $r->print($output);      $r->print($output);
     &print_footer($r);      &print_footer($r);
Line 483  ENDSCRIPT Line 509  ENDSCRIPT
 }  }
   
 sub print_username_form {  sub print_username_form {
     my ($r,$domain,$domdesc,$cancreate,$now,$lonhost,$include,$courseid,$gotlondes,$emailusername,      my ($r,$domain,$domdesc,$cancreate,$now,$lonhost,$include,$courseid,$emailusername,
         $usertype) = @_;          $usertype) = @_;
     my %lt = &Apache::lonlocal::texthash (      my %lt = &Apache::lonlocal::texthash (
                                          unam => 'username',                                           unam => 'username',
Line 511  sub print_username_form { Line 537  sub print_username_form {
                                       $domain,'createaccount').'</div>';                                        $domain,'createaccount').'</div>';
             }              }
         }          }
         if (grep(/^email(|approval)$/,@{$cancreate})) {          if (grep(/^email$/,@{$cancreate})) {
             $output .= '<div class="LC_left_float"><h3>'.&mt('Create account with an e-mail address as your username').'</h3>';              $output .= '<div class="LC_left_float"><h3>'.&mt('Create account with an e-mail address as your username').'</h3>';
             my ($captchaform,$error,$captcha) = &Apache::loncommon::captcha_display('usercreation',$lonhost);              my ($captchaform,$error,$captcha) = &Apache::loncommon::captcha_display('usercreation',$lonhost);
             if ($error) {              if ($error) {
Line 542  sub print_username_form { Line 568  sub print_username_form {
                                $lt{'yopw'}.'<br />';                                 $lt{'yopw'}.'<br />';
                 }                  }
                 $output .= &print_dataentry_form($r,$domain,$lonhost,$include,$now,$captchaform,                  $output .= &print_dataentry_form($r,$domain,$lonhost,$include,$now,$captchaform,
                                                  $courseid,$gotlondes,$emailusername,$captcha,                                                   $courseid,$emailusername,$captcha,$usertype);
                                                  $usertype);  
             }              }
             $output .= '</div>';              $output .= '</div>';
         }          }
Line 612  sub process_email_request { Line 637  sub process_email_request {
         $server,$settings,$emailusername,$courseid,$usertype) = @_;          $server,$settings,$emailusername,$courseid,$usertype) = @_;
     my $output;      my $output;
     if (ref($cancreate) eq 'ARRAY') {      if (ref($cancreate) eq 'ARRAY') {
         if (!grep(/^email(|approval)$/,@{$cancreate})) {          if (!grep(/^email$/,@{$cancreate})) {
             $output = &invalid_state('noemails',$domdesc,              $output = &invalid_state('noemails',$domdesc,
                                      $contact_name,$contact_email);                                       $contact_name,$contact_email);
             return $output;              return $output;
Line 755  sub send_token { Line 780  sub send_token {
   
 sub process_mailtoken {  sub process_mailtoken {
     my ($r,$token,$contact_name,$contact_email,$domain,$domdesc,$lonhost,      my ($r,$token,$contact_name,$contact_email,$domain,$domdesc,$lonhost,
         $include,$start_page,$cancreate,$settings) = @_;          $include,$start_page,$cancreate,$settings,$usertype) = @_;
     my ($msg,$nostart,$noend,$redirect);      my ($msg,$nostart,$noend,$redirect);
     my %data = &Apache::lonnet::tmpget($token);      my %data = &Apache::lonnet::tmpget($token);
     my $now = time;      my $now = time;
Line 772  sub process_mailtoken { Line 797  sub process_mailtoken {
         if ($now - $data{'time'} < 7200) {          if ($now - $data{'time'} < 7200) {
 # Check if request should be queued.  # Check if request should be queued.
             if (ref($cancreate) eq 'ARRAY') {              if (ref($cancreate) eq 'ARRAY') {
                   my $disposition;
                 if (grep(/^email$/,@{$cancreate})) {                  if (grep(/^email$/,@{$cancreate})) {
                     my ($result,$output,$uhome) =                       if (ref($settings) eq 'HASH') {
                         &create_account($r,$domain,$domdesc,\%data);                          if (ref($settings->{'cancreate'}) eq 'HASH') {
                     if ($result eq 'ok') {                              if (ref($settings->{'cancreate'}{'selfcreateprocessing'}) eq 'HASH') {
                         $msg = $output;                                  $disposition = $settings->{'cancreate'}{'selfcreateprocessing'}{$usertype}; 
                         my $shownow = &Apache::lonlocal::locallocaltime($now);                              }
                         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";  
                         my $mailresult = &Apache::resetpw::send_mail($domdesc,$data{'email'},  
                                                                      $mailmsg,$contact_name,  
                                                                      $contact_email);  
                         if ($mailresult eq 'ok') {  
                             $msg .= &mt('An e-mail confirming creation of your new LON-CAPA account has been sent to [_1].',$data{'username'});  
                         } else {  
                             $msg .= &mt('An error occurred when sending e-mail to [_1] confirming creation of your LON-CAPA account.',$data{'username'});  
                         }                          }
                         $redirect = &start_session($r,$data{'username'},$domain,$uhome,                      }
                                                    $data{'courseid'},$token);                      if ($disposition eq 'approval') {
                         $nostart = 1;                          $msg = &store_request($domain,$data{'username'},'approval',\%data,$settings);
                         $noend = 1;                          my $delete = &Apache::lonnet::tmpdel($token);
                     } else {                      } else {
                         $msg .= &mt('A problem occurred when attempting to create your new LON-CAPA account.')                          my ($result,$output,$uhome) = 
                                .'<br />'.$output;                              &create_account($r,$domain,$domdesc,\%data);
                         if (($contact_name ne '') && ($contact_email ne '')) {                          if ($result eq 'ok') {
                             $msg .= &mt('Please contact the [_1] ([_2]) for assistance.',$contact_name,$contact_email);                              $msg = $output;
                               my $shownow = &Apache::lonlocal::locallocaltime($now);
                               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";
                               my $mailresult = &Apache::resetpw::send_mail($domdesc,$data{'email'},
                                                                           $mailmsg,$contact_name,
                                                                           $contact_email);
                               if ($mailresult eq 'ok') {
                                   $msg .= &mt('An e-mail confirming creation of your new LON-CAPA account has been sent to [_1].',$data{'username'});
                               } else {
                                   $msg .= &mt('An error occurred when sending e-mail to [_1] confirming creation of your LON-CAPA account.',$data{'username'});
                               }
                               $redirect = &start_session($r,$data{'username'},$domain,$uhome,
                                                          $data{'courseid'},$token);
                               $nostart = 1;
                               $noend = 1;
                           } else {
                               $msg .= &mt('A problem occurred when attempting to create your new LON-CAPA account.')
                                      .'<br />'.$output;
                               if (($contact_name ne '') && ($contact_email ne '')) {
                                   $msg .= &mt('Please contact the [_1] ([_2]) for assistance.',$contact_name,$contact_email);
                               }
                         }                          }
                           my $delete = &Apache::lonnet::tmpdel($token);
                     }                      }
                     my $delete = &Apache::lonnet::tmpdel($token);  
                 } elsif (grep(/^emailapproval$/,@{$cancreate})) {  
                     $msg = &store_request($domain,$data{'username'},'approval',\%data,$settings);  
                     my $delete = &Apache::lonnet::tmpdel($token);  
                 } else {                  } else {
                     $msg = &invalid_state('noemails',$domdesc,$contact_name,$contact_email);                      $msg = &invalid_state('noemails',$domdesc,$contact_name,$contact_email);
                 }                  }
Line 846  sub start_session { Line 881  sub start_session {
 # Stores token to store DES-key and stage during creation session  # Stores token to store DES-key and stage during creation session
 #  #
 sub print_dataentry_form {  sub print_dataentry_form {
     my ($r,$domain,$lonhost,$include,$now,$captchaform,$courseid,$gotlondes,$emailusername,$captcha,      my ($r,$domain,$lonhost,$include,$now,$captchaform,$courseid,$emailusername,$captcha,
         $usertype) = @_;          $usertype) = @_;
     my ($error,$output);      my ($error,$output);
     unless ($gotlondes) {      if (open(my $jsh,"<$include/londes.js")) {
         if (open(my $jsh,"<$include/londes.js")) {          while(my $line = <$jsh>) {
             while(my $line = <$jsh>) {              $r->print($line);
                 $r->print($line);          }
             }          close($jsh);
             close($jsh);          $output = &javascript_setforms($now,$emailusername,$captcha,$usertype)."\n".
             $output = &javascript_setforms($now,$emailusername,$captcha,$usertype)."\n";                    &javascript_checkpass($now,'email');
             $gotlondes = 1;  
         }  
     }  
     if ($gotlondes) {  
         $output .= &javascript_checkpass($now,'email');  
         my ($lkey,$ukey) = &Apache::loncommon::des_keys();          my ($lkey,$ukey) = &Apache::loncommon::des_keys();
         my ($lextkey,$uextkey) = &getkeys($lkey,$ukey);          my ($lextkey,$uextkey) = &getkeys($lkey,$ukey);
         my $logtoken=Apache::lonnet::reply('tmpput:'.$ukey.$lkey.'&createaccount:createaccount',          my $logtoken=Apache::lonnet::reply('tmpput:'.$ukey.$lkey.'&createaccount:createaccount',
Line 964  sub get_creation_controls { Line 994  sub get_creation_controls {
             if (ref($usercreation->{'cancreate'}{'emailusername'}) eq 'HASH') {              if (ref($usercreation->{'cancreate'}{'emailusername'}) eq 'HASH') {
                 $emailusername = $usercreation->{'cancreate'}{'emailusername'};                  $emailusername = $usercreation->{'cancreate'}{'emailusername'};
             } else {              } else {
                 $emailusername =  {'lastname' => '1', 'firstname' => 1, };                  $emailusername = {
                                       default =>  {
                                                      'lastname' => '1',
                                                      'firstname' => 1,
                                                   },
                                    };
             }              }
         }          }
     }      }
Line 991  sub create_account { Line 1026  sub create_account {
         $middlename = $dataref->{'middlename'};          $middlename = $dataref->{'middlename'};
         $lastname   = $dataref->{'lastname'};          $lastname   = $dataref->{'lastname'};
         $generation = $dataref->{'generation'};          $generation = $dataref->{'generation'};
         $inststatus = $dataref->{'usertype'};          $inststatus = $dataref->{'inststatus'};
          
         my $currhome = &Apache::lonnet::homeserver($username,$domain);          my $currhome = &Apache::lonnet::homeserver($username,$domain);
         unless ($currhome eq 'no_host') {          unless ($currhome eq 'no_host') {
             $output = &mt('User account requested for username: [_1] in domain: [_2] already exists.',$username,$domain);              $output = &mt('User account requested for username: [_1] in domain: [_2] already exists.',$username,$domain);
Line 1153  sub login_failure_msg { Line 1188  sub login_failure_msg {
   
 sub username_check {  sub username_check {
     my ($username,$domain,$domdesc,$courseid,$lonhost,$contact_email,      my ($username,$domain,$domdesc,$courseid,$lonhost,$contact_email,
         $contact_name,$sso_logout,$statustocreate) = @_;          $contact_name,$sso_logout,$statustocreate,$shibenv) = @_;
     my (%rulematch,%inst_results,$checkfail,$rowcount,$editable,$output,$msg,      my (%rulematch,%inst_results,$checkfail,$rowcount,$editable,$output,$msg,
         %alerts,%curr_rules,%got_rules);          %alerts,%curr_rules,%got_rules);
     &call_rulecheck($username,$domain,\%alerts,\%rulematch,      &call_rulecheck($username,$domain,\%alerts,\%rulematch,
Line 1189  sub username_check { Line 1224  sub username_check {
     }      }
     if (!$checkfail) {      if (!$checkfail) {
         $output = '<form method="post" action="/adm/createaccount">';          $output = '<form method="post" action="/adm/createaccount">';
           if (ref($shibenv) eq 'HASH') {
               foreach my $key (keys(%{$shibenv})) {
                   if ($ENV{$shibenv->{$key}} ne '') {
                       $inst_results{$username.':'.$domain}{$key} = $ENV{$shibenv->{$key}};
                   }
               }
           }
         (my $datatable,$rowcount,$editable) =           (my $datatable,$rowcount,$editable) = 
             &Apache::loncreateuser::personal_data_display($username,$domain,1,'selfcreate',              &Apache::loncreateuser::personal_data_display($username,$domain,1,'selfcreate',
                                                          $inst_results{$username.':'.$domain});                                                           $inst_results{$username.':'.$domain});

Removed from v.1.62  
changed lines
  Added in v.1.68


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