-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetPassword.php
More file actions
122 lines (105 loc) · 5.03 KB
/
setPassword.php
File metadata and controls
122 lines (105 loc) · 5.03 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
<!DOCTYPE html>
<html lang="en">
<?php
session_start();
include('./db_connect.php');
$qry = $conn->query("select id from users where email='" . $_GET['email'] . "' and active = 1")->fetch_assoc();
$user_id = $qry['id'];
if (isset($_SESSION['login_id'])) {
header("location:index.php?page=home");
}
include 'header.php';
?>
<body class="hold-transition login-pages">
<div class="container-fluid w-full h-6 p-4 fixed-top z-10" style="background-color: #fff;">
<img src="assets/logo (1).png" alt="logo">
</div>
<div class="login-page">
<div class="login-box">
<div class="login-logo">
<a href="#"><b>FTS-KNIT | Reset Password</b></a>
</div>
<div class="card">
<div class="card-body login-card-body">
<form action="" id="password-form">
<div class="input-group mb-3">
<input type="text" class="form-control" name="old_password" id="old_password" required placeholder="old password">
<div class="input-group-append">
<div class="input-group-text">
<span class="fas fa-lock"></span>
</div>
</div>
</div>
<div class="input-group mb-3">
<input type="hidden" id="user_id" name="user_id" value="<?php echo $user_id ?>">
<input type="password" class="form-control" id="_password" name="_password" required placeholder="Password">
<div class="input-group-append">
<div class="input-group-text">
<span class="fas fa-lock"></span>
</div>
</div>
</div>
<div class="input-group mb-3">
<input type="text" class="form-control" name="confirm_password" id="confirm_password" required placeholder="Confirm Password">
<div class="input-group-append">
<div class="input-group-text">
<span class="fas fa-lock"></span>
</div>
</div>
</div>
<div class="row">
<div class="col-4">
<button type="submit" class="btn btn-primary btn-block">Save</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function() {
$('#password-form').submit(function(e) {
e.preventDefault();
start_load();
if ($(this).find('.alert-danger').length > 0)
$(this).find('.alert-danger').remove();
var password = document.getElementById("_password").value;
var confirmPassword = document.getElementById("confirm_password").value;
if (password !== confirmPassword) {
$('#password-form').prepend('<div class="alert alert-danger">Password fields do not match.</div>');
e.preventDefault(); // Prevent form submission
end_load();
} else {
//save to database
$.ajax({
url: 'ajax.php?action=save_password',
method: 'POST',
data: $(this).serialize(),
error: err => {
console.log(err)
end_load();
},
success: function(resp) {
if (resp == 0) {
alert_toast("Password successfully updated", 'success')
setTimeout(function() {
location.reload()
}, 2000)
location.href = 'login.php';
} else if (resp == 2) {
$('#password-form').prepend('<div class="alert alert-danger">Old Password is not correct.</div>')
end_load();
} else {
$('#password-form').prepend('<div class="alert alert-danger">Some Error occured.</div>')
end_load();
}
}
})
}//end else
})
})
</script>
<?php include 'footer.php' ?>
</body>
</html>