3 require_once('include/email.php');
4 require_once('include/enotify.php');
5 require_once('include/text.php');
7 function lostpass_post(App &$a) {
9 $loginame = notags(trim($_POST['login-name']));
13 $r = q("SELECT * FROM `user` WHERE ( `email` = '%s' OR `nickname` = '%s' ) AND `verified` = 1 AND `blocked` = 0 LIMIT 1",
18 if (! dbm::is_result($r)) {
19 notice( t('No valid account found.') . EOL);
24 $username = $r[0]['username'];
25 $email = $r[0]['email'];
27 $new_password = autoname(12) . mt_rand(100,9999);
28 $new_password_encoded = hash('whirlpool',$new_password);
30 $r = q("UPDATE `user` SET `pwdreset` = '%s' WHERE `uid` = %d",
31 dbesc($new_password_encoded),
35 info( t('Password reset request issued. Check your email.') . EOL);
38 $sitename = $a->config['sitename'];
39 $resetlink = App::get_baseurl() . '/lostpass?verify=' . $new_password;
41 $preamble = deindent(t('
43 A request was recently received at "%2$s" to reset your account
44 password. In order to confirm this request, please select the verification link
45 below or paste it into your web browser address bar.
47 If you did NOT request this change, please DO NOT follow the link
48 provided and ignore and/or delete this email.
50 Your password will not be changed unless we can verify that you
51 issued this request.'));
53 Follow this link to verify your identity:
57 You will then receive a follow-up message containing the new password.
58 You may change that password from your account settings page after logging in.
60 The login details are as follows:
65 $preamble = sprintf($preamble, $username, $sitename);
66 $body = sprintf($body, $resetlink, App::get_baseurl(), $email);
69 'type' => "SYSTEM_EMAIL",
71 'subject'=> sprintf( t('Password reset requested at %s'),$sitename),
72 'preamble'=> $preamble,
80 function lostpass_content(App &$a) {
83 if(x($_GET,'verify')) {
84 $verify = $_GET['verify'];
85 $hash = hash('whirlpool', $verify);
87 $r = q("SELECT * FROM `user` WHERE `pwdreset` = '%s' LIMIT 1",
90 if (! dbm::is_result($r)) {
91 $o = t("Request could not be verified. \x28You may have previously submitted it.\x29 Password reset failed.");
95 $username = $r[0]['username'];
96 $email = $r[0]['email'];
98 $new_password = autoname(6) . mt_rand(100,9999);
99 $new_password_encoded = hash('whirlpool',$new_password);
101 $r = q("UPDATE `user` SET `password` = '%s', `pwdreset` = '' WHERE `uid` = %d",
102 dbesc($new_password_encoded),
106 /// @TODO Is dbm::is_result() okay here?
108 $tpl = get_markup_template('pwdreset.tpl');
109 $o .= replace_macros($tpl,array(
110 '$lbl1' => t('Password Reset'),
111 '$lbl2' => t('Your password has been reset as requested.'),
112 '$lbl3' => t('Your new password is'),
113 '$lbl4' => t('Save or copy your new password - and then'),
114 '$lbl5' => '<a href="' . App::get_baseurl() . '">' . t('click here to login') . '</a>.',
115 '$lbl6' => t('Your password may be changed from the <em>Settings</em> page after successful login.'),
116 '$newpass' => $new_password,
117 '$baseurl' => App::get_baseurl()
120 info("Your password has been reset." . EOL);
123 $sitename = $a->config['sitename'];
124 // $username, $email, $new_password
125 $preamble = deindent(t('
127 Your password has been changed as requested. Please retain this
128 information for your records (or change your password immediately to
129 something that you will remember).
132 Your login details are as follows:
138 You may change that password from your account settings page after logging in.
141 $preamble = sprintf($preamble, $username);
142 $body = sprintf($body, App::get_baseurl(), $email, $new_password);
145 'type' => "SYSTEM_EMAIL",
146 'to_email' => $email,
147 'subject'=> sprintf( t('Your password has been changed at %s'),$sitename),
148 'preamble'=> $preamble,
156 $tpl = get_markup_template('lostpass.tpl');
158 $o .= replace_macros($tpl,array(
159 '$title' => t('Forgot your Password?'),
160 '$desc' => t('Enter your email address and submit to have your password reset. Then check your email for further instructions.'),
161 '$name' => t('Nickname or Email: '),
162 '$submit' => t('Reset')