This repository has been archived by the owner on Oct 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathreset-password.php
76 lines (67 loc) · 2.2 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
<?php
require_once 'init.php';
if ($currentUser) {
header('Location: index.php');
exit();
}
?>
<?php include 'header.php' ?>
<?php
$code = NULL;
if (isset($_GET['code']) && !empty($_GET['code'])) {
$code = $_GET['code'];
$check = checkValidCodeResetPassword($code);
if (!$check) {
header('Location: activate-reset-password.php');
exit();
}
} else {
header('Location: activate-reset-password.php');
exit();
}
?>
<h1>Reset mật khẩu</h1>
<?php if (!(isset($_POST['newPassword']) || isset($_POST['newPasswordRepeat']))) : ?>
<form action="reset-password.php?code=<?php echo $code ?>" method="POST">
<div class="form-group">
<label for="newPassword">Mật khẩu mới</label>
<input type="password" class="form-control" id="newPassword" name="newPassword" placeholder="Mật khẩu mới">
</div>
<div class="form-group">
<label for="newPasswordRepeat">Mật khẩu mới (nhập lại)</label>
<input type="password" class="form-control" id="newPasswordRepeat" name="newPasswordRepeat" placeholder="Mật khẩu mới (nhập lại)">
</div>
<button type="submit" class="btn btn-primary">Đổi mật khẩu</button>
</form>
<?php else : ?>
<?php
// fetch from data
$newPassword = $_POST['newPassword'];
$newPasswordRepeat = $_POST['newPasswordRepeat'];
$success = false;
// check fields
$errorPattern = "<div class='alert alert-danger' role='alert alert-dismissible fade show'>";
$error = "";
if (empty($newPassword) || empty($newPasswordRepeat)) {
$error .= $errorPattern . "Bạn phải nhập đủ dữ liệu!</div>";
} else {
if ($newPassword == $newPasswordRepeat) {
$success = resetPassword($code, $newPassword);
} else {
$error .= $errorPattern . "Mật khẩu nhập lại không trùng khớp!</div>";
}
}
if ($success) {
header('Location: login.php');
exit();
} else {
$error .= $errorPattern . "Reset mật khẩu thất bại!</div>";
}
if (!empty($error)) {
echo $error;
}
?>
<a href="./reset-password.php?code=<?php echo $code ?>" class="btn btn-light">Thử lại</a>
</div>
<?php endif; ?>
<?php include 'footer.php' ?>