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