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