-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathrecover.php
More file actions
executable file
·212 lines (199 loc) · 6.34 KB
/
recover.php
File metadata and controls
executable file
·212 lines (199 loc) · 6.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<?php
/**
* Password recovery
*
* PHP version 8
*
* Copyright (C) Ere Maijala 2018-2021
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category MLInvoice
* @package MLInvoice\Base
* @author Ere Maijala <ere@labs.fi>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://labs.fi/mlinvoice.eng.php
*/
// buffered, so we can redirect later if necessary
ini_set('implicit_flush', 'Off');
ob_start();
require_once 'vendor/autoload.php';
require_once 'sessionfuncs.php';
require_once 'sqlfuncs.php';
require_once 'miscfuncs.php';
require_once 'config.php';
require_once 'htmlfuncs.php';
require_once 'translator.php';
require_once 'mailer.php';
if (!session_id()) {
session_start();
}
if (!getSetting('password_recovery')) {
echo htmlPageStart();
?>
<body>
<div class="container-fluid">
<div class="form_container">
Unavailable
</div>
</div>
</body>
</html>
<?php
return;
}
$token = getPostOrQuery('token');
if ($token) {
$tokenTime = intval(substr($token, -10));
if (time() - $tokenTime > 3600) {
$errorMessage = Translator::translate('TokenExpired');
} else {
$user = getUserByToken($token);
if (!$user) {
$errorMessage = Translator::translate('AccountNotFound');
} else {
$password = getPostOrQuery('password', false);
if (false !== $password) {
updateUserPassword($user['id'], $password);
$message = Translator::translate('PasswordChanged');
$completed = true;
}
}
}
}
$userId = getPost('userid', false);
if ($userId) {
if (CSRF_OK !== sesCheckCsrf(getPost('csrf'))) {
$message = Translator::translate('LoginTimeout');
} else {
$user = getUserByLoginId($userId);
if (!$user) {
$message = Translator::translate('RecoveryInstructionsSent');
$completed = true;
} else {
if (!empty($user['email'])) {
$newToken = updateUserToken($user['id']);
$scheme = $_SERVER['REQUEST_SCHEME'];
$url = "$scheme://" . $_SERVER['SERVER_NAME'];
$port = $_SERVER['SERVER_PORT'];
if (('http' === $scheme && 80 != $port)
|| ('https' === $scheme && 443 != $port)
) {
$url .= ":$port";
}
$url .= $_SERVER['REQUEST_URI'];
$url .= (strpos($url, '?') === false ? '?' : '&');
$url .= 'token=' . $newToken;
$mailer = new Mailer();
$result = $mailer->sendEmail(
$user['email'],
$user['email'],
[],
[],
Translator::translate('RecoverAccountEmailSubject'),
Translator::translate(
'RecoverAccountEmailBody',
['%%url%%' => $url]
),
[]
);
if (!$result) {
$errorMessage = $mailer->getErrorMessage();
} else {
$message = Translator::translate('RecoveryInstructionsSent');
$completed = true;
}
} else {
$message = Translator::translate('RecoveryInstructionsSent');
$completed = true;
}
}
}
}
usleep(rand(500, 1000) * 1000 * MLINVOICE_LOGIN_DELAY_MULTIPLIER);
$csrf = sesCreateCsrf();
echo htmlPageStart('');
?>
<body>
<div class="pagewrapper mb-4">
<?php createNavBar([], '')?>
<div class="content recover-form">
<?php
if (isset($message)) {
?>
<div class="alert alert-success message">
<?php echo $message?>
</div>
<br />
<?php
} elseif (isset($errorMessage)) {
?>
<div class="alert alert-danger message">
<?php echo $errorMessage?>
</div>
<br />
<?php
}
if (empty($completed)) {
?>
<div class="form login">
<h1><?php echo Translator::translate('RecoverAccount')?></h1>
<form method="post" name="recover_form">
<input type="hidden" name="csrf" value="<?php echo htmlentities($csrf)?>">
<?php
if ($token && !empty($user)) {
?>
<input type="hidden" name="token" value="<?php echo htmlentities($token)?>">
<p>
<span class="label">
<?php echo Translator::translate('UserID')?>
</span>
<?php echo htmlentities($user['login'])?>
</p>
<p>
<span class="label">
<?php echo Translator::translate('NewPassword')?>
</span>
<input class="form-control medium" name="password" id="password" type="password" value="">
</p>
<?php
} else {
?>
<p>
<span class="label">
<?php echo Translator::translate('UserIdOrEmail')?>
</span>
<input class="form-control medium" name="userid" id="userid" type="text" value="">
</p>
<?php
}
?>
<p>
<input class="btn btn-primary" type="submit" name="logon"
value="<?php echo Translator::translate('Continue')?>">
</p>
</form>
</div>
<?php
}
?>
<div>
<p>
<a href="login.php"><?php echo Translator::translate('BackToLogin')?></a>
</p>
</div>
</div>
</div>
</body>
</html>