[LON-CAPA-cvs] cvs: loncom / lond /interface lonpreferences.pm resetpw.pm /lonnet/perl lonnet.pm

raeburn raeburn@source.lon-capa.org
Thu, 08 Oct 2009 19:54:37 -0000


This is a MIME encoded message

--raeburn1255031677
Content-Type: text/plain

raeburn		Thu Oct  8 19:54:37 2009 EDT

  Modified files:              
    /loncom	lond 
    /loncom/lonnet/perl	lonnet.pm 
    /loncom/interface	lonpreferences.pm resetpw.pm 
  Log:
  - Feedback to point to user's homeserver if reset fails.
  
  
--raeburn1255031677
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20091008195437.txt"

Index: loncom/lond
diff -u loncom/lond:1.427 loncom/lond:1.428
--- loncom/lond:1.427	Mon Sep 28 19:13:32 2009
+++ loncom/lond	Thu Oct  8 19:54:26 2009
@@ -2,7 +2,7 @@
 # The LearningOnline Network
 # lond "LON Daemon" Server (port "LOND" 5663)
 #
-# $Id: lond,v 1.427 2009/09/28 19:13:32 raeburn Exp $
+# $Id: lond,v 1.428 2009/10/08 19:54:26 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -59,7 +59,7 @@
 my $status='';
 my $lastlog='';
 
-my $VERSION='$Revision: 1.427 $'; #' stupid emacs
+my $VERSION='$Revision: 1.428 $'; #' stupid emacs
 my $remoteVERSION;
 my $currenthostid="default";
 my $currentdomainid;
@@ -1815,8 +1815,9 @@
     #  npass - New password.
     #  context - Context in which this was called 
     #            (preferences or reset_by_email).
+    #  lonhost - HostID of server where request originated 
    
-    my ($udom,$uname,$upass,$npass,$context)=split(/:/,$tail);
+    my ($udom,$uname,$upass,$npass,$context,$lonhost)=split(/:/,$tail);
 
     $upass=&unescape($upass);
     $npass=&unescape($npass);
@@ -1825,9 +1826,13 @@
     # First require that the user can be authenticated with their
     # old password unless context was 'reset_by_email':
     
-    my $validated;
+    my ($validated,$failure);
     if ($context eq 'reset_by_email') {
-        $validated = 1;
+        if ($lonhost eq '') {
+            $failure = 'invalid_client';
+        } else {
+            $validated = 1;
+        }
     } else {
         $validated = &validate_user($udom, $uname, $upass);
     }
@@ -1841,8 +1846,11 @@
 	    $salt=substr($salt,6,2);
 	    my $ncpass=crypt($npass,$salt);
 	    if(&rewrite_password_file($udom, $uname, "internal:$ncpass")) {
-		&logthis("Result of password change for "
-			 ."$uname: pwchange_success");
+		my $msg="Result of password change for $uname: pwchange_success";
+                if ($lonhost) {
+                    $msg .= " - request originated from: $lonhost";
+                }
+                &logthis($msg);
 		&Reply($client, "ok\n", $userinput);
 	    } else {
 		&logthis("Unable to open $uname passwd "               
@@ -1863,7 +1871,10 @@
 	}  
 	
     } else {
-	&Failure( $client, "non_authorized\n", $userinput);
+	if ($failure eq '') {
+	    $failure = 'non_authorized';
+	}
+	&Failure( $client, "$failure\n", $userinput);
     }
 
     return 1;
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1029 loncom/lonnet/perl/lonnet.pm:1.1030
--- loncom/lonnet/perl/lonnet.pm:1.1029	Mon Sep 28 19:13:37 2009
+++ loncom/lonnet/perl/lonnet.pm	Thu Oct  8 19:54:31 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.1029 2009/09/28 19:13:37 raeburn Exp $
+# $Id: lonnet.pm,v 1.1030 2009/10/08 19:54:31 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -785,7 +785,8 @@
     my ($uname,$udom,$currentpass,$newpass,$server,$context)=@_;
     $currentpass = &escape($currentpass);
     $newpass     = &escape($newpass);
-    my $answer = reply("encrypt:passwd:$udom:$uname:$currentpass:$newpass:$context",
+    my $lonhost = $perlvar{'lonHostID'};
+    my $answer = reply("encrypt:passwd:$udom:$uname:$currentpass:$newpass:$context:$lonhost",
 		       $server);
     if (! $answer) {
 	&logthis("No reply on password change request to $server ".
@@ -810,6 +811,9 @@
     } elsif ($answer =~ "^refused") {
 	&logthis("$server refused to change $uname in $udom password because ".
 		 "it was sent an unencrypted request to change the password.");
+    } elsif ($answer =~ "invalid_client") {
+        &logthis("$server refused to change $uname in $udom password because ".
+                 "it was a reset by e-mail originating from an invalid server.");
     }
     return $answer;
 }
Index: loncom/interface/lonpreferences.pm
diff -u loncom/interface/lonpreferences.pm:1.172 loncom/interface/lonpreferences.pm:1.173
--- loncom/interface/lonpreferences.pm:1.172	Thu Oct  1 22:41:55 2009
+++ loncom/interface/lonpreferences.pm	Thu Oct  8 19:54:37 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Preferences
 #
-# $Id: lonpreferences.pm,v 1.172 2009/10/01 22:41:55 raeburn Exp $
+# $Id: lonpreferences.pm,v 1.173 2009/10/08 19:54:37 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1338,6 +1338,8 @@
                    this.document.client.elements.uname.value;
         this.document.pserver.elements.udom.value =
                    this.document.client.elements.udom.options[this.document.client.elements.udom.selectedIndex].value;
+        this.document.pserver.elements.email.value =
+                   this.document.client.elements.email.value;
 |;
     }
     $ output .= qq|
@@ -1422,6 +1424,7 @@
 <input type="hidden" name="token"   value="$mailtoken" />
 <input type="hidden" name="uname"   value="" />
 <input type="hidden" name="udom"   value="" />
+<input type="hidden" name="email"   value="" />
 
 |;
     }
@@ -1574,13 +1577,18 @@
         }
     } else {
 	# error error: run in circles, scream and shout
-        $message = &Apache::lonhtmlcommon::confirm_success(
-          &mt("The password for user [_1] was not changed.",'<i>'.$user.'</i>').' '.&mt('Please make sure your old password was entered correctly.'),1);
-        unless ($caller eq 'reset_by_email') {
+        if ($caller eq 'reset_by_email') {
+            if (!$result) {
+                return 1;
+            } else {
+                return $result;
+            }
+        } else {
+            $message = &Apache::lonhtmlcommon::confirm_success(
+                &mt("The password for user [_1] was not changed.",'<i>'.$user.'</i>').' '.&mt('Please make sure your old password was entered correctly.'),1);
             $message=&Apache::loncommon::confirmwrapper($message);
             &print_main_menu($r, $message);
         }
-        return 1;
     }
     return;
 }
Index: loncom/interface/resetpw.pm
diff -u loncom/interface/resetpw.pm:1.19 loncom/interface/resetpw.pm:1.20
--- loncom/interface/resetpw.pm:1.19	Thu Oct  1 17:22:13 2009
+++ loncom/interface/resetpw.pm	Thu Oct  8 19:54:37 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Allow access to password changing via a token sent to user's e-mail. 
 #
-# $Id: resetpw.pm,v 1.19 2009/10/01 17:22:13 raeburn Exp $
+# $Id: resetpw.pm,v 1.20 2009/10/08 19:54:37 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -271,10 +271,24 @@
                     }
                     $msg .= '<br /><br />'
                            .'<a href="/adm/login">'.&mt('Go to the login page').'</a>.';
+                } elsif ($change_failed eq 'invalid_client') {
+                    my $homeserver = &Apache::lonnet::homeserver($data{'username'},$data{'domain'});
+                    if ($homeserver eq 'no_host') {
+                        $msg .= &generic_failure_msg($contact_name,$contact_email);
+                    } else {
+                        my $protocol = $Apache::lonnet::protocol{$homeserver};
+                        $protocol = 'http' if ($protocol ne 'https');
+                        my $url = $protocol.'://'.&Apache::lonnet::hostname($homeserver).
+                                  '/adm/resetpw';
+                        my ($opentag,$closetag);
+                        if ($url) {
+                           $opentag = '<a href="'.$url.'">';
+                           $closetag = '</a>';
+                        }
+                        $msg .= &mt('A problem occurred when attempting to reset the password for your account. Please try again from your [_1]home server[_2].',$opentag,$closetag);
+                    }
                 } else {
-                    $msg .= &mt('A problem occurred when attempting to reset the password for your account. Please contact the [_1] - ([_2]) for assistance.'
-                               ,$contact_name
-                               ,'<a href="mailto:'.$contact_email.'">'.$contact_email.'</a>');
+                    $msg .= &generic_failure_msg($contact_name,$contact_email);
                 }
             } else {
                 $r->print(&mt('The token included in an e-mail sent to you [_1] has been verified, so you may now proceed to reset the password for your LON-CAPA account.',$reqtime).'<br /><br />');
@@ -292,6 +306,12 @@
     return $msg;
 }
 
+sub generic_failure_msg {
+    my ($contact_name,$contact_email) = @_;
+    return &mt('A problem occurred when attempting to reset the password for your account. Please contact the [_1] - ([_2]) for assistance.',
+              $contact_name,'<a href="mailto:'.$contact_email.'">'.$contact_email.'</a>');
+}
+
 sub create_passwd {
     my $passwd = '';
     my @letts = ("a".."z");

--raeburn1255031677--