]> git.mxchange.org Git - friendica.git/blob - mod/lostpass.php
merged multipart email changes
[friendica.git] / mod / lostpass.php
1 <?php
2
3
4 function lostpass_post(&$a) {
5
6         $email = notags(trim($_POST['login-name']));
7         if(! $email)
8                 goaway($a->get_baseurl());
9
10         $r = q("SELECT * FROM `user` WHERE ( `email` = '%s' OR `nickname` = '%s' ) LIMIT 1",
11                 dbesc($email),
12                 dbesc($email)
13         );
14         if(! count($r))
15                 goaway($a->get_baseurl());
16         $uid = $r[0]['uid'];
17         $username = $r[0]['username'];
18
19         $new_password = autoname(12) . mt_rand(100,9999);
20         $new_password_encoded = hash('whirlpool',$new_password);
21
22         $r = q("UPDATE `user` SET `pwdreset` = '%s' WHERE `uid` = %d LIMIT 1",
23                 dbesc($new_password_encoded),
24                 intval($uid)
25         );
26         if($r)
27                 notice( t('Password reset request issued. Check your email.') . EOL);
28
29         $email_tpl = get_intltext_template("lostpass_eml.tpl");
30         $email_tpl = replace_macros($email_tpl, array(
31                         '$sitename' => $a->config['sitename'],
32                         '$siteurl' =>  $a->get_baseurl(),
33                         '$username' => $username,
34                         '$email' => $email,
35                         '$reset_link' => $a->get_baseurl() . '/lostpass?verify=' . $new_password
36         ));
37
38         $res = mail($email, sprintf( t('Password reset requested at %s'),$a->config['sitename']),
39                         $email_tpl,
40                         'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME'] . "\n"
41                         . 'Content-type: text/plain; charset=UTF-8' . "\n"
42                         . 'Content-transfer-encoding: 8bit' );
43
44
45         goaway($a->get_baseurl());
46 }
47
48
49 function lostpass_content(&$a) {
50
51
52         if(x($_GET,'verify')) {
53                 $verify = $_GET['verify'];
54                 $hash = hash('whirlpool', $verify);
55
56                 $r = q("SELECT * FROM `user` WHERE `pwdreset` = '%s' LIMIT 1",
57                         dbesc($hash)
58                 );
59                 if(! count($r)) {
60                         notice( t("Request could not be verified. \x28You may have previously submitted it.\x29 Password reset failed.") . EOL);
61                         goaway($a->get_baseurl());
62                         return;
63                 }
64                 $uid = $r[0]['uid'];
65                 $username = $r[0]['username'];
66                 $email = $r[0]['email'];
67
68                 $new_password = autoname(6) . mt_rand(100,9999);
69                 $new_password_encoded = hash('whirlpool',$new_password);
70
71                 $r = q("UPDATE `user` SET `password` = '%s', `pwdreset` = ''  WHERE `uid` = %d LIMIT 1",
72                         dbesc($new_password_encoded),
73                         intval($uid)
74                 );
75                 if($r) {
76                         $tpl = get_markup_template('pwdreset.tpl');
77                         $o .= replace_macros($tpl,array(
78                                 '$lbl1' => t('Password Reset'),
79                                 '$lbl2' => t('Your password has been reset as requested.'),
80                                 '$lbl3' => t('Your new password is'),
81                                 '$lbl4' => t('Save or copy your new password - and then'),
82                                 '$lbl5' => '<a href="' . $a->get_baseurl() . '">' . t('click here to login') . '</a>.',
83                                 '$lbl6' => t('Your password may be changed from the <em>Settings</em> page after successful login.'),
84                                 '$newpass' => $new_password,
85                                 '$baseurl' => $a->get_baseurl()
86
87                         ));
88                                 notice("Your password has been reset." . EOL);
89
90
91
92                         $email_tpl = get_intltext_template("passchanged_eml.tpl");
93                         $email_tpl = replace_macros($email_tpl, array(
94                         '$sitename' => $a->config['sitename'],
95                         '$siteurl' =>  $a->get_baseurl(),
96                         '$username' => $username,
97                         '$email' => $email,
98                         '$new_password' => $new_password,
99                         '$uid' => $newuid ));
100
101                         $res = mail($email,"Your password has changed at {$a->config['sitename']}",$email_tpl,
102                                 'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME'] . "\n"
103                                 . 'Content-type: text/plain; charset=UTF-8' . "\n"
104                                 . 'Content-transfer-encoding: 8bit' );
105
106                         return $o;
107                 }
108         
109         }
110         else {
111                 $tpl = get_markup_template('lostpass.tpl');
112
113                 $o .= replace_macros($tpl,array(
114                         '$title' => t('Forgot your Password?'),
115                         '$desc' => t('Enter your email address and submit to have your password reset. Then check your email for further instructions.'),
116                         '$name' => t('Nickname or Email: '),
117                         '$submit' => t('Reset') 
118                 ));
119
120                 return $o;
121         }
122
123 }