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

raeburn raeburn at source.lon-capa.org
Sun Aug 25 10:35:24 EDT 2019


raeburn		Sun Aug 25 14:35:24 2019 EDT

  Modified files:              (Branch: version_2_11_X)
    /loncom/interface	domainprefs.pm 
  Log:
  - For 2.11
    Backport 1.365, 1.366, 1.367 (except password expiration parts).
  
  
-------------- next part --------------
Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.160.6.98 loncom/interface/domainprefs.pm:1.160.6.99
--- loncom/interface/domainprefs.pm:1.160.6.98	Wed Aug 21 20:31:37 2019
+++ loncom/interface/domainprefs.pm	Sun Aug 25 14:35:21 2019
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set domain-wide configuration settings
 #
-# $Id: domainprefs.pm,v 1.160.6.98 2019/08/21 20:31:37 raeburn Exp $
+# $Id: domainprefs.pm,v 1.160.6.99 2019/08/25 14:35:21 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -4341,6 +4341,7 @@
         }
     } elsif ($position eq 'lower') {
         my ($min,$max,%chars,$numsaved);
+        $min = $Apache::lonnet::passwdmin;
         if (ref($settings) eq 'HASH') {
             if ($settings->{min}) {
                 $min = $settings->{min};
@@ -4354,8 +4355,6 @@
             if ($settings->{numsaved}) {
                 $numsaved = $settings->{numsaved};
             }
-        } else {
-            $min = '7';
         }
         my %rulenames = &Apache::lonlocal::texthash(
                                                      uc => 'At least one upper case letter',
@@ -4366,14 +4365,16 @@
         $css_class = $itemcount%2?' class="LC_odd_row"':'';
         $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
                       '<td class="LC_left_item"><span class="LC_nobreak">'.
-                      '<input type="text" name="passwords_min" value="'.$min.'" size="3" />'.
-                      '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no minimum)').'</span>'.
+                      '<input type="text" name="passwords_min" value="'.$min.'" size="3" '.
+                      'onblur="javascript:warnIntPass(this);" />'.
+                      '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
                       '</span></td></tr>';
         $itemcount ++;
         $css_class = $itemcount%2?' class="LC_odd_row"':'';
         $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
                       '<td class="LC_left_item"><span class="LC_nobreak">'.
-                      '<input type="text" name="passwords_max" value="'.$max.'" size="3" />'.
+                      '<input type="text" name="passwords_max" value="'.$max.'" size="3" '.
+                      'onblur="javascript:warnIntPass(this);" />'.
                       '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
                       '</span></td></tr>';
         $itemcount ++;
@@ -4413,7 +4414,8 @@
         $css_class = $itemcount%2?' class="LC_odd_row"':'';
         $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
                       '<td class="LC_left_item"><span class="LC_nobreak">'.
-                      '<input type="text" name="passwords_numsaved" value="'.$numsaved.'" size="3" />'.
+                      '<input type="text" name="passwords_numsaved" value="'.$numsaved.'" size="3" .
+                      'onblur="javascript:warnIntPass(this);" />'.
                       '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
                       '</span></td></tr>';
     } else {
@@ -7135,16 +7137,22 @@
 }
 
 sub passwords_javascript {
-    my $intauthcheck = &mt('Warning: disallowing login for an authenticated user if the stored cost is less than the default will require a password reset by/for the user.');
-    my $intauthcost = &mt('Warning: bcrypt encryption cost for internal authentication must be an integer.');
-    &js_escape(\$intauthcheck);
-    &js_escape(\$intauthcost);
+    my %intalert = &Apache::lonlocal::texthash (
+        authcheck => 'Warning: disallowing login for an authenticated user if the stored cost is less than the default will require a password reset by/for the user.',
+        authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
+        passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
+        passmax => 'Warning: maximum password length must be a positive integer (or blank).',
+        passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
+        passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
+    );
+    &js_escape(\%intalert);
+    my $defmin = $Apache::lonnet::passwdmin;
     my $intauthjs = <<"ENDSCRIPT";
 
 function warnIntAuth(field) {
     if (field.name == 'intauth_check') {
         if (field.value == '2') {
-            alert('$intauthcheck');
+            alert('$intalert{authcheck}');
         }
     }
     if (field.name == 'intauth_cost') {
@@ -7152,7 +7160,60 @@
         if (field.value != '') {
             var regexdigit=/^\\d+\$/;
             if (!regexdigit.test(field.value)) {
-                alert('$intauthcost');
+                alert('$intalert{authcost}');
+            }
+        }
+    }
+    return;
+}
+
+function warnIntPass(field) {
+    field.value.replace(/^\s+/,'');
+    field.value.replace(/\s+\$/,'');
+    var regexdigit=/^\\d+\$/;
+    if (field.name == 'passwords_min') {
+        if (field.value == '') {
+            alert('$intalert{passmin}');
+            field.value = '$defmin';
+        } else {
+            if (!regexdigit.test(field.value)) {
+                alert('$intalert{passmin}');
+                field.value = '$defmin';
+            }
+            var minval = parseInt(field.value,10);
+            if (minval < $defmin) {
+                alert('$intalert{passmin}');
+                field.value = '$defmin';
+            }
+        }
+    } else {
+        if (field.value == '0') {
+            field.value = '';
+        }
+        if (field.value != '') {
+            if (field.name == 'passwords_expire') {
+                var regexpposnum=/^\\d+(|\\.\\d*)\$/;
+                if (!regexpposnum.test(field.value)) {
+                    alert('$intalert{passexp}');
+                    field.value = '';
+                } else {
+                    var expval = parseFloat(field.value);
+                    if (expval == 0) {
+                        alert('$intalert{passexp}');
+                        field.value = '';
+                    }
+                }
+            } else {
+                if (!regexdigit.test(field.value)) {
+                    if (field.name == 'passwords_max') {
+                        alert('$intalert{passmax}');
+                    } else {
+                        if (field.name == 'passwords_numsaved') {
+                            alert('$intalert{passnum}');
+                        }
+                    }
+                }
+                field.value = '';
             }
         }
     }
@@ -10575,8 +10636,8 @@
         'intauth_cost'   => 10,
         'intauth_check'  => 0,
         'intauth_switch' => 0,
-        'min'            => 7,
     );
+    $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
     foreach my $type (@oktypes) {
         $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
     }
@@ -10756,7 +10817,18 @@
     }
     foreach my $rule ('min','max','numsaved') {
         $env{'form.passwords_'.$rule} =~ s/^\s+|\s+$//g;
-        if ($env{'form.passwords_'.$rule} =~ /^\d+$/) {
+        my $ruleok;
+        if ($rule eq 'min') {
+            if ($env{'form.passwords_'.$rule} =~ /^\d+$/) {
+                if ($env{'form.passwords_'.$rule} >= $Apache::lonnet::passwdmin) {
+                    $ruleok = 1;
+                }
+            }
+        } elsif (($env{'form.passwords_'.$rule} =~ /^\d+$/) &&
+                 ($env{'form.passwords_'.$rule} ne '0')) {
+            $ruleok = 1;
+        }
+        if ($ruleok) {
             $newvalues{$rule} = $env{'form.passwords_'.$rule};
             if (exists($current{$rule})) {
                 if ($newvalues{$rule} ne $current{$rule}) {
@@ -10963,7 +11035,8 @@
                             if ($confighash{'passwords'}{$rule} eq '') {
                                 if ($rule eq 'min') {
                                     $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
-                                                   ' '.&mt('Default of 7 will be used').'</li>';
+                                                   ' '.&mt('Default of [_1] will be used',
+                                                           $Apache::lonnet::passwdmin).'</li>';
                                 } else {
                                     $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
                                 }


More information about the LON-CAPA-cvs mailing list