Make password-reset process less confusing for users:
[plewww.git] / planetlab / persons / reset_password.php
1 <?php
2 //
3 // Reset password form
4 //
5 // Mark Huang <mlhuang@cs.princeton.edu>
6 // Copyright (C) 2007 The Trustees of Princeton University
7 //
8 // $Id$ $
9 //
10
11 // Get session and API handles
12 require_once 'plc_session.php';
13 global $plc, $api, $adm;
14
15 // Print header
16 require_once 'plc_drupal.php';
17 include 'plc_header.php';
18
19 // Only display dialogs if the user is not logged in.
20 if ( !$plc->person) {
21
22     if (!empty($_REQUEST['id']) && !empty($_REQUEST['key'])) {
23       $person_id = intval($_REQUEST['id']);
24       drupal_set_title('Password Reset: Confirmed');
25       if ($adm->ResetPassword($person_id, $_REQUEST['key']) != 1) {
26         print '<div class="messages error">' . $adm->error() . '.</div>';
27       } else {
28         drupal_set_html_head("<meta http-equiv=\"refresh\" content=\"60; URL=/\"");
29
30         print '<div class="messages status">';
31         print "Success!  We've sent you another e-mail with your new temporary password. <br/>"; 
32         print "You can login using this temporaray password.  <br/>"; 
33         print "Please change it once you login by visiting 'My Account' and updating your password. ";
34         print '</div>';
35       }
36     } elseif (!empty($_REQUEST['email'])) {
37       drupal_set_title('Password Reset: Request Sent');
38       if ($adm->ResetPassword($_REQUEST['email']) != 1) {
39         print '<div class="messages error">' . $adm->error() . '.</div>';
40       } else {
41         print '<div class="messages status">';
42         print "We've sent an e-mail to " . $_REQUEST['email'] . " that will allow you to confirm the password reset. <br/>";
43         print "Please check your email now and follow the link contained there to reset your password. ";
44         print '</div>';
45       }
46     } else {
47
48         drupal_set_title('Password Reset');
49         $self = $_SERVER['PHP_SELF'];
50         if (!empty($_SERVER['QUERY_STRING'])) {
51           $self .= "?" . $_SERVER['QUERY_STRING'];
52         }
53
54         // XXX Use our own stylesheet instead of drupal.css
55         print <<<EOF
56 <div class="content">
57 <form action="$self" method="post">
58
59 <table border="0" cellpadding="0" cellspacing="0" id="content">
60   <tr>
61     <td>
62       <div class="form-item">
63         E-mail: <span class="form-required" title="This field is required.">*</span></label>
64         <input type="text" maxlength="60" name="email" id="edit-name" size="30" value="" class="form-text required" />
65       </div>
66       <input type="submit" name="op" value="Reset password"  class="form-submit" />
67     </td>
68   </tr>
69 </table>
70
71 </form>
72 </div>
73 EOF;
74
75     }
76 }
77
78 include 'plc_footer.php';
79
80 ?>