-
-
Notifications
You must be signed in to change notification settings - Fork 314
/
Copy pathreset-password.php
93 lines (80 loc) · 3.14 KB
/
reset-password.php
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
<?php
/**
* Show the form to reset the password.
*/
$allowed_levels = array(9, 8, 7, 0);
require_once 'bootstrap.php';
$page_title = __('Lost password', 'cftp_admin');
$page_id = (!empty($_GET['token']) && !empty($_GET['user'])) ? 'reset_password_enter_new' : 'reset_password_enter_email';
include_once ADMIN_VIEWS_DIR . DS . 'header-unlogged.php';
$pass_reset = new \ProjectSend\Classes\PasswordReset();
// Process request
if ($_POST) {
$form_type = encode_html($_POST['form_type']);
switch ($form_type) {
case 'new_request':
recaptcha2_validate_request();
$get_user = get_user_by('user', 'email', $_POST['email']);
if ($get_user) {
$request = $pass_reset->requestNew($get_user['id']);
if ($request['status'] == 'success') {
$flash->success($request['message']);
} else {
$flash->error($request['message']);
}
} else {
// Simulate that the request has been set, do not show that email exists or not on the database
$flash->success($pass_reset->getNewRequestSuccessMessage());
}
ps_redirect(BASE_URI . 'reset-password.php');
break;
case 'new_password':
$get_user = get_user_by_username($_POST['user']);
if (!empty($get_user['id'])) {
$pass_reset->getByTokenAndUserId($_POST['token'], $get_user['id']);
$set = $pass_reset->processRequest($_POST['password']);
if ($set['status'] == 'success') {
$flash->success($set['message']);
ps_redirect(BASE_URI);
} else {
$flash->error($set['message']);
ps_redirect(BASE_URI . 'reset-password.php');
}
}
exit_with_error_code(403);
break;
}
} else {
if (!empty($_GET['token']) && !empty($_GET['user'])) {
$get_user = get_user_by_username($_GET['user']);
$pass_reset->getByTokenAndUserId($_GET['token'], $get_user['id']);
$validate = $pass_reset->validate();
if ($validate['status'] == 'error') {
$flash->error($validate['message']);
ps_redirect(BASE_URI . 'reset-password.php');
}
}
}
?>
<div class="row justify-content-md-center">
<div class="col-12 col-sm-12 col-lg-4">
<div class="white-box">
<div class="white-box-interior">
<?php
switch ($page_id) {
case 'reset_password_enter_email':
default:
include_once FORMS_DIR . DS . 'reset-password' . DS . 'enter-email.php';
break;
case 'reset_password_enter_new':
include_once FORMS_DIR . DS . 'reset-password' . DS . 'enter-password.php';
break;
}
?>
<?php login_form_links(['homepage']); ?>
</div>
</div>
</div>
</div>
<?php
include_once ADMIN_VIEWS_DIR . DS . 'footer.php';