3 require_once('include/email.php');
5 function lostpass_post(&$a) {
7 $loginame = notags(trim($_POST['login-name']));
11 $r = q("SELECT * FROM `user` WHERE ( `email` = '%s' OR `nickname` = '%s' ) AND `verified` = 1 AND `blocked` = 0 LIMIT 1",
17 notice( t('No valid account found.') . EOL);
22 $username = $r[0]['username'];
23 $email = $r[0]['email'];
25 $new_password = autoname(12) . mt_rand(100,9999);
26 $new_password_encoded = hash('whirlpool',$new_password);
28 $r = q("UPDATE `user` SET `pwdreset` = '%s' WHERE `uid` = %d LIMIT 1",
29 dbesc($new_password_encoded),
33 info( t('Password reset request issued. Check your email.') . EOL);
35 $engine = get_app()->get_template_engine();
36 get_app()->set_template_engine();
38 $email_tpl = get_intltext_template("lostpass_eml.tpl");
39 $email_tpl = replace_macros($email_tpl, array(
40 '$sitename' => $a->config['sitename'],
41 '$siteurl' => $a->get_baseurl(),
42 '$username' => $username,
44 '$reset_link' => $a->get_baseurl() . '/lostpass?verify=' . $new_password
47 get_app()->set_template_engine($engine);
49 $res = mail($email, email_header_encode(sprintf( t('Password reset requested at %s'),$a->config['sitename']),'UTF-8'),
51 'From: ' . 'Administrator' . '@' . $_SERVER['SERVER_NAME'] . "\n"
52 . 'Content-type: text/plain; charset=UTF-8' . "\n"
53 . 'Content-transfer-encoding: 8bit' );
60 function lostpass_content(&$a) {
63 if(x($_GET,'verify')) {
64 $verify = $_GET['verify'];
65 $hash = hash('whirlpool', $verify);
67 $r = q("SELECT * FROM `user` WHERE `pwdreset` = '%s' LIMIT 1",
71 notice( t("Request could not be verified. \x28You may have previously submitted it.\x29 Password reset failed.") . EOL);
76 $username = $r[0]['username'];
77 $email = $r[0]['email'];
79 $new_password = autoname(6) . mt_rand(100,9999);
80 $new_password_encoded = hash('whirlpool',$new_password);
82 $r = q("UPDATE `user` SET `password` = '%s', `pwdreset` = '' WHERE `uid` = %d LIMIT 1",
83 dbesc($new_password_encoded),
87 $tpl = get_markup_template('pwdreset.tpl');
88 $o .= replace_macros($tpl,array(
89 '$lbl1' => t('Password Reset'),
90 '$lbl2' => t('Your password has been reset as requested.'),
91 '$lbl3' => t('Your new password is'),
92 '$lbl4' => t('Save or copy your new password - and then'),
93 '$lbl5' => '<a href="' . $a->get_baseurl() . '">' . t('click here to login') . '</a>.',
94 '$lbl6' => t('Your password may be changed from the <em>Settings</em> page after successful login.'),
95 '$newpass' => $new_password,
96 '$baseurl' => $a->get_baseurl()
99 info("Your password has been reset." . EOL);
102 $engine = get_app()->get_template_engine();
103 get_app()->set_template_engine();
105 $email_tpl = get_intltext_template("passchanged_eml.tpl");
106 $email_tpl = replace_macros($email_tpl, array(
107 '$sitename' => $a->config['sitename'],
108 '$siteurl' => $a->get_baseurl(),
109 '$username' => $username,
111 '$new_password' => $new_password,
112 '$uid' => $newuid ));
114 get_app()->set_template_engine($engine);
116 $subject = sprintf( t('Your password has been changed at %s'), $a->config['sitename']);
118 $res = mail($email, email_header_encode( $subject, 'UTF-8'), $email_tpl,
119 'From: ' . 'Administrator' . '@' . $_SERVER['SERVER_NAME'] . "\n"
120 . 'Content-type: text/plain; charset=UTF-8' . "\n"
121 . 'Content-transfer-encoding: 8bit' );
128 $tpl = get_markup_template('lostpass.tpl');
130 $o .= replace_macros($tpl,array(
131 '$title' => t('Forgot your Password?'),
132 '$desc' => t('Enter your email address and submit to have your password reset. Then check your email for further instructions.'),
133 '$name' => t('Nickname or Email: '),
134 '$submit' => t('Reset')