Diff for /loncom/interface/resetpw.pm between versions 1.2 and 1.3

version 1.2, 2006/10/23 21:40:31 version 1.3, 2006/11/10 02:03:49
Line 66  sub handler { Line 66  sub handler {
         my $domdesc = $Apache::lonnet::domaindescription{$udom};          my $domdesc = $Apache::lonnet::domaindescription{$udom};
         my $authtype = &Apache::lonnet::queryauthenticate($uname,$udom);          my $authtype = &Apache::lonnet::queryauthenticate($uname,$udom);
         if ($authtype =~ /^internal/) {          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);              &Apache::lonnet::get('environment',\@emailtypes,$udom,$uname);
             my $email = '';                  my $email = '';
             my $emailtarget;                  my $emailtarget;
             foreach my $type (@emailtypes) {                  foreach my $type (@emailtypes) {
                 $email = $userinfo{$type};                      $email = $userinfo{$type};
                 if ($email =~ /[^\@]+\@[^\@]+/) {                      if ($email =~ /[^\@]+\@[^\@]+/) {
                     $emailtarget = $type;                           $emailtarget = $type; 
                     last;                          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)/) {           } elsif ($authtype =~ /^(krb|unix|local)/) { 
             $output = &invalid_state('authentication',$domdesc,              $output = &invalid_state('authentication',$domdesc,
Line 104  sub get_uname { Line 117  sub get_uname {
     my %lt = &Apache::lonlocal::texthash(      my %lt = &Apache::lonlocal::texthash(
                                          unam => 'username',                                           unam => 'username',
                                          udom => 'domain',                                           udom => 'domain',
                                            uemail => 'Email address in LON-CAPA',
                                          proc => 'Proceed');                                           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.');      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.');
Line 118  sub get_uname { Line 132  sub get_uname {
     <td>|;      <td>|;
     $msg .= &Apache::loncommon::select_dom_form($defdom,'udom');      $msg .= &Apache::loncommon::select_dom_form($defdom,'udom');
     $msg .= qq|</td></tr>      $msg .= qq|</td></tr>
   <tr><td align="left">$lt{'uemail'}:                             </td>
       <td><input type="text" name="useremail" size="20"  /></td></tr>
 <tr><td colspan="2" align="left"><br />  <tr><td colspan="2" align="left"><br />
     <input type="button" value="$lt{'proc'}" onClick="document.forgotpw.submit()"></td></tr>      <input type="button" value="$lt{'proc'}" onClick="document.forgotpw.submit()"></td></tr>
 </table>  </table>
Line 129  sub get_uname { Line 145  sub get_uname {
 sub send_token {  sub send_token {
     my ($uname,$udom,$email,$server,$domdesc,$contact_name,      my ($uname,$udom,$email,$server,$domdesc,$contact_name,
         $contact_email) = @_;          $contact_email) = @_;
 #    my $token = MD5->hexhash(MD5->hexhash(time.{}.rand().$$));  
     my $msg = &mt('Thank you for your request to reset the password for your      my $msg = &mt('Thank you for your request to reset the password for your
         LON-CAPA account.').'<br /><br />';          LON-CAPA account.').'<br /><br />';
   
Line 142  sub send_token { Line 157  sub send_token {
  'email'      => $email,   'email'      => $email,
  'temppasswd' => $temppasswd);   'temppasswd' => $temppasswd);
   
     my $token = &Apache::lonnet::tmpput(\%info,$server);      my $token = &Apache::lonnet::tmpput(\%info,$server,'resetpw');
     if ($token !~ /^error/) {      if ($token !~ /^error/ && $token ne 'no_such_host') {
         my $esc_token = &escape($token);          my $esc_token = &escape($token);
         my $mailmsg = "A request was submitted on ".localtime(time)." for a reset of the ".          my $mailmsg = "A request was submitted on ".localtime(time)." for a reset of the ".
              "password for your LON-CAPA account.".               "password for your LON-CAPA account.".
Line 152  sub send_token { Line 167  sub send_token {
         my $result = &send_mail($domdesc,$email,$mailmsg,$contact_name,          my $result = &send_mail($domdesc,$email,$mailmsg,$contact_name,
                                 $contact_email);                                  $contact_email);
         if ($result eq 'ok') {          if ($result eq 'ok') {
             $msg .= &mt("An e-mail message sent to <b>$email</b> includes the web address for the link you should use to complete the reset process.<br /><br />The link included in the message will be valid for the next <b>two</b> 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.<br /><br />The link included in the message will be valid for the next <b>two</b> hours.");
         } else {          } 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 {      } else {
         $msg .= &mt("An error occurred creating a token required for the password reset process. Please contact the $contact_name ($contact_email) for assistance.");          $msg .= &mt("An error occurred creating a token required for the password reset process. Please contact the $contact_name ($contact_email) for assistance.");
Line 187  sub invalid_state { Line 202  sub invalid_state {
     if ($error eq 'invalid') {      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 <a href="javascript:history.go(-1)"><u>go back</u></a> and try again.');          $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 <a href="javascript:history.go(-1)"><u>go back</u></a> and try again.');
     } else {      } 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.');              $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') {          } elsif ($error eq 'authentication') {
             $msg = &mt('The username you provided uses an authentication type which can not be reset directly via LON-CAPA.');              $msg = &mt('The username you provided uses an authentication type which can not be reset directly via LON-CAPA.');
         }          }
         if ($contact_email ne '') {          if ($contact_email ne '') {
             my $escuri = &HTML::Entities::encode('/adm/resetpw','&<>"');              my $escuri = &HTML::Entities::encode('/adm/resetpw','&<>"');
             $msg .= &mt(' You may wish to contact the <a href="/adm/helpdesk?origurl=[_1]">LON-CAPA helpdesk</a> for the [_2] domain.',$escuri,$domdesc);              $msg .= '<br />'.&mt(' You may wish to contact the <a href="/adm/helpdesk?origurl=[_1]">LON-CAPA helpdesk</a> for the [_2] domain.',$escuri,$domdesc);
         } else {          } 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 .= '<br />'.&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;      return $msg;
Line 214  sub reset_passwd { Line 233  sub reset_passwd {
     if (($data{'time'} =~ /^\d+$/) &&       if (($data{'time'} =~ /^\d+$/) && 
         ($data{'username'} ne '') &&           ($data{'username'} ne '') && 
         ($data{'domain'} ne '') &&           ($data{'domain'} ne '') && 
         ($data{'email'}  =~ /^[^\@]+\@[^\@]+$/) &&           ($data{'email'}  =~ /^[^\@]+\@[^\@]+\.[^\@\.]+$/) && 
         ($data{'temppasswd'} =~/^\w+$/)) {          ($data{'temppasswd'} =~/^\w+$/)) {
         my $reqtime = localtime($data{'time'});          my $reqtime = localtime($data{'time'});
         if ($now - $data{'time'} < 7200) {          if ($now - $data{'time'} < 7200) {

Removed from v.1.2  
changed lines
  Added in v.1.3


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>