[LON-CAPA-cvs] cvs: loncom(version_2_11_X) /interface createaccount.pm

raeburn raeburn at source.lon-capa.org
Sun Aug 25 09:55:56 EDT 2019


raeburn		Sun Aug 25 13:55:56 2019 EDT

  Modified files:              (Branch: version_2_11_X)
    /loncom/interface	createaccount.pm 
  Log:
  - For 2.11
    Backport 1.77, 1.78, 1.79 
  
  
-------------- next part --------------
Index: loncom/interface/createaccount.pm
diff -u loncom/interface/createaccount.pm:1.72.4.2 loncom/interface/createaccount.pm:1.72.4.3
--- loncom/interface/createaccount.pm:1.72.4.2	Mon Jul 29 13:54:02 2019
+++ loncom/interface/createaccount.pm	Sun Aug 25 13:55:55 2019
@@ -4,7 +4,7 @@
 # kerberos, or SSO) or an e-mail address. Requests to use an e-mail address as
 # username may be processed automatically, or may be queued for approval.
 #
-# $Id: createaccount.pm,v 1.72.4.2 2019/07/29 13:54:02 raeburn Exp $
+# $Id: createaccount.pm,v 1.72.4.3 2019/08/25 13:55:55 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -37,6 +37,7 @@
 use Apache::lonnet;
 use Apache::loncommon;
 use Apache::lonhtmlcommon;
+use Apache::lonuserutils;
 use Apache::lonlocal;
 use Apache::lonauth;
 use Apache::resetpw;
@@ -520,10 +521,12 @@
 }
 
 sub javascript_checkpass {
-    my ($now,$context) = @_;
+    my ($now,$context,$domain) = @_;
     my $nopass = &mt('You must enter a password.');
     my $mismatchpass = &mt('The passwords you entered did not match.')."\n".
                        &mt('Please try again.'); 
+    my ($numrules,$intargjs) =
+        &Apache::lonuserutils::passwd_validation_js('upass',$domain);
     &js_escape(\$nopass);
     &js_escape(\$mismatchpass);
     my $js = <<"ENDSCRIPT";
@@ -540,6 +543,10 @@
                 return false;
             }
             if (upass == upasscheck) {
+                var numrules = $numrules;
+                if (numrules > 0) {
+$intargjs
+                }
                 client.elements.upasscheck$now.value='';
                 if (validate_email(client)) {
                     send(one,two,'$context');
@@ -835,8 +842,24 @@
             } else {
                 my ($captcha_chk,$captcha_error) = &Apache::loncommon::captcha_response('usercreation',$server);
                 if ($captcha_chk != 1) {
-                    $output = &invalid_state('captcha',$domdesc,$contact_name,
-                                             $contact_email,$captcha_error);
+                    $output = '<span class="LC_warning">'.
+                              &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;
                 }
                 my (%rulematch,%inst_results,%curr_rules,%got_rules,%alerts);
@@ -894,16 +917,72 @@
     $env{'form.logtoken'} =~ s/(`)//g;
     if ($env{'form.logtoken'}) {
         my $logtoken = $env{'form.logtoken'};
+        my $earlyout;
         my $tmpinfo=Apache::lonnet::reply('tmpget:'.$logtoken,$server);
         if (($tmpinfo=~/^error/) || ($tmpinfo eq 'con_lost')) {
             $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 {
             my $reply = &Apache::lonnet::reply('tmpdel:'.$logtoken,$server);
             unless ($reply eq 'ok') {
                 $msg .= &mt('Request could not be processed.');
             }
         }
+# Check if the password entered by the user satisfies domain's requirements
+        my %passwdconf = &Apache::lonnet::get_passwdconf($domain);
+        my ($min,$max, at 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 %info = ('ip'         => $ENV{'REMOTE_ADDR'},
                     'time'       => $now,
                     'domain'     => $domain,
@@ -1096,7 +1175,7 @@
         close($jsh);
         $output = &javascript_setforms($now,$emailusername,$captcha,$usertype,$recaptchaversion,
                                        $usernameset,$condition,$excluded).
-                  "\n".&javascript_checkpass($now,'email');
+                  "\n".&javascript_checkpass($now,'email',$domain);
         my ($lkey,$ukey) = &Apache::loncommon::des_keys();
         my ($lextkey,$uextkey) = &getkeys($lkey,$ukey);
         my $logtoken=Apache::lonnet::reply('tmpput:'.$ukey.$lkey.'&createaccount:createaccount',
@@ -1704,8 +1783,6 @@
         $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') {
         $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') {
         $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') {


More information about the LON-CAPA-cvs mailing list