Diff for /loncom/interface/createaccount.pm between versions 1.74 and 1.82

version 1.74, 2017/08/03 16:22:08 version 1.82, 2020/12/18 15:23:02
Line 37  use Apache::lonacc; Line 37  use Apache::lonacc;
 use Apache::lonnet;  use Apache::lonnet;
 use Apache::loncommon;  use Apache::loncommon;
 use Apache::lonhtmlcommon;  use Apache::lonhtmlcommon;
   use Apache::lonuserutils;
 use Apache::lonlocal;  use Apache::lonlocal;
 use Apache::lonauth;  use Apache::lonauth;
 use Apache::resetpw;  use Apache::resetpw;
Line 328  sub handler { Line 329  sub handler {
         &print_header($r,$start_page,$courseid,$pagetitle);          &print_header($r,$start_page,$courseid,$pagetitle);
         my $now=time;          my $now=time;
         if ((grep(/^login$/,@{$cancreate})) && (!grep(/^email$/,@{$cancreate}))) {          if ((grep(/^login$/,@{$cancreate})) && (!grep(/^email$/,@{$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);
                 }                  }
Line 520  ENDSCRIPT Line 521  ENDSCRIPT
 }  }
   
 sub javascript_checkpass {  sub javascript_checkpass {
     my ($now,$context) = @_;      my ($now,$context,$domain) = @_;
     my $nopass = &mt('You must enter a password.');      my $nopass = &mt('You must enter a password.');
     my $mismatchpass = &mt('The passwords you entered did not match.')."\n".      my $mismatchpass = &mt('The passwords you entered did not match.')."\n".
                        &mt('Please try again.');                          &mt('Please try again.'); 
       my ($numrules,$intargjs) =
           &Apache::lonuserutils::passwd_validation_js('upass',$domain);
     &js_escape(\$nopass);      &js_escape(\$nopass);
     &js_escape(\$mismatchpass);      &js_escape(\$mismatchpass);
     my $js = <<"ENDSCRIPT";      my $js = <<"ENDSCRIPT";
Line 540  sub javascript_checkpass { Line 543  sub javascript_checkpass {
                 return false;                  return false;
             }              }
             if (upass == upasscheck) {              if (upass == upasscheck) {
                   var numrules = $numrules;
                   if (numrules > 0) {
   $intargjs
                   }
                 client.elements.upasscheck$now.value='';                  client.elements.upasscheck$now.value='';
                 if (validate_email(client)) {                  if (validate_email(client)) {
                     send(one,two,'$context');                      send(one,two,'$context');
Line 563  sub javascript_validmail { Line 570  sub javascript_validmail {
     my %js_lt = &Apache::lonlocal::texthash (      my %js_lt = &Apache::lonlocal::texthash (
                email => 'The e-mail address you entered',                 email => 'The e-mail address you entered',
                notv  => 'is not a valid e-mail address',                 notv  => 'is not a valid e-mail address',
                avae  => 'A valid e-mail address is not formed when the value you entered',                 avae  => 'A valid e-mail address is not formed when the value you entered is combined with the required domain',
                isco  => 'is combined with the required domain',  
     );      );
     my $output =  "\n".'<script type="text/javascript">'."\n".      my $output =  "\n".'<script type="text/javascript">'."\n".
                   '// <![CDATA['."\n".                    '// <![CDATA['."\n".
Line 576  function validate_email(client) { Line 582  function validate_email(client) {
     var condition = '$condition';      var condition = '$condition';
     if (validmail(field,condition) == false) {      if (validmail(field,condition) == false) {
         if ((condition != undefined) && (condition != '')) {          if ((condition != undefined) && (condition != '')) {
             alert("$js_lt{'avae'}: "+field.value+" $js_lt{'isco'}: "+condition);              alert("$js_lt{'avae'}: "+condition);
         } else {          } else {
             alert("$js_lt{'email'}: "+field.value+" $js_lt{'notv'}.");              alert("$js_lt{'email'}: "+field.value+" $js_lt{'notv'}.");
         }          }
Line 634  sub print_username_form { Line 640  sub print_username_form {
                     push(@posstypes,'default');                      push(@posstypes,'default');
                 }                  }
                 $output .= '<p>'.&mt('Choose your affiliation at [_1]',$domdesc).'</p>'."\n".                  $output .= '<p>'.&mt('Choose your affiliation at [_1]',$domdesc).'</p>'."\n".
                            '<form name="reportstatus" id="LC_reportstatus" action="" method="post" '.                             '<form name="reportstatus" id="LC_reportstatus" action="/adm/createaccount" method="post" '.
                            'onsubmit="return checkVerification();"><p>';                             'onsubmit="return checkVerification();"><p>';
                 foreach my $type (@posstypes) {                  foreach my $type (@posstypes) {
                     my $name;                      my $name;
Line 648  sub print_username_form { Line 654  sub print_username_form {
                             }                              }
                         }                          }
                     }                      }
                     $output .= '<label><input type="radio" name="type" value="'.$type.'" />'.                      my $checked;
                       if ($env{'form.type'} eq $type) {
                           $checked = ' checked="checked"';
                       }
                       $output .= '<label><input type="radio" name="type" value="'.$type.'"'.$checked.' />'.
                                $name.'</label>'.('&nbsp;'x2);                                 $name.'</label>'.('&nbsp;'x2);
                 }                  }
                 if ($env{'form.courseid'} =~ /^$match_domain\_$match_courseid$/) {                  if ($env{'form.courseid'} =~ /^$match_domain\_$match_courseid$/) {
Line 687  sub print_username_form { Line 697  sub print_username_form {
                     }                      }
                     if ($usertype eq '') {                      if ($usertype eq '') {
                         $usertype = 'default';                          $usertype = 'default';
                       } elsif (ref($usertypes) eq 'HASH') {
                           my $usertitle;
                           if ($usertype eq 'default') {
                               $usertitle = $othertitle;
                           } elsif (exists($usertypes->{$usertype})) {
                               $usertitle = $usertypes->{$usertype};
                           }
                           if ($usertitle ne '') {
                               $output .= &mt('Self-reported affiliation: [_1]',
                                              '<span style="font-style: italic;">'.$usertitle.'</span>').
                                          '<br />';
                           }
                     }                      }
                     $output .= &print_dataentry_form($r,$domain,$lonhost,$include,$now,$captchaform,                      $output .= &print_dataentry_form($r,$domain,$lonhost,$include,$now,$captchaform,
                                                      $courseid,$emailusername,$captcha,$usertype,                                                       $courseid,$emailusername,$captcha,$usertype,
Line 819  sub process_email_request { Line 841  sub process_email_request {
             } else {              } else {
                 my ($captcha_chk,$captcha_error) = &Apache::loncommon::captcha_response('usercreation',$server);                  my ($captcha_chk,$captcha_error) = &Apache::loncommon::captcha_response('usercreation',$server);
                 if ($captcha_chk != 1) {                  if ($captcha_chk != 1) {
                     $output = &invalid_state('captcha',$domdesc,$contact_name,                      $output = '<span class="LC_warning">'.
                                              $contact_email,$captcha_error);                                &mt('Validation of the code you entered failed.').'</span>'.
                                 '<br />'.$captcha_error."\n".'<br /><p>'.
                                  &mt('[_1]Return[_2] to the previous page to try again.',
                                      '<a href="javascript:document.retryemail.submit();">','</a>')."\n".
                                 '<form name="retryemail" action="/adm/createaccount" method="post" />'.
                                 '<input type="hidden" name="domain" value="'.$domain.'" />'."\n";
                       if ($env{'form.courseid'} =~ /^$match_domain\_$match_courseid$/) {
                           $output .= '<input type="hidden" name="courseid" value="'.$env{'form.courseid'}.'" />'."\n";
                       }
                       if ($env{'form.type'}) {
                           my $usertype = &get_usertype($domain);
                           if ($usertype ne '') {
                               $output .= '<input type="hidden" name="type" value="'.$usertype.'" />'."\n".
                                          '<input type="hidden" name="reportedtype" value="'.&mt('Submit').'" />'."\n";
                           }
                       }
                       $output .= '</form></p>';
                     return $output;                      return $output;
                 }                  }
                 my (%rulematch,%inst_results,%curr_rules,%got_rules,%alerts);                  my (%rulematch,%inst_results,%curr_rules,%got_rules,%alerts);
Line 878  sub send_token { Line 916  sub send_token {
     $env{'form.logtoken'} =~ s/(`)//g;      $env{'form.logtoken'} =~ s/(`)//g;
     if ($env{'form.logtoken'}) {      if ($env{'form.logtoken'}) {
         my $logtoken = $env{'form.logtoken'};          my $logtoken = $env{'form.logtoken'};
           my $earlyout;
         my $tmpinfo=Apache::lonnet::reply('tmpget:'.$logtoken,$server);          my $tmpinfo=Apache::lonnet::reply('tmpget:'.$logtoken,$server);
         if (($tmpinfo=~/^error/) || ($tmpinfo eq 'con_lost')) {          if (($tmpinfo=~/^error/) || ($tmpinfo eq 'con_lost')) {
             $msg = &mt('Information needed to process your request is missing, inaccessible or expired.')              $msg = &mt('Information needed to process your request is missing, inaccessible or expired.')
                   .'<br />'.&mt('Return to the previous page to try again.');                    .'<br /><p>'.&mt('[_1]Return[_2] to the previous page to try again.',
                                      '<a href="javascript:document.retryemail.submit();">','</a>');
               $earlyout = 1;
         } else {          } else {
             my $reply = &Apache::lonnet::reply('tmpdel:'.$logtoken,$server);              my $reply = &Apache::lonnet::reply('tmpdel:'.$logtoken,$server);
             unless ($reply eq 'ok') {              unless ($reply eq 'ok') {
                 $msg .= &mt('Request could not be processed.');                  $msg .= &mt('Request could not be processed.');
             }              }
         }          }
         my %info = ('ip'         => $ENV{'REMOTE_ADDR'},  # Check if the password entered by the user satisfies domain's requirements
           my %passwdconf = &Apache::lonnet::get_passwdconf($domain);
           my ($min,$max,@chars);
           $min = $Apache::lonnet::passwdmin;
           if (ref($passwdconf{'chars'}) eq 'ARRAY') {
               if ($passwdconf{'min'} =~ /^\d+$/) {
                   if ($passwdconf{'min'} > $min) {
                       $min = $passwdconf{'min'};
                   }
               }
               if ($passwdconf{'max'} =~ /^\d+$/) {
                   $max = $passwdconf{'max'};
               }
               @chars = @{$passwdconf{'chars'}};
           }
           my $encpass = $env{'form.upass'};
           if ($encpass eq '') {
               $msg = &mt('Password retrieved was blank.').
                      '<br /><p>'.&mt('[_1]Return[_2] to the previous page to try again.',
                                      '<a href="javascript:document.retryemail.submit();">','</a>');
               $earlyout = 1;
           } else {
   # Split the logtoken to retrieve the DES key and decrypt the encypted password
               my ($key,$caller)=split(/&/,$tmpinfo);
               if ($caller eq 'createaccount') {
                   my $plainpass = &Apache::loncommon::des_decrypt($key,$encpass);
                   if (($min > 0) || ($max ne '') || (@chars > 0)) {
                       my $warning = &Apache::loncommon::check_passwd_rules($domain,$plainpass);
                       if ($warning) {
                           $msg = $warning.
                                  '<p>'.&mt('[_1]Return[_2] to the previous page to try again.',
                                            '<a href="javascript:document.retryemail.submit();">','</a>');
                           $earlyout = 1;
                       }
                   }
               }
           }
           if ($earlyout) {
               $msg .= '<form name="retryemail" action="/adm/createaccount" method="post" />'.
                       '<input type="hidden" name="domain" value="'.$domain.'" />'."\n";
               if ($env{'form.courseid'} =~ /^$match_domain\_$match_courseid$/) {
                   $msg .= '<input type="hidden" name="courseid" value="'.$env{'form.courseid'}.'" />'."\n";
               }
               if ($env{'form.type'}) {
                   my $usertype = &get_usertype($domain);
                   if ($usertype ne '') {
                       $msg .= '<input type="hidden" name="type" value="'.$usertype.'" />'.
                               '<input type="hidden" name="reportedtype" value="'.&mt('Submit').'" />'."\n";
                   }
               }
               $msg .= '</form></p>';
               return $msg;
           }
           my $ip = &Apache::lonnet::get_requestor_ip();
           my %info = ('ip'         => $ip,
                     'time'       => $now,                      'time'       => $now,
                     'domain'     => $domain,                      'domain'     => $domain,
                     'username'   => $email,                      'username'   => $email,
Line 1004  sub process_mailtoken { Line 1099  sub process_mailtoken {
                             &create_account($r,$domain,$domdesc,\%data);                              &create_account($r,$domain,$domdesc,\%data);
                         if ($result eq 'ok') {                          if ($result eq 'ok') {
                             $msg = $output;                              $msg = $output;
                               my $ip = &Apache::lonnet::get_requestor_ip();
                             my $shownow = &Apache::lonlocal::locallocaltime($now);                              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 $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,$ip,$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 1073  sub print_dataentry_form { Line 1169  sub print_dataentry_form {
     my ($r,$domain,$lonhost,$include,$now,$captchaform,$courseid,$emailusername,$captcha,      my ($r,$domain,$lonhost,$include,$now,$captchaform,$courseid,$emailusername,$captcha,
         $usertype,$recaptchaversion,$usernameset,$condition,$excluded) = @_;          $usertype,$recaptchaversion,$usernameset,$condition,$excluded) = @_;
     my ($error,$output);      my ($error,$output);
     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,$recaptchaversion,          $output = &javascript_setforms($now,$emailusername,$captcha,$usertype,$recaptchaversion,
                                        $usernameset,$condition,$excluded).                                         $usernameset,$condition,$excluded).
                   "\n".&javascript_checkpass($now,'email');                    "\n".&javascript_checkpass($now,'email',$domain);
         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 1311  sub create_account { Line 1407  sub create_account {
             unless (($inststatus eq 'default') || ($inststatus eq '')) {              unless (($inststatus eq 'default') || ($inststatus eq '')) {
                 &Apache::lonnet::put('environment',{inststatus => $inststatus},$domain,$username);                  &Apache::lonnet::put('environment',{inststatus => $inststatus},$domain,$username);
             }              }
             $output .= '<br />'.&mt('Home server: [_1]',$uhome).' '.              $output .= '<br />'.&mt('Home Server').": $uhome ".
                        &Apache::lonnet::hostname($uhome).'<br /><br />';                         &Apache::lonnet::hostname($uhome).'<br /><br />';
             return ('ok',$output,$uhome);              return ('ok',$output,$uhome);
         } else {          } else {
Line 1484  sub username_check { Line 1580  sub username_check {
                     '<input type="hidden" name="udom" value="'.$domain.'" />'."\n".                      '<input type="hidden" name="udom" value="'.$domain.'" />'."\n".
                     '<input type="hidden" name="phase" value="username_activation" />';                      '<input type="hidden" name="phase" value="username_activation" />';
         my $now = time;          my $now = time;
         my %info = ('ip'         => $ENV{'REMOTE_ADDR'},          my $ip = &Apache::lonnet::get_requestor_ip();
           my %info = ('ip'         => $ip,
                     'time'       => $now,                      'time'       => $now,
                     'domain'     => $domain,                      'domain'     => $domain,
                     'username'   => $username);                      'username'   => $username);
Line 1688  sub invalid_state { Line 1785  sub invalid_state {
         $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') {
         $msg .= &mt('The e-mail address you provided may not be used as a username at this LON-CAPA institution.');          $msg .= &mt('The e-mail address you provided may not be used as a username at this LON-CAPA institution.');
     } elsif ($error eq 'captcha') {  
         $msg .= &mt('Validation of the code you entered failed.');  
     } elsif ($error eq 'noemails') {      } elsif ($error eq 'noemails') {
         $msg .= &mt('Creation of a new user account using an e-mail address as username is not permitted at this LON-CAPA institution.');          $msg .= &mt('Creation of a new user account using an e-mail address as username is not permitted at this LON-CAPA institution.');
     } elsif ($error eq 'emailfail') {      } elsif ($error eq 'emailfail') {
Line 1870  sub sso_logout_frag { Line 1965  sub sso_logout_frag {
     if (defined($r->dir_config('lonSSOUserLogoutMessageFile_'.$domain))) {      if (defined($r->dir_config('lonSSOUserLogoutMessageFile_'.$domain))) {
         my $msgfile = $r->dir_config('lonSSOUserLogoutMessageFile_'.$domain);          my $msgfile = $r->dir_config('lonSSOUserLogoutMessageFile_'.$domain);
         if (-e $msgfile) {          if (-e $msgfile) {
             open(my $fh,"<$msgfile");              open(my $fh,"<",$msgfile);
             $endsessionmsg = join('',<$fh>);              $endsessionmsg = join('',<$fh>);
             close($fh);              close($fh);
         }          }
     } elsif (defined($r->dir_config('lonSSOUserLogoutMessageFile'))) {      } elsif (defined($r->dir_config('lonSSOUserLogoutMessageFile'))) {
         my $msgfile = $r->dir_config('lonSSOUserLogoutMessageFile');          my $msgfile = $r->dir_config('lonSSOUserLogoutMessageFile');
         if (-e $msgfile) {               if (-e $msgfile) {     
             open(my $fh,"<$msgfile");              open(my $fh,"<",$msgfile);
             $endsessionmsg = join('',<$fh>);              $endsessionmsg = join('',<$fh>);
             close($fh);              close($fh);
         }          }
Line 1996  function checkVerification() { Line 2091  function checkVerification() {
             if (curr == types[j]) {              if (curr == types[j]) {
                 if (!cancreate) {                  if (!cancreate) {
                     alert('Creation of an account via verification by e-mail unavailable for user type: "'+names[j]+'"');                      alert('Creation of an account via verification by e-mail unavailable for user type: "'+names[j]+'"');
                       setElements();
                 }                  }
                 break;                  break;
             }              }

Removed from v.1.74  
changed lines
  Added in v.1.82


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