--- loncom/interface/lonpreferences.pm 2019/04/24 21:15:48 1.231 +++ loncom/interface/lonpreferences.pm 2025/03/07 02:13:40 1.248 @@ -1,7 +1,7 @@ # The LearningOnline Network # Preferences # -# $Id: lonpreferences.pm,v 1.231 2019/04/24 21:15:48 raeburn Exp $ +# $Id: lonpreferences.pm,v 1.248 2025/03/07 02:13:40 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -31,7 +31,6 @@ package Apache::lonpreferences; use strict; -use LONCAPA; use Apache::Constants qw(:common); use Apache::File; use Apache::loncommon(); @@ -40,6 +39,7 @@ use Apache::lonlocal; use Apache::lonnet; use LONCAPA::lonauthcgi(); use LONCAPA(); +use DateTime::TimeZone(); ################################################################ # Handler subroutines # @@ -103,16 +103,17 @@ sub languagechanger { { href => '/adm/preferences?action=changelanguages', text => 'Change Language'}); $r->print(Apache::loncommon::start_page('Content Display Settings')); - $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Language')); + $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Language'). + '
'.$blocktext.'
'); - return; - } + my ($r,$caller,$mailtoken,$timelimit,$extrafields,$ended) = @_; + my ($user,$domain,$homeserver,$clientip); if ($caller eq 'reset_by_email') { $user = $env{'form.uname'}; $domain = $env{'form.udom'}; @@ -1538,20 +1679,31 @@ sub verify_and_change_password { if ($homeserver eq 'no_host') { &passwordchanger($r,"\n". &mt("Invalid username and/or domain")."\n
", - $caller,$mailtoken); - return 1; + $caller,$mailtoken,$timelimit,$extrafields); + return 'no_host'; } } else { &passwordchanger($r,"\n". &mt("Username and domain were blank")."\n
", - $caller,$mailtoken); - return 1; + $caller,$mailtoken,$timelimit,$extrafields); + return 'missingdata'; } } else { $user = $env{'user.name'}; $domain = $env{'user.domain'}; $homeserver = $env{'user.home'}; } + $clientip = &Apache::lonnet::get_requestor_ip($r); + my ($blocked,$blocktext) = + &Apache::loncommon::blocking_status('passwd',$clientip,$user,$domain); + if ($blocked) { + $r->print(''.$blocktext.'
'); + if ($caller eq 'reset_by_email') { + return 'blocked'; + } else { + return; + } + } my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain); # Check for authentication types that allow changing of the password. if ($currentauth !~ /^(unix|internal):/) { @@ -1559,8 +1711,8 @@ sub verify_and_change_password { &passwordchanger($r,"\n". &mt("Authentication type for this user can not be changed by this mechanism"). "\n
", - $caller,$mailtoken); - return 1; + $caller,$mailtoken,$timelimit,$extrafields); + return 'otherauth'; } else { return; } @@ -1576,8 +1728,12 @@ sub verify_and_change_password { defined($newpass2) ){ &passwordchanger($r,"\n". &mt("One or more password fields were blank"). - "\n
",$caller,$mailtoken); - return; + "\n",$caller,$mailtoken,$timelimit,$extrafields); + if ($caller eq 'reset_by_email') { + return 'missingdata'; + } else { + return; + } } # Get the keys my $lonhost = $r->dir_config('lonHostID'); @@ -1595,7 +1751,11 @@ sub verify_and_change_password { ENDERROR # Probably should log an error here - return 1; + if ($caller eq 'reset_by_email') { + return 'internalerror'; + } else { + return; + } } my ($ckey,$n1key,$n2key)=split(/&/,$tmpinfo); # @@ -1609,101 +1769,52 @@ ENDERROR &passwordchanger($r, ''. &mt('Could not verify current authentication.').' '. - &mt('Please try again.').'',$caller,$mailtoken); - return 1; + &mt('Please try again.').'',$caller,$mailtoken,$timelimit,$extrafields); + return 'emptydata'; } if ($currentpass ne $data{'temppasswd'}) { &passwordchanger($r, ''. &mt('Could not verify current authentication.').' '. - &mt('Please try again.').'',$caller,$mailtoken); - return 1; + &mt('Please try again.').'',$caller,$mailtoken,$timelimit,$extrafields); + return 'missingtemp'; } } if ($newpass1 ne $newpass2) { &passwordchanger($r, ''. &mt('The new passwords you entered do not match.').' '. - &mt('Please try again.').'',$caller,$mailtoken); - return 1; + &mt('Please try again.').'',$caller,$mailtoken,$timelimit,$extrafields); + if ($caller eq 'reset_by_email') { + return 'mismatch'; + } else { + return; + } } if ($currentauth eq 'unix:') { if (length($newpass1) < 7) { &passwordchanger($r, ''. &mt('Passwords must be a minimum of 7 characters long.').' '. - &mt('Please try again.').'',$caller,$mailtoken); - return 1; - } - } else { - my %passwdconf = &Apache::lonnet::get_passwdconf($domain); - my ($min,$max,@chars,@brokerule); - if (ref($passwdconf{'chars'}) eq 'ARRAY') { - if ($passwdconf{'min'} =~ /^\d+$/) { - $min = $passwdconf{'min'}; - } - if ($passwdconf{'max'} =~ /^\d+$/) { - $max = $passwdconf{'max'}; - } - @chars = @{$passwdconf{'chars'}}; - } else { - $min = 7; - } - if (($min) && (length($newpass1) < $min)) { - push(@brokerule,'min'); - } - if (($max) && (length($newpass1) > $max)) { - push(@brokerule,'max'); - } - if (@chars) { - my %rules; - map { $rules{$_} = 1; } @chars; - if ($rules{'uc'}) { - unless ($newpass1 =~ /[A-Z]/) { - push(@brokerule,'uc'); - } - } - if ($rules{'lc'}) { - unless ($newpass1 =~ /a-z/) { - push(@brokerule,'lc'); - } - } - if ($rules{'num'}) { - unless ($newpass1 =~ /\d/) { - push(@brokerule,'num'); - } - } - if ($rules{'spec'}) { - unless ($newpass1 =~ /[!"#$%&'()*+,\-.\/:;<=>?@[\\\]^_`{|}~]/) { - push(@brokerule,'spec'); - } + &mt('Please try again.').'',$caller,$mailtoken,$timelimit,$extrafields); + if ($caller eq 'reset_by_email') { + return 'length'; + } else { + return; } } - if (@brokerule) { - my %rulenames = &Apache::lonlocal::texthash( - uc => 'At least one upper case letter', - lc => 'At least one lower case letter', - num => 'At least one number', - spec => 'At least one non-alphanumeric', - ); - $rulenames{'uc'} .= ': ABCDEFGHIJKLMNOPQRSTUVWXYZ'; - $rulenames{'lc'} .= ': abcdefghijklmnopqrstuvwxyz'; - $rulenames{'num'} .= ': 0123456789'; - $rulenames{'spec'} .= ': !"\#$%&\'()*+,-./:;<=>?@[\]^_\`{|}~'; - $rulenames{'min'} = &mt('Minimum password length: [_1]',$min); - $rulenames{'max'} = &mt('Maximum password length: [_1]',$max); - my $warning = &mt('Password did not satisfy the following:').''.$lt{'thde'}.'
'); - $r->print(&Apache::loncommon::start_data_table()); + $r->print(&Apache::loncommon::start_data_table(). + &Apache::loncommon::start_data_table_header_row()); $r->print(<<"END"); -$lt{'curd'}: $domdefdisplay
++ +
++ +