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