]> git.mxchange.org Git - friendica.git/blob - mod/lostpass.php
Merge remote-tracking branch 'friendica/develop' into develop
[friendica.git] / mod / lostpass.php
1 <?php
2
3 require_once('include/email.php');
4 require_once('include/enotify.php');
5 require_once('include/text.php');
6
7 function lostpass_post(&$a) {
8
9         $loginame = notags(trim($_POST['login-name']));
10         if(! $loginame)
11                 goaway(z_root());
12
13         $r = q("SELECT * FROM `user` WHERE ( `email` = '%s' OR `nickname` = '%s' ) AND `verified` = 1 AND `blocked` = 0 LIMIT 1",
14                 dbesc($loginame),
15                 dbesc($loginame)
16         );
17
18         if (! dbm::is_result($r)) {
19                 notice( t('No valid account found.') . EOL);
20                 goaway(z_root());
21         }
22
23         $uid = $r[0]['uid'];
24         $username = $r[0]['username'];
25         $email = $r[0]['email'];
26
27         $new_password = autoname(12) . mt_rand(100,9999);
28         $new_password_encoded = hash('whirlpool',$new_password);
29
30         $r = q("UPDATE `user` SET `pwdreset` = '%s' WHERE `uid` = %d",
31                 dbesc($new_password_encoded),
32                 intval($uid)
33         );
34         if($r)
35                 info( t('Password reset request issued. Check your email.') . EOL);
36
37
38         $sitename = $a->config['sitename'];
39         $resetlink = App::get_baseurl() . '/lostpass?verify=' . $new_password;
40
41         $preamble = deindent(t('
42                 Dear %1$s,
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.
46
47                 If you did NOT request this change, please DO NOT follow the link
48                 provided and ignore and/or delete this email.
49
50                 Your password will not be changed unless we can verify that you
51                 issued this request.'));
52         $body = deindent(t('
53                 Follow this link to verify your identity:
54
55                 %1$s
56
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.
59
60                 The login details are as follows:
61
62                 Site Location:  %2$s
63                 Login Name:     %3$s'));
64
65         $preamble = sprintf($preamble, $username, $sitename);
66         $body = sprintf($body, $resetlink, App::get_baseurl(), $email);
67
68         notification(array(
69                 'type' => "SYSTEM_EMAIL",
70                 'to_email' => $email,
71                 'subject'=> sprintf( t('Password reset requested at %s'),$sitename),
72                 'preamble'=> $preamble,
73                 'body' => $body));
74
75         goaway(z_root());
76
77 }
78
79
80 function lostpass_content(&$a) {
81
82
83         if(x($_GET,'verify')) {
84                 $verify = $_GET['verify'];
85                 $hash = hash('whirlpool', $verify);
86
87                 $r = q("SELECT * FROM `user` WHERE `pwdreset` = '%s' LIMIT 1",
88                         dbesc($hash)
89                 );
90                 if (! dbm::is_result($r)) {
91                         $o =  t("Request could not be verified. \x28You may have previously submitted it.\x29 Password reset failed.");
92                         return $o;
93                 }
94                 $uid = $r[0]['uid'];
95                 $username = $r[0]['username'];
96                 $email = $r[0]['email'];
97
98                 $new_password = autoname(6) . mt_rand(100,9999);
99                 $new_password_encoded = hash('whirlpool',$new_password);
100
101                 $r = q("UPDATE `user` SET `password` = '%s', `pwdreset` = ''  WHERE `uid` = %d",
102                         dbesc($new_password_encoded),
103                         intval($uid)
104                 );
105                 if ($r) {
106                         $tpl = get_markup_template('pwdreset.tpl');
107                         $o .= replace_macros($tpl,array(
108                                 '$lbl1' => t('Password Reset'),
109                                 '$lbl2' => t('Your password has been reset as requested.'),
110                                 '$lbl3' => t('Your new password is'),
111                                 '$lbl4' => t('Save or copy your new password - and then'),
112                                 '$lbl5' => '<a href="' . App::get_baseurl() . '">' . t('click here to login') . '</a>.',
113                                 '$lbl6' => t('Your password may be changed from the <em>Settings</em> page after successful login.'),
114                                 '$newpass' => $new_password,
115                                 '$baseurl' => App::get_baseurl()
116
117                         ));
118                                 info("Your password has been reset." . EOL);
119
120
121                         $sitename = $a->config['sitename'];
122                         // $username, $email, $new_password
123                         $preamble = deindent(t('
124                                 Dear %1$s,
125                                         Your password has been changed as requested. Please retain this
126                                 information for your records (or change your password immediately to
127                                 something that you will remember).
128                         '));
129                         $body = deindent(t('
130                                 Your login details are as follows:
131
132                                 Site Location:  %1$s
133                                 Login Name:     %2$s
134                                 Password:       %3$s
135
136                                 You may change that password from your account settings page after logging in.
137                         '));
138
139                         $preamble = sprintf($preamble, $username);
140                         $body = sprintf($body, App::get_baseurl(), $email, $new_password);
141
142                         notification(array(
143                                 'type' => "SYSTEM_EMAIL",
144                                 'to_email' => $email,
145                                 'subject'=> sprintf( t('Your password has been changed at %s'),$sitename),
146                                 'preamble'=> $preamble,
147                                 'body' => $body));
148
149                         return $o;
150                 }
151
152         }
153         else {
154                 $tpl = get_markup_template('lostpass.tpl');
155
156                 $o .= replace_macros($tpl,array(
157                         '$title' => t('Forgot your Password?'),
158                         '$desc' => t('Enter your email address and submit to have your password reset. Then check your email for further instructions.'),
159                         '$name' => t('Nickname or Email: '),
160                         '$submit' => t('Reset')
161                 ));
162
163                 return $o;
164         }
165
166 }