--- loncom/interface/lonpreferences.pm 2019/04/24 02:00:23 1.229 +++ 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.229 2019/04/24 02:00:23 raeburn Exp $ +# $Id: lonpreferences.pm,v 1.248 2025/03/07 02:13:40 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -27,13 +27,10 @@ # # This package uses the "londes.js" javascript code. # -# TODOs that have to be completed: -# interface with lonnet to change the password package Apache::lonpreferences; use strict; -use LONCAPA; use Apache::Constants qw(:common); use Apache::File; use Apache::loncommon(); @@ -42,6 +39,7 @@ use Apache::lonlocal; use Apache::lonnet; use LONCAPA::lonauthcgi(); use LONCAPA(); +use DateTime::TimeZone(); ################################################################ # Handler subroutines # @@ -105,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'}; @@ -1540,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):/) { @@ -1561,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; } @@ -1578,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'); @@ -1597,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); # @@ -1611,30 +1769,53 @@ 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 (length($newpass1) < 7) { - &passwordchanger($r, - ''. - &mt('Passwords must be a minimum of 7 characters long.').' '. - &mt('Please try again.').'',$caller,$mailtoken); - return 1; + 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,$timelimit,$extrafields); + if ($caller eq 'reset_by_email') { + return 'length'; + } else { + return; + } + } + } else { + my $warning = &Apache::loncommon::check_passwd_rules($domain,$newpass1); + if ($warning) { + &passwordchanger($r,''. + $warning. + &mt('Please try again.').'', + $caller,$mailtoken,$timelimit,$extrafields); + if ($caller eq 'reset_by_email') { + return 'rules'; + } else { + return; + } + } } # # Check for bad characters @@ -1653,8 +1834,12 @@ ENDERROR ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_\`abcdefghijklmnopqrstuvwxyz{|}~ ENDERROR - &passwordchanger($r,$errormessage,$caller,$mailtoken); - return 1; + &passwordchanger($r,$errormessage,$caller,$mailtoken,$timelimit,$extrafields); + if ($caller eq 'reset_by_email') { + return 'badchars'; + } else { + return; + } } # # Change the password (finally) @@ -1677,13 +1862,19 @@ ENDERROR # error error: run in circles, scream and shout if ($caller eq 'reset_by_email') { if (!$result) { - return 1; + return 'error'; } else { return $result; } } else { + my $feedback; + if ($result eq 'prioruse') { + $feedback = &mt('Please enter a password that you have not used recently.'); + } else { + $feedback = &mt('Please make sure your old password was entered correctly.'); + } $message = &Apache::lonhtmlcommon::confirm_success( - &mt("The password for user [_1] was not changed.",''.$user.'').' '.&mt('Please make sure your old password was entered correctly.'),1); + &mt("The password for user [_1] was not changed.",''.$user.'').' '.$feedback,1); $message=&Apache::loncommon::confirmwrapper($message); &print_main_menu($r, $message); if (ref($ended)) { @@ -1703,7 +1894,8 @@ sub discussionchanger { { href => '/adm/preferences?action=changediscussions', text => 'Change Discussion Preferences'}); $r->print(Apache::loncommon::start_page('Change Discussion Preferences')); - $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Discussion Preferences')); + $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Discussion Preferences'). + ''.$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
++ +
++ +