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