]> git.mxchange.org Git - friendica.git/blob - mod/lostpass.php
Fix formatting mod/lostpass
[friendica.git] / mod / lostpass.php
1 <?php
2
3 /**
4  * @file mod/lostpass.php
5  */
6
7 use Friendica\App;
8 use Friendica\Core\System;
9 use Friendica\Database\DBM;
10
11 require_once 'include/boot.php';
12 require_once 'include/enotify.php';
13 require_once 'include/text.php';
14 require_once 'include/pgettext.php';
15
16 function lostpass_post(App $a)
17 {
18         $loginame = notags(trim($_POST['login-name']));
19         if (!$loginame) {
20                 goaway(System::baseUrl());
21         }
22
23         $condition = ['(`email` = ? OR `nickname` = ?) AND `verified` = 1 AND `blocked` = 0', $loginame, $loginame];
24         $user = dba::selectFirst('user', ['uid', 'username', 'email'], $condition);
25         if (!DBM::is_result($user)) {
26                 notice(t('No valid account found.') . EOL);
27                 goaway(System::baseUrl());
28         }
29
30         $pwdreset_token = autoname(12) . mt_rand(1000, 9999);
31
32         $result = dba::update('user', ['pwdreset' => $pwdreset_token], ['uid' => $user['uid']]);
33         if ($result) {
34                 info(t('Password reset request issued. Check your email.') . EOL);
35         }
36
37         $sitename = $a->config['sitename'];
38         $resetlink = System::baseUrl() . '/lostpass?verify=' . $pwdreset_token;
39
40         $preamble = deindent(t('
41                 Dear %1$s,
42                         A request was recently received at "%2$s" to reset your account
43                 password. In order to confirm this request, please select the verification link
44                 below or paste it into your web browser address bar.
45
46                 If you did NOT request this change, please DO NOT follow the link
47                 provided and ignore and/or delete this email.
48
49                 Your password will not be changed unless we can verify that you
50                 issued this request.', $user['username'], $sitename));
51         $body = deindent(t('
52                 Follow this link to verify your identity:
53
54                 %1$s
55
56                 You will then receive a follow-up message containing the new password.
57                 You may change that password from your account settings page after logging in.
58
59                 The login details are as follows:
60
61                 Site Location:  %2$s
62                 Login Name:     %3$s', $resetlink, System::baseUrl(), $user['email']));
63
64         notification([
65                 'type'     => SYSTEM_EMAIL,
66                 'to_email' => $user['email'],
67                 'subject'  => t('Password reset requested at %s', $sitename),
68                 'preamble' => $preamble,
69                 'body'     => $body
70         ]);
71
72         goaway(System::baseUrl());
73 }
74
75 function lostpass_content(App $a)
76 {
77         $o = '';
78         if (x($_GET, 'verify')) {
79                 $pwdreset_token = $_GET['verify'];
80
81                 $user = dba::selectFirst('user', ['uid', 'username', 'email'], ['pwdreset' => $pwdreset_token]);
82                 if (!DBM::is_result($user)) {
83                         $o = t("Request could not be verified. \x28You may have previously submitted it.\x29 Password reset failed.");
84                         return $o;
85                 }
86
87                 $new_password = autoname(6) . mt_rand(100, 9999);
88                 $new_password_encoded = hash('whirlpool', $new_password);
89
90                 $result = dba::update('user', ['password' => $new_password_encoded, 'pwdreset' => ''], ['uid' => $user['uid']]);
91                 if (DBM::is_result($result)) {
92                         $tpl = get_markup_template('pwdreset.tpl');
93                         $o .= replace_macros($tpl,
94                                 [
95                                 '$lbl1'    => t('Password Reset'),
96                                 '$lbl2'    => t('Your password has been reset as requested.'),
97                                 '$lbl3'    => t('Your new password is'),
98                                 '$lbl4'    => t('Save or copy your new password - and then'),
99                                 '$lbl5'    => '<a href="' . System::baseUrl() . '">' . t('click here to login') . '</a>.',
100                                 '$lbl6'    => t('Your password may be changed from the <em>Settings</em> page after successful login.'),
101                                 '$newpass' => $new_password,
102                                 '$baseurl' => System::baseUrl()
103                         ]);
104
105                         info("Your password has been reset." . EOL);
106
107                         $sitename = $a->config['sitename'];
108                         $preamble = deindent(t('
109                                 Dear %1$s,
110                                         Your password has been changed as requested. Please retain this
111                                 information for your records (or change your password immediately to
112                                 something that you will remember).
113                         ', $user['username']));
114                         $body = deindent(t('
115                                 Your login details are as follows:
116
117                                 Site Location:  %1$s
118                                 Login Name:     %2$s
119                                 Password:       %3$s
120
121                                 You may change that password from your account settings page after logging in.
122                         ', System::baseUrl(), $user['email'], $new_password));
123
124                         notification([
125                                 'type'     => SYSTEM_EMAIL,
126                                 'to_email' => $user['email'],
127                                 'subject'  => t('Your password has been changed at %s', $sitename),
128                                 'preamble' => $preamble,
129                                 'body'     => $body
130                         ]);
131
132                         return $o;
133                 }
134         } else {
135                 $tpl = get_markup_template('lostpass.tpl');
136                 $o .= replace_macros($tpl, [
137                         '$title'  => t('Forgot your Password?'),
138                         '$desc'   => t('Enter your email address and submit to have your password reset. Then check your email for further instructions.'),
139                         '$name'   => t('Nickname or Email: '),
140                         '$submit' => t('Reset')
141                 ]);
142
143                 return $o;
144         }
145 }