-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathreset.php
131 lines (117 loc) · 5.16 KB
/
reset.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
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
<?php
if (isset($_SESSION['allowed']) && $_SESSION['allowed'] === true) {
header('location: /index.php');
}
$title = 'Reset Password';
include __DIR__ . '/common/header_auth.php';
if (empty($_GET['code'])) {
header('location: /signin.php');
exit;
} else {
if ($query = $mysql->prepare("SELECT id FROM `users` WHERE `code` = ?")) {
if ($query->bind_param("s", $_GET['code'])) {
if ($query->execute()) {
if ($results = $query->get_result()) {
if ($results->num_rows != 1) {
header('location: /signin.php');
exit;
}
}
}
}
}
}
$flash = null;
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (!empty($_POST['code'])) {
if ($query = $mysql->prepare("SELECT id, email, lastlogin FROM `users` WHERE `code` = ?")) {
if ($query->bind_param("s", $_POST['code'])) {
if ($query->execute()) {
if ($result = $query->get_result()) {
if ($result->num_rows == 1) {
$user = $result->fetch_assoc();
if ($query = $mysql->prepare("UPDATE `users` SET `password` = ? WHERE `id` = ?")) {
if ($query->bind_param("si", password_hash($_POST['password']), $user['id'])) {
if ($query->execute()) {
if ($query->affected_rows === 1) {
session_start();
$_SESSION['allowed'] = true;
$_SESSION['user'] = [
'id' => $user['id'],
'email' => $user['email'],
'lastlogin' => $user['lastlogin']
];
header('location: /index.php');
exit();
} else {
$flash = '<div class="alert alert-danger" role="alert">Error occurred</div>';
}
} else {
$flash = '<div class="alert alert-danger" role="alert">Error occurred</div>';
}
} else {
$flash = '<div class="alert alert-danger" role="alert">Error occurred</div>';
}
} else {
$flash = '<div class="alert alert-danger" role="alert">Error occurred</div>';
}
} else {
$flash = '<div class="alert alert-danger" role="alert">Error occurred</div>';
}
} else {
$flash = '<div class="alert alert-danger" role="alert">Error occurred</div>';
}
} else {
$flash = '<div class="alert alert-danger" role="alert">Error occurred</div>';
}
} else {
$flash = '<div class="alert alert-danger" role="alert">Error occurred</div>';
}
} else {
$flash = '<div class="alert alert-danger" role="alert">Error occurred</div>';
}
} else {
$flash = '<div class="alert alert-danger" role="alert">Error occurred</div>';
}
}
?>
<div class="box">
<div class="box-body">
<form action="" id="frmReset" method="post" class="form-auth">
<input name="code" type="hidden" value="<?php echo $_GET['code']; ?>" />
<?php if (!empty($flash)) { ?><?php echo $flash; ?><?php } ?>
<div class="form-group">
<label for="password">New Password</label>
<input name="password" type="password" id="password" class="form-control" placeholder="Password">
</div>
<div class="form-group">
<label for="confirm">Confirm</label>
<input name="confirm" type="password" id="confirm" class="form-control" placeholder="Confirm Password">
</div>
<div class="row">
<div class="col-12">
<button class="btn btn-info btn-block" type="submit">Change Password <i class="fa fa-sign-in-alt"></i></button>
</div>
</div>
</form>
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
$("#frmReset").validate({
rules: {
password: {
required: true,
normalizer: function(value) {
return $.trim(value);
},
minlength: 8
},
confirm: {
equalTo: '#password'
}
}
});
});
</script>
<?php include __DIR__ . '/common/footer.php'; ?>