--- loncom/interface/resetpw.pm 2006/10/23 21:40:31 1.2 +++ loncom/interface/resetpw.pm 2006/11/10 02:03:49 1.3 @@ -66,23 +66,36 @@ sub handler { my $domdesc = $Apache::lonnet::domaindescription{$udom}; my $authtype = &Apache::lonnet::queryauthenticate($uname,$udom); if ($authtype =~ /^internal/) { - my %userinfo = + my $useremail = $env{'form.useremail'}; + if ($useremail !~ /^[^\@]+\@[^\@]+\.[^\@\.]+$/) { + $output = &invalid_state('baduseremail',$domdesc, + $contact_name,$contact_email); + } else { + my %userinfo = &Apache::lonnet::get('environment',\@emailtypes,$udom,$uname); - my $email = ''; - my $emailtarget; - foreach my $type (@emailtypes) { - $email = $userinfo{$type}; - if ($email =~ /[^\@]+\@[^\@]+/) { - $emailtarget = $type; - last; + my $email = ''; + my $emailtarget; + foreach my $type (@emailtypes) { + $email = $userinfo{$type}; + if ($email =~ /[^\@]+\@[^\@]+/) { + $emailtarget = $type; + last; + } + } + if ($email =~ /^[^\@]+\@[^\@]+\.[^\@\.]+$/) { + if ($useremail eq $email) { + $output = &send_token($uname,$udom,$email,$server, + $domdesc,$contact_name, + $contact_email); + } else { + $output = &invalid_state('mismatch',$domdesc, + $contact_name, + $contact_email); + } + } else { + $output = &invalid_state('missing',$domdesc, + $contact_name,$contact_email); } - } - if ($email =~ /[^\@]+\@[^\@]+/) { - $output = &send_token($uname,$udom,$email,$server,$domdesc, - $contact_name,$contact_email); - } else { - $output = &invalid_state('missing',$domdesc, - $contact_name,$contact_email); } } elsif ($authtype =~ /^(krb|unix|local)/) { $output = &invalid_state('authentication',$domdesc, @@ -104,6 +117,7 @@ sub get_uname { my %lt = &Apache::lonlocal::texthash( unam => 'username', udom => 'domain', + uemail => 'Email address in LON-CAPA', proc => 'Proceed'); my $msg = &mt('If you use the same account for other campus services besides LON-CAPA, (e.g., e-mail, course registration, etc.), a separate centrally managed mechanism likely exists to reset a password. However, if your account is used for just LON-CAPA access you will probably be able to reset a password from this page.'); @@ -118,6 +132,8 @@ sub get_uname { |; $msg .= &Apache::loncommon::select_dom_form($defdom,'udom'); $msg .= qq| +$lt{'uemail'}: +
@@ -129,7 +145,6 @@ sub get_uname { sub send_token { my ($uname,$udom,$email,$server,$domdesc,$contact_name, $contact_email) = @_; -# my $token = MD5->hexhash(MD5->hexhash(time.{}.rand().$$)); my $msg = &mt('Thank you for your request to reset the password for your LON-CAPA account.').'

'; @@ -142,8 +157,8 @@ sub send_token { 'email' => $email, 'temppasswd' => $temppasswd); - my $token = &Apache::lonnet::tmpput(\%info,$server); - if ($token !~ /^error/) { + my $token = &Apache::lonnet::tmpput(\%info,$server,'resetpw'); + if ($token !~ /^error/ && $token ne 'no_such_host') { my $esc_token = &escape($token); my $mailmsg = "A request was submitted on ".localtime(time)." for a reset of the ". "password for your LON-CAPA account.". @@ -152,9 +167,9 @@ sub send_token { my $result = &send_mail($domdesc,$email,$mailmsg,$contact_name, $contact_email); if ($result eq 'ok') { - $msg .= &mt("An e-mail message sent to $email includes the web address for the link you should use to complete the reset process.

The link included in the message will be valid for the next two hours."); + $msg .= &mt("An e-mail message sent to the e-mail address associated with your LON-CAPA account includes the web address for the link you should use to complete the reset process.

The link included in the message will be valid for the next two hours."); } else { - $msg .= ("An error occurred when sending e-mail to $email with information about the reset process. Please contact the $contact_name ($contact_email) for assistance."); + $msg .= ("An error occurred when sending a message to the e-mail address associated with your LON-CAPA account. Please contact the $contact_name ($contact_email) for assistance."); } } else { $msg .= &mt("An error occurred creating a token required for the password reset process. Please contact the $contact_name ($contact_email) for assistance."); @@ -187,16 +202,20 @@ sub invalid_state { if ($error eq 'invalid') { $msg = &mt('The username you provided was not verified as a valid username in the LON-CAPA system for the [_1] domain.',$domdesc).&mt(' Please go back and try again.'); } else { - if ($error eq 'missing') { + if ($error eq 'baduseremail') { + $msg = &mt('The e-mail address you provided does not appear to be a valid address.'); + } elsif ($error eq 'mismatch') { + $msg = &mt('The e-mail address you provided does not match the address recorded in the LON-CAPA system for the username and domain you provided.'); + } elsif ($error eq 'missing') { $msg = &mt('A valid e-mail address was not located in the LON-CAPA system for the username and domain you provided.'); } elsif ($error eq 'authentication') { $msg = &mt('The username you provided uses an authentication type which can not be reset directly via LON-CAPA.'); } if ($contact_email ne '') { my $escuri = &HTML::Entities::encode('/adm/resetpw','&<>"'); - $msg .= &mt(' You may wish to contact the LON-CAPA helpdesk for the [_2] domain.',$escuri,$domdesc); + $msg .= '
'.&mt(' You may wish to contact the LON-CAPA helpdesk for the [_2] domain.',$escuri,$domdesc); } else { - $msg .= &mt(' You may wish to send an e-mail to the server administrator: [_1] for the [_2] domain.',Apache::lonnet::perlvar{'AdminEmail'},$domdesc); + $msg .= '
'.&mt(' You may wish to send an e-mail to the server administrator: [_1] for the [_2] domain.',Apache::lonnet::perlvar{'AdminEmail'},$domdesc); } } return $msg; @@ -214,7 +233,7 @@ sub reset_passwd { if (($data{'time'} =~ /^\d+$/) && ($data{'username'} ne '') && ($data{'domain'} ne '') && - ($data{'email'} =~ /^[^\@]+\@[^\@]+$/) && + ($data{'email'} =~ /^[^\@]+\@[^\@]+\.[^\@\.]+$/) && ($data{'temppasswd'} =~/^\w+$/)) { my $reqtime = localtime($data{'time'}); if ($now - $data{'time'} < 7200) {