Diff for /loncom/interface/createaccount.pm between versions 1.40.2.5.2.3 and 1.54

version 1.40.2.5.2.3, 2012/02/11 23:30:16 version 1.54, 2012/12/05 18:23:54
Line 39  use Apache::lonhtmlcommon; Line 39  use Apache::lonhtmlcommon;
 use Apache::lonlocal;  use Apache::lonlocal;
 use Apache::lonauth;  use Apache::lonauth;
 use Apache::resetpw;  use Apache::resetpw;
 use Captcha::reCAPTCHA;  
 use DynaLoader; # for Crypt::DES version  use DynaLoader; # for Crypt::DES version
 use Crypt::DES;  use Crypt::DES;
 use LONCAPA qw(:DEFAULT :match);  use LONCAPA qw(:DEFAULT :match);
 use HTML::Entities;  use HTML::Entities;
   
   #TODO this module needs documentation
   
 sub handler {  sub handler {
     my $r = shift;      my $r = shift;
     &Apache::loncommon::content_type($r,'text/html');      &Apache::loncommon::content_type($r,'text/html');
Line 65  sub handler { Line 66  sub handler {
     if ($sso_username ne '' && $sso_domain ne '') {      if ($sso_username ne '' && $sso_domain ne '') {
         $domain = $sso_domain;           $domain = $sso_domain; 
     } else {      } else {
         $domain = &Apache::lonnet::default_login_domain();          ($domain, undef) = Apache::lonnet::is_course($env{'form.courseid'}); 
         if (defined($env{'form.courseid'})) {          $domain ||= &Apache::lonnet::default_login_domain();
             if (&validate_course($env{'form.courseid'})) {  
                 if ($env{'form.courseid'} =~ /^($match_domain)_($match_courseid)$/) {  
                     $domain = $1;   
                 }  
             }  
         }  
     }      }
     my $domdesc = &Apache::lonnet::domain($domain,'description');      my $domdesc = &Apache::lonnet::domain($domain,'description');
     my $contact_name = &mt('LON-CAPA helpdesk');      my $contact_name = &mt('LON-CAPA helpdesk');
Line 98  sub handler { Line 93  sub handler {
     }      }
   
     my ($js,$courseid,$title);      my ($js,$courseid,$title);
     if (defined($env{'form.courseid'})) {      $courseid = Apache::lonnet::is_course($env{'form.courseid'});
         $courseid = &validate_course($env{'form.courseid'});  
     }  
     if ($courseid ne '') {      if ($courseid ne '') {
         $js = &catreturn_js();          $js = &catreturn_js();
         $title = 'Self-enroll in a LON-CAPA course';          $title = 'Self-enroll in a LON-CAPA course';
Line 127  sub handler { Line 120  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,  
                                                {'no_inline_link'   => 1,});  
             &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,  
                                        {'no_inline_link'   => 1,});  
     my %domconfig =       my %domconfig = 
         &Apache::lonnet::get_dom('configuration',['usercreation'],$domain);          &Apache::lonnet::get_dom('configuration',['usercreation'],$domain);
     my ($cancreate,$statustocreate) = &get_creation_controls($domain,$domconfig{'usercreation'});      my ($cancreate,$statustocreate) = &get_creation_controls($domain,$domconfig{'usercreation'});
Line 146  sub handler { Line 136  sub handler {
         &print_header($r,$start_page,$courseid);          &print_header($r,$start_page,$courseid);
         my $output = '<h3>'.&mt('Account creation unavailable').'</h3>'.          my $output = '<h3>'.&mt('Account creation unavailable').'</h3>'.
                      '<span class="LC_warning">'.                       '<span class="LC_warning">'.
                      &mt('Creation of a new user account using an e-mail address or an institutional log-in ID as username is not permitted for [_1].',$domdesc).'</span><br /><br />';                       &mt('Creation of a new user account using an e-mail address or an institutional log-in ID as username is not permitted at this institution ([_1]).',$domdesc).'</span><br /><br />';
         $r->print($output);          $r->print($output);
         &print_footer($r);          &print_footer($r);
         return OK;          return OK;
Line 198  sub handler { Line 188  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 245  sub handler { Line 235  sub handler {
     return OK;      return OK;
 }  }
   
 sub get_custom_name {  
     my ($domain) = @_;  
     if ($domain eq 'relate') {  
         return 'Learn-Physics';  
     } else {  
         return lc($domain);  
     }  
 }  
   
 sub print_header {  sub print_header {
     my ($r,$start_page,$courseid) = @_;      my ($r,$start_page,$courseid) = @_;
     $r->print($start_page);      $r->print($start_page);
Line 305  sub selfenroll_crumbs { Line 286  sub selfenroll_crumbs {
     return;      return;
 }  }
   
 sub validate_course {  
     my ($courseid) = @_;  
     my ($cdom,$cnum) = ($courseid =~ /^($match_domain)_($match_courseid)$/);  
     if (($cdom ne '') && ($cnum ne '')) {  
         if (&Apache::lonnet::is_course($cdom,$cnum)) {  
             return ($courseid);  
         }  
     }  
     return;  
 }  
   
 sub javascript_setforms {  sub javascript_setforms {
     my ($now) =  @_;      my ($now) =  @_;
     my $js = <<ENDSCRIPT;      my $js = <<ENDSCRIPT;
Line 382  function validate_email() { Line 352  function validate_email() {
     if (validmail(field) == false) {      if (validmail(field) == false) {
         alert("$lt{'email'}: "+field.value+" $lt{'notv'}.");          alert("$lt{'email'}: "+field.value+" $lt{'notv'}.");
         return false;          return false;
     } else {  
        var emailaddr = field.value;  
        var lcemail = emailaddr.toLowerCase();  
        if (emailaddr != lcemail) {  
            field.value = lcemail;  
            alert("Learn-Physics usernames are all lower case.\\nAccordingly your username will be "+lcemail+" once activated.");  
        }  
     }      }
     return true;      return true;
 }  }
Line 417  sub print_username_form { Line 380  sub print_username_form {
             }              }
         }          }
         if (grep(/^email$/,@{$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>';
                         &mt('You are about to sign-up for a Learn Physics account so you can take the pre-requisite test for enrollment in the online course.').'<br />'.              my ($captchaform,$error) = &Apache::loncommon::captcha_display('usercreation',$lonhost);
                         &mt('Your performance on the test will help both you and us gauge your readiness to take the course.').'<br />'.              if ($error) {
                         &mt('Although the pre-test exam will be the basis for admitting people into the course, we can only accommodate a limited number of students.').'<br />'.                  my $helpdesk = '/adm/helpdesk?origurl=%2fadm%2fcreateaccount';
                         &mt('We will e-mail you with instructions on how to access the course by the end of February, if we are able to accommodate you.').'<br />';                  if ($courseid ne '') {
             my $captchaform = &create_recaptcha();                      $helpdesk .= '&courseid='.$courseid;
             if ($captchaform) {                  }
                 my $submit_text = &mt('Sign-up');                  $output .= '<span class="LC_error">'.&mt('An error occurred generating the validation code[_1] required for an e-mail address to be used as username.','<br />').'</span><br /><br />'.&mt('[_1]Contact the helpdesk[_2] or [_3]reload[_2] the page and try again.','<a href="'.$helpdesk.'">','</a>','<a href="javascript:window.location.reload()">');
               } else {
                   my $submit_text = &mt('Request LON-CAPA account');
                 my $emailform = '<input type="text" name="useremail" size="25" value="" />';                  my $emailform = '<input type="text" name="useremail" size="25" value="" />';
                 if (grep(/^login$/,@{$cancreate})) {                  if (grep(/^login$/,@{$cancreate})) {
                     $output .= &mt('Provide your e-mail address to sign up for a Learn Physics account if you do not have a log-in ID at your institution.','<br />').'<br /><br />';                      $output .= &mt('Provide your e-mail address to request a LON-CAPA account,[_1] if you do not have a log-in ID at your institution.','<br />').'<br /><br />';
                 } else {                  } else {
                     $output .= '<br />';                      $output .= '<br />';
                 }                  }
                 $output .=  '<form name="createaccount" method="post" onsubmit="return validate_email()" action="/adm/createaccount">'.                  $output .=  '<form name="createaccount" method="post" onsubmit="return validate_email()" action="/adm/createaccount">'.
                             &Apache::lonhtmlcommon::start_pick_box()."\n".                              &Apache::lonhtmlcommon::start_pick_box()."\n".
                             &Apache::lonhtmlcommon::row_title(&mt('E-mail address'),                              &Apache::lonhtmlcommon::row_title(&mt('E-mail address'),
                                                              'LC_pick_box_title')."\n".                                                                'LC_pick_box_title')."\n".
                             $emailform."\n".                              $emailform."\n";
                             &Apache::lonhtmlcommon::row_closure(1).                  if ($captchaform) {
                             &Apache::lonhtmlcommon::row_title(&mt('Validation'),                      $output .= &Apache::lonhtmlcommon::row_closure(1).
                                                              'LC_pick_box_title')."\n".                                 &Apache::lonhtmlcommon::row_title(&mt('Validation'),
                             $captchaform."\n".                                                                   'LC_pick_box_title')."\n".
                             &mt('If either word is hard to read, [_1] will replace them.','<image src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').'<br /><br />';                                 $captchaform."\n".'<br /><br />';
                   }
                 if ($courseid ne '') {                  if ($courseid ne '') {
                     $output .= '<input type="hidden" name="courseid" value="'.$courseid.'"/>'."\n";                       $output .= '<input type="hidden" name="courseid" value="'.$courseid.'"/>'."\n"; 
                 }                  }
Line 454  sub print_username_form { Line 420  sub print_username_form {
                     $output .= &Apache::lonhtmlcommon::echo_form_input(['courseid']);                      $output .= &Apache::lonhtmlcommon::echo_form_input(['courseid']);
                 }                  }
                 $output .= '</form>';                  $output .= '</form>';
             } else {  
                 my $helpdesk = '/adm/helpdesk?origurl=%2fadm%2fcreateaccount';  
                 if ($courseid ne '') {  
                     $helpdesk .= '&courseid='.$courseid;  
                 }  
                 $output .= '<span class="LC_error">'.&mt('An error occurred generating the validation code[_1] required for an e-mail address to be used as username.','<br />').'</span><br /><br />'.&mt('[_1]Contact the helpdesk[_2] or [_3]reload[_2] the page and try again.','<a href="'.$helpdesk.'">','</a>','<a href="javascript:window.location.reload()">');  
             }              }
             $output .= '</div>';              $output .= '</div>';
         }          }
Line 487  sub login_box { Line 447  sub login_box {
     my $unameform = '<input type="text" name="uname" size="20" value="" />';      my $unameform = '<input type="text" name="uname" size="20" value="" />';
     my $upassform = '<input type="password" name="upass'.$now.'" size="20" />';      my $upassform = '<input type="password" name="upass'.$now.'" size="20" />';
     $output .= '<form name="client" method="post" action="" onsubmit="return(send());">'."\n".      $output .= '<form name="client" method="post" action="" onsubmit="return(send());">'."\n".
                '<input type="hidden" name="udom" value="'.$domain.'" />'.  
                &Apache::lonhtmlcommon::start_pick_box()."\n".                 &Apache::lonhtmlcommon::start_pick_box()."\n".
                &Apache::lonhtmlcommon::row_title($titles{$context},                 &Apache::lonhtmlcommon::row_title($titles{$context},
                                                  'LC_pick_box_title')."\n".                                                   'LC_pick_box_title')."\n".
Line 495  sub login_box { Line 454  sub login_box {
                &Apache::lonhtmlcommon::row_closure(1)."\n".                 &Apache::lonhtmlcommon::row_closure(1)."\n".
                &Apache::lonhtmlcommon::row_title(&mt('Password'),                 &Apache::lonhtmlcommon::row_title(&mt('Password'),
                                                 'LC_pick_box_title')."\n".                                                  'LC_pick_box_title')."\n".
                $upassform.                 $upassform;
                &Apache::lonhtmlcommon::row_closure(1).      if ($context eq 'selfenroll') {
           my $udomform = '<input type="text" name="udom" size="10" value="'.
                           $domain.'" />';
           $output .= &Apache::lonhtmlcommon::row_closure(1)."\n".
                      &Apache::lonhtmlcommon::row_title(&mt('Domain'),
                                                        'LC_pick_box_title')."\n".
                      $udomform."\n";
       } else {
           $output .= '<input type="hidden" name="udom" value="'.$domain.'" />';
       }
       $output .= &Apache::lonhtmlcommon::row_closure(1).
                &Apache::lonhtmlcommon::row_title().                 &Apache::lonhtmlcommon::row_title().
                '<br /><input type="submit" name="username_validation" value="'.                 '<br /><input type="submit" name="username_validation" value="'.
                $submit_text.'" />'."\n";                 $submit_text.'" />'."\n";
Line 517  sub login_box { Line 486  sub login_box {
 sub process_email_request {  sub process_email_request {
     my ($useremail,$domain,$domdesc,$contact_name,$contact_email,$cancreate,      my ($useremail,$domain,$domdesc,$contact_name,$contact_email,$cancreate,
         $server,$settings,$courseid) = @_;          $server,$settings,$courseid) = @_;
     $useremail = lc($env{'form.useremail'});      $useremail = $env{'form.useremail'};
     my $output;      my $output;
     if (ref($cancreate) eq 'ARRAY') {      if (ref($cancreate) eq 'ARRAY') {
         if (!grep(/^email$/,@{$cancreate})) {          if (!grep(/^email$/,@{$cancreate})) {
Line 532  sub process_email_request { Line 501  sub process_email_request {
             my $uhome = &Apache::lonnet::homeserver($useremail,$domain);              my $uhome = &Apache::lonnet::homeserver($useremail,$domain);
             if ($uhome ne 'no_host') {              if ($uhome ne 'no_host') {
                 $output = &invalid_state('existinguser',$domdesc,                  $output = &invalid_state('existinguser',$domdesc,
                                          $contact_name,$contact_email,'',$useremail);                                           $contact_name,$contact_email);
                 return $output;                  return $output;
             } else {              } else {
                  my $captcha = Captcha::reCAPTCHA->new;                  my ($captcha_chk,$captcha_error) = &Apache::loncommon::captcha_response('usercreation',$server);
                  my $captcha_result =                  if ($captcha_chk != 1) {
                      $captcha->check_answer(  
                                             'PRIVATEKEY',  
                                             $ENV{'REMOTE_ADDR'},  
                                             $env{'form.recaptcha_challenge_field'},  
                                             $env{'form.recaptcha_response_field'},  
                                            );  
                 # PRIVATE key from https://www.google.com/recaptcha  
                 if (!$captcha_result->{is_valid}) {  
                     $output = &invalid_state('captcha',$domdesc,$contact_name,                      $output = &invalid_state('captcha',$domdesc,$contact_name,
                                              $contact_email);                                               $contact_email,$captcha_error);
   
                     return $output;                      return $output;
                 }                  }
                 my $uhome=&Apache::lonnet::homeserver($useremail,$domain);                  my $uhome=&Apache::lonnet::homeserver($useremail,$domain);
Line 610  sub send_token { Line 570  sub send_token {
     if ($token !~ /^error/ && $token ne 'no_such_host') {      if ($token !~ /^error/ && $token ne 'no_such_host') {
         my $esc_token = &escape($token);          my $esc_token = &escape($token);
         my $showtime = localtime(time);          my $showtime = localtime(time);
         my $mailmsg = &mt('A request was submitted on [_1] for creation of a [_1] account.',$showtime,$domdesc)."\n".          my $mailmsg = &mt('A request was submitted on [_1] for creation of a LON-CAPA account at the following institution: [_2].',$showtime,$domdesc).' '.
              &mt('To complete this process please open a web browser and enter the following URL in the address/location box: [_1]',               &mt('To complete this process please open a web browser and enter the following URL in the address/location box: [_1]',
                  "\n\n".&Apache::lonnet::absolute_url().'/adm/createaccount?token='.$esc_token);                   &Apache::lonnet::absolute_url().'/adm/createaccount?token='.$esc_token);
         my $result = &Apache::resetpw::send_mail($domdesc,$email,$mailmsg,$contact_name,          my $result = &Apache::resetpw::send_mail($domdesc,$email,$mailmsg,$contact_name,
                                                  $contact_email);                                                   $contact_email);
         if ($result eq 'ok') {          if ($result eq 'ok') {
             $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 sign-up process.').'<br />'.&mt("The link included in the message will be valid for the next [_1]two[_2] hours.",'<b>','</b>');              $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>');
         } else {          } else {
             $msg .= '<span class="LC_error">'.              $msg .= '<span class="LC_error">'.
                     &mt('An error occurred when sending a message to the e-mail address you provided.').'</span><br />'.                      &mt('An error occurred when sending a message to the e-mail address you provided.').'</span><br />'.
Line 647  sub process_mailtoken { Line 607  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);
                     my $mailmsg = &mt('A [_1] account 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 $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'},                      my $mailresult = &Apache::resetpw::send_mail($domdesc,$data{'email'},
                                                                  $mailmsg,$contact_name,                                                                   $mailmsg,$contact_name,
                                                                  $contact_email);                                                                   $contact_email);
Line 661  sub process_mailtoken { Line 621  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'});
                     }                      }
                     my %form = &start_session($r,$data{'username'},$domain,                       &start_session($r,$data{'username'},$domain,$uhome,
                                               $lonhost,$data{'courseid'},                                     $data{'courseid'},$token);
                                               $token);  
                     $nostart = 1;                      $nostart = 1;
                     $noend = 1;                      $noend = 1;
                 } else {                  } else {
Line 690  sub process_mailtoken { Line 649  sub process_mailtoken {
 }  }
   
 sub start_session {  sub start_session {
     my ($r,$username,$domain,$lonhost,$courseid,$token) = @_;      my ($r,$username,$domain,$uhome,$courseid,$token) = @_;
     my %form = (  
                 uname => $username,  
                 udom  => $domain,  
                );  
     my $firsturl = '/adm/roles';  
     if (defined($courseid)) {  
         $courseid = &validate_course($courseid);  
         if ($courseid ne '') {  
             $form{'courseid'} = $courseid;  
             $firsturl = '/adm/selfenroll?courseid='.$courseid;  
         }  
     }  
     if ($r->dir_config('lonBalancer') eq 'yes') {      if ($r->dir_config('lonBalancer') eq 'yes') {
         &Apache::lonauth::success($r,$form{'uname'},$form{'udom'},          Apache::lonauth::success($r, $username, $domain, $uhome,
                                   $lonhost,'noredirect',undef,\%form);              'noredirect', undef, {});
         if ($token ne '') {   
             my $delete = &Apache::lonnet::tmpdel($token);          Apache::lonnet::tmpdel($token) if $token;
         }  
         $r->internal_redirect('/adm/switchserver');          $r->internal_redirect('/adm/switchserver');
     } else {      } else {
         &Apache::lonauth::success($r,$form{'uname'},$form{'udom'},          $courseid = Apache::lonnet::is_course($courseid); 
                                   $lonhost,$firsturl,undef,\%form);  
           Apache::lonauth::success($r, $username, $domain, $uhome,
               ($courseid ? "/adm/selfenroll?courseid=$courseid" : '/adm/roles'),
               undef, {}); 
     }      }
     return %form;  
 }  
   
       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 797  ENDSERVERFORM Line 753  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 835  sub get_creation_controls { Line 795  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 />';
     my $rtnlink   = '<a href="javascript:history.back();" />'.      my $rtnlink   = '<a href="javascript:history.back();">'.
                     &mt('Return to previous page').'</a>'.                      &mt('Return to previous page').'</a>'.
                     &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 856  sub create_account { Line 821  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 {
     my ($r,$username,$domain,$domdesc,$contact_name,$contact_email,$courseid,      my ($r,$username,$domain,$domdesc,$contact_name,$contact_email,$courseid,
         $lonhost,$statustocreate) = @_;          $lonhost,$statustocreate) = @_;
   # $username,$domain: for the user who needs to be validated
   # $domdesc: full name of the domain (for error messages)
   # $contact_name, $contact_email: name and email for user assistance (for error messages in &username_check
   # $courseid: ID of the course that the user should be validated for, goes into start_session
   # $statustocreate: -> inststatus in username_check ('faculty', 'staff', 'student', ...)
    
     my ($retrieved,$output,$upass);      my ($retrieved,$output,$upass);
   
     $username= &LONCAPA::clean_username($username);      $username= &LONCAPA::clean_username($username);
Line 886  sub username_validation { Line 861  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') { 
             my %form = &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 1040  sub username_check { Line 1015  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 />';
     my $rtnlink   = '<a href="javascript:history.back();" />'.      my $rtnlink   = '<a href="javascript:history.back();">'.
                     &mt('Return to previous page').'</a>'.                      &mt('Return to previous page').'</a>'.
                     &Apache::loncommon::end_page();                      &Apache::loncommon::end_page();
     my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);      my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
Line 1110  sub username_activation { Line 1085  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);
             my %form = &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 1126  sub username_activation { Line 1102  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}} = (
Line 1153  sub check_id { Line 1132  sub check_id {
 }  }
   
 sub invalid_state {  sub invalid_state {
     my ($error,$domdesc,$contact_name,$contact_email,$msgtext,$useremail) = @_;      my ($error,$domdesc,$contact_name,$contact_email,$msgtext) = @_;
     my $msg = '<h3>'.&mt('Account creation unavailable').'</h3><span class="LC_error">';      my $msg = '<h3>'.&mt('Account creation unavailable').'</h3><span class="LC_error">';
     if ($error eq 'baduseremail') {      if ($error eq 'baduseremail') {
         $msg .= &mt('The e-mail address you provided does not appear to be a valid address.');          $msg .= &mt('The e-mail address you provided does not appear to be a valid address.');
     } elsif ($error eq 'existinguser') {      } elsif ($error eq 'existinguser') {
         my $uname = &HTML::Entities::encode($useremail);           $msg .= &mt('The e-mail address you provided is already in use as a username in LON-CAPA at this institution.');
         $msg .= &mt('The e-mail address you provided is already in use as a username in LON-CAPA at this institution.').'</span><br /><br /><span class="LC_warning">'.&mt('You can either:').'<ul>'.  
                 '<li>'.&mt('Return to the [_1]log-in page[_2] and enter your password.','<a href="/adm/login?username='.$uname.'">','</a>').'</li>'.  
                 '<li>'.&mt('or, if you do not remember your password, visit the "[_1]Forgot your password?[_2]" page.','<a href="/adm/resetpw?uname='.$uname.'&useremail='.$uname.'&referrer=createaccount">','</a>').  
                 '</li></ul>';  
     } elsif ($error eq 'userrules') {      } elsif ($error eq 'userrules') {
         $msg .= &mt('Username rules at this institution do not allow the e-mail address you provided to be used as a username.');          $msg .= &mt('Username rules at this institution do not allow the e-mail address you provided to be used as a username.');
     } elsif ($error eq 'userformat') {      } elsif ($error eq 'userformat') {
Line 1198  sub linkto_email_help { Line 1173  sub linkto_email_help {
     return $msg;      return $msg;
 }  }
   
 sub create_recaptcha {  
     my $captcha = Captcha::reCAPTCHA->new;  
     # generate PUBLICKEY from https://www.google.com/recaptcha  
     return $captcha->get_options_setter({theme => 'white'})."\n".  
            $captcha->get_html('PUBLICKEY');  
 }  
   
 sub getkeys {  sub getkeys {
     my ($lkey,$ukey) = @_;      my ($lkey,$ukey) = @_;
     my $lextkey=hex($lkey);      my $lextkey=hex($lkey);
Line 1242  ENDSERVERFORM Line 1210  ENDSERVERFORM
 }  }
   
 sub process_credentials {  sub process_credentials {
   #
   # Fetches the information from the logtoken via tmpget
   # Token contains the DES-key and the stage of the process (would only be "createaccount")
   # $lonhost in this routine is *not* necessarily the machine that this runs on,
   # but $env{'form.serverid'}, the machine that issued the token. 
   #
     my ($logtoken,$lonhost) = @_;      my ($logtoken,$lonhost) = @_;
     my $tmpinfo=Apache::lonnet::reply('tmpget:'.$logtoken,$lonhost);      my $tmpinfo=Apache::lonnet::reply('tmpget:'.$logtoken,$lonhost);
     my ($retrieved,$output,$upass);      my ($retrieved,$output,$upass);
Line 1263  sub process_credentials { Line 1237  sub process_credentials {
     } else {      } else {
         $output = &mt('Unable to retrieve your log-in information - unexpected context');          $output = &mt('Unable to retrieve your log-in information - unexpected context');
     }      }
   # $retrieved is 'ok' if retrieved okay
   # $output is screen output for the user
   # $upass is $env{'form.upass'}, decrypted with the DES-key, if stage was 'createaccount'
   
     return ($retrieved,$output,$upass);      return ($retrieved,$output,$upass);
 }  }
   

Removed from v.1.40.2.5.2.3  
changed lines
  Added in v.1.54


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