4 * @file mod/lostpass.php
8 use Friendica\Core\System;
9 use Friendica\Database\DBM;
10 use Friendica\Model\User;
12 require_once 'include/boot.php';
13 require_once 'include/enotify.php';
14 require_once 'include/text.php';
15 require_once 'include/pgettext.php';
17 function lostpass_post(App $a)
19 $loginame = notags(trim($_POST['login-name']));
21 goaway(System::baseUrl());
24 $condition = ['(`email` = ? OR `nickname` = ?) AND `verified` = 1 AND `blocked` = 0', $loginame, $loginame];
25 $user = dba::selectFirst('user', ['uid', 'username', 'email'], $condition);
26 if (!DBM::is_result($user)) {
27 notice(t('No valid account found.') . EOL);
28 goaway(System::baseUrl());
31 $pwdreset_token = autoname(12) . mt_rand(1000, 9999);
33 $result = dba::update('user', ['pwdreset' => $pwdreset_token], ['uid' => $user['uid']]);
35 info(t('Password reset request issued. Check your email.') . EOL);
38 $sitename = $a->config['sitename'];
39 $resetlink = System::baseUrl() . '/lostpass?verify=' . $pwdreset_token;
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.', $user['username'], $sitename));
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:
63 Login Name: %3$s', $resetlink, System::baseUrl(), $user['email']));
66 'type' => SYSTEM_EMAIL,
67 'to_email' => $user['email'],
68 'subject' => t('Password reset requested at %s', $sitename),
69 'preamble' => $preamble,
73 goaway(System::baseUrl());
76 function lostpass_content(App $a)
79 if (x($_GET, 'verify')) {
80 $pwdreset_token = $_GET['verify'];
82 $user = dba::selectFirst('user', ['uid', 'username', 'email'], ['pwdreset' => $pwdreset_token]);
83 if (!DBM::is_result($user)) {
84 $o = t("Request could not be verified. \x28You may have previously submitted it.\x29 Password reset failed.");
88 $new_password = User::generateNewPassword();
89 $result = User::updatePassword($user['uid'], $new_password);
90 if (DBM::is_result($result)) {
91 $tpl = get_markup_template('pwdreset.tpl');
92 $o .= replace_macros($tpl,
94 '$lbl1' => t('Password Reset'),
95 '$lbl2' => t('Your password has been reset as requested.'),
96 '$lbl3' => t('Your new password is'),
97 '$lbl4' => t('Save or copy your new password - and then'),
98 '$lbl5' => '<a href="' . System::baseUrl() . '">' . t('click here to login') . '</a>.',
99 '$lbl6' => t('Your password may be changed from the <em>Settings</em> page after successful login.'),
100 '$newpass' => $new_password,
101 '$baseurl' => System::baseUrl()
104 info("Your password has been reset." . EOL);
106 $sitename = $a->config['sitename'];
107 $preamble = deindent(t('
109 Your password has been changed as requested. Please retain this
110 information for your records (or change your password immediately to
111 something that you will remember).
112 ', $user['username']));
114 Your login details are as follows:
120 You may change that password from your account settings page after logging in.
121 ', System::baseUrl(), $user['email'], $new_password));
124 'type' => SYSTEM_EMAIL,
125 'to_email' => $user['email'],
126 'subject' => t('Your password has been changed at %s', $sitename),
127 'preamble' => $preamble,
134 $tpl = get_markup_template('lostpass.tpl');
135 $o .= replace_macros($tpl, [
136 '$title' => t('Forgot your Password?'),
137 '$desc' => t('Enter your email address and submit to have your password reset. Then check your email for further instructions.'),
138 '$name' => t('Nickname or Email: '),
139 '$submit' => t('Reset')