[LON-CAPA-cvs] cvs: loncom /interface resetpw.pm

raeburn raeburn at source.lon-capa.org
Sat Oct 29 21:45:31 EDT 2016


raeburn		Sun Oct 30 01:45:31 2016 EDT

  Modified files:              
    /loncom/interface	resetpw.pm 
  Log:
  - Ensure header is sent before body.
  
  
Index: loncom/interface/resetpw.pm
diff -u loncom/interface/resetpw.pm:1.38 loncom/interface/resetpw.pm:1.39
--- loncom/interface/resetpw.pm:1.38	Mon Sep 12 16:02:16 2016
+++ loncom/interface/resetpw.pm	Sun Oct 30 01:45:31 2016
@@ -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.38 2016/09/12 16:02:16 raeburn Exp $
+# $Id: resetpw.pm,v 1.39 2016/10/30 01:45:31 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -196,7 +196,10 @@
                  '<h2>'.&mt('Reset forgotten LON-CAPA password').'</h2>';
     my $output;
     if ($token) {
-        $output = &reset_passwd($r,$token,$contact_name,$contact_email);
+        $r->print($header);
+        &reset_passwd($r,$token,$contact_name,$contact_email);
+        $r->print(&Apache::loncommon::end_page());
+        return OK;
     } elsif ($udom) {
         if (!$domdesc) {
             $output = &invalid_state('baddomain',$domdesc,
@@ -423,13 +426,13 @@
 
 sub reset_passwd {
     my ($r,$token,$contact_name,$contact_email) = @_;
-    my $msg;
     my %data = &Apache::lonnet::tmpget($token);
     my $now = time;
     if (keys(%data) == 0) {
-        $msg = &mt('Sorry, the URL you provided to complete the reset of your password was invalid. Either the token included in the URL has been deleted or the URL you provided was invalid. Please submit a [_1]new request[_2] for a password reset, and follow the link to the new URL included in the e-mail that will be sent to you, to allow you to enter a new password.'
-                  ,'<a href="/adm/resetpw">','</a>');
-        return $msg;
+        $r->print(&mt('Sorry, the URL you provided to complete the reset of your password was invalid. Either the token included in the URL has been deleted or the URL you provided was invalid. Please submit a [_1]new request[_2] for a password reset, and follow the link to the new URL included in the e-mail that will be sent to you, to allow you to enter a new password.'
+                  ,'<a href="/adm/resetpw">','</a>')
+        );
+        return;
     }
     if (($data{'time'} =~ /^\d+$/) && 
         ($data{'username'} ne '') && 
@@ -440,13 +443,13 @@
         my ($blocked,$blocktext) =
             &Apache::loncommon::blocking_status('passwd',$data{'username'},$data{'domain'});
         if ($blocked) {
-            $msg = '<p class="LC_warning">'.$blocktext.'</p>';
-            return $msg;
+            $r->print('<p class="LC_warning">'.$blocktext.'</p>');
+            return;
         } elsif ($now - $data{'time'} < 7200) {
             if ($env{'form.action'} eq 'verify_and_change_pass') {
                 unless (($env{'form.uname'} eq $data{'username'}) && ($env{'form.udom'} eq $data{'domain'}) && ($env{'form.email'} eq $data{'email'})) {
-                    $msg = &generic_failure_msg($contact_name,$contact_email);
-                    return $msg;
+                    $r->print(&generic_failure_msg($contact_name,$contact_email));
+                    return;
                 }
                 my $change_failed = 
 		    &Apache::lonpreferences::verify_and_change_password($r,'reset_by_email',$token);
@@ -472,14 +475,15 @@
                                    .' confirming setting of your new password.'
                                     ,'<span class="LC_filename">'.$data{'email'}.'</span>'),1);
                     }
-                    $msg .=
+                    $r->print(
                         &Apache::loncommon::confirmwrapper($confirm_msg)
                        .&Apache::lonhtmlcommon::actionbox([
-                            '<a href="/adm/login">'.&mt('Go to the login page').'</a>']);
+                            '<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);
+                        $r->print(&generic_failure_msg($contact_name,$contact_email));
                     } else {
                         my $protocol = $Apache::lonnet::protocol{$homeserver};
                         $protocol = 'http' if ($protocol ne 'https');
@@ -490,16 +494,17 @@
                            $opentag = '<a href="'.$url.'">';
                            $closetag = '</a>';
                         }
-                        $msg .=
+                        $r->print(
                             '<p class="LC_warning">'
                            .&mt('A problem occurred when attempting to reset'
                                .' the password for your account.'
                                .' Please try again from your [_1]home server[_2].'
                                 ,$opentag,$closetag)
-                           .'</p>';
+                           .'</p>'
+                        );
                     }
                 } else {
-                    $msg .= &generic_failure_msg($contact_name,$contact_email);
+                    $r->print(&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 />');
@@ -507,20 +512,22 @@
                 &Apache::lonpreferences::passwordchanger($r,'','reset_by_email',$token);
             }
         } else {
-            $msg =
+            $r->print(
                 '<p class="LC_warning">'
                .&mt('Sorry, the token generated when you requested a password reset has expired. Please submit a [_1]new request[_2], and follow the link to the web page included in the new e-mail that will be sent to you, to allow you to enter a new password.'
                     ,'<a href="/adm/resetpw">','</a>')
-               .'</p>';
+               .'</p>'
+            );
         }
     } else {
-        $msg .=
+        $r->print(
             '<p class="LC_warning">'
            .&mt('Sorry, the URL generated when you requested reset of your password contained incomplete information. Please submit a [_1]new request[_2] for a password reset, and use the new URL that will be sent to your e-mail account to complete the process.'
                 ,'<a href="/adm/resetpw">','</a>')
-           .'</p>';
+           .'</p>'
+        );
     }
-    return $msg;
+    return;
 }
 
 sub generic_failure_msg {




More information about the LON-CAPA-cvs mailing list