]> git.mxchange.org Git - friendica.git/blob - mod/lostpass.php
lost password verification mail via notification()
[friendica.git] / mod / lostpass.php
1 <?php
2
3 require_once('include/email.php');
4 require_once('include/enotify.php');
5
6 function lostpass_post(&$a) {
7
8         $loginame = notags(trim($_POST['login-name']));
9         if(! $loginame)
10                 goaway(z_root());
11
12         $r = q("SELECT * FROM `user` WHERE ( `email` = '%s' OR `nickname` = '%s' ) AND `verified` = 1 AND `blocked` = 0 LIMIT 1",
13                 dbesc($loginame),
14                 dbesc($loginame)
15         );
16
17         if(! count($r)) {
18                 notice( t('No valid account found.') . EOL);
19                 goaway(z_root());
20         }
21
22         $uid = $r[0]['uid'];
23         $username = $r[0]['username'];
24         $email = $r[0]['email'];
25
26         $new_password = autoname(12) . mt_rand(100,9999);
27         $new_password_encoded = hash('whirlpool',$new_password);
28
29         $r = q("UPDATE `user` SET `pwdreset` = '%s' WHERE `uid` = %d",
30                 dbesc($new_password_encoded),
31                 intval($uid)
32         );
33         if($r)
34                 info( t('Password reset request issued. Check your email.') . EOL);
35
36
37         $sitename = $a->config['sitename'];
38         $siteurl = $a->get_baseurl();
39         $resetlink = $a->get_baseurl() . '/lostpass?verify=' . $new_password;
40
41         $preamble = t('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.');
51         $body = t('Follow this link to verify your identity:
52
53 %1$s
54
55 You will then receive a follow-up message containing the new password.
56
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');
63
64         $preamble = sprintf($preamble, $username, $sitename);
65         $body = sprintf($body, $resetlink, $siteurl, $email);
66
67         notification(array(
68                 'type' => "SYSTEM_EMAIL",
69                 'to_email' => $email,
70                 'subject'=> sprintf( t('Password reset requested at %s'),$sitename),
71                 'preamble'=> $preamble,
72                 'body' => $body));
73
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(! count($r)) {
91                         notice( t("Request could not be verified. \x28You may have previously submitted it.\x29 Password reset failed.") . EOL);
92                         goaway(z_root());
93                         return;
94                 }
95                 $uid = $r[0]['uid'];
96                 $username = $r[0]['username'];
97                 $email = $r[0]['email'];
98
99                 $new_password = autoname(6) . mt_rand(100,9999);
100                 $new_password_encoded = hash('whirlpool',$new_password);
101
102                 $r = q("UPDATE `user` SET `password` = '%s', `pwdreset` = ''  WHERE `uid` = %d",
103                         dbesc($new_password_encoded),
104                         intval($uid)
105                 );
106                 if($r) {
107                         $tpl = get_markup_template('pwdreset.tpl');
108                         $o .= replace_macros($tpl,array(
109                                 '$lbl1' => t('Password Reset'),
110                                 '$lbl2' => t('Your password has been reset as requested.'),
111                                 '$lbl3' => t('Your new password is'),
112                                 '$lbl4' => t('Save or copy your new password - and then'),
113                                 '$lbl5' => '<a href="' . $a->get_baseurl() . '">' . t('click here to login') . '</a>.',
114                                 '$lbl6' => t('Your password may be changed from the <em>Settings</em> page after successful login.'),
115                                 '$newpass' => $new_password,
116                                 '$baseurl' => $a->get_baseurl()
117
118                         ));
119                                 info("Your password has been reset." . EOL);
120
121
122
123                         $email_tpl = get_intltext_template("passchanged_eml.tpl");
124                         $email_tpl = replace_macros($email_tpl, array(
125                         '$sitename' => $a->config['sitename'],
126                         '$siteurl' =>  $a->get_baseurl(),
127                         '$username' => $username,
128                         '$email' => $email,
129                         '$new_password' => $new_password,
130                         '$uid' => $newuid ));
131
132                         $subject = sprintf( t('Your password has been changed at %s'), $a->config['sitename']);
133
134                         $res = mail($email, email_header_encode( $subject, 'UTF-8'), $email_tpl,
135                                 'From: ' . 'Administrator' . '@' . $_SERVER['SERVER_NAME'] . "\n"
136                                 . 'Content-type: text/plain; charset=UTF-8' . "\n"
137                                 . 'Content-transfer-encoding: 8bit' );
138
139                         return $o;
140                 }
141
142         }
143         else {
144                 $tpl = get_markup_template('lostpass.tpl');
145
146                 $o .= replace_macros($tpl,array(
147                         '$title' => t('Forgot your Password?'),
148                         '$desc' => t('Enter your email address and submit to have your password reset. Then check your email for further instructions.'),
149                         '$name' => t('Nickname or Email: '),
150                         '$submit' => t('Reset')
151                 ));
152
153                 return $o;
154         }
155
156 }