-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecoverPassword.php
More file actions
231 lines (208 loc) · 9.6 KB
/
Copy pathrecoverPassword.php
File metadata and controls
231 lines (208 loc) · 9.6 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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<!DOCTYPE html>
<html lang="en">
<?php
session_start();
include('./db_connect.php');
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 | recover password</b></a>
</div>
<div class="card">
<div class="card-body login-card-body">
<form action="" id="send-otp">
<div class="input-group mb-3">
<input type="email" class="form-control" name="email" id="email" required placeholder="email">
<div class="input-group-append">
<div class="input-group-text">
<span class="fas fa-envelope"></span>
</div>
</div>
</div>
<div class="row">
<div class="col-4">
<button type="submit" class="btn btn-primary btn-block" id="send_otp_btn">Send OTP</button>
</div>
<div class="col-8 resend-timer" style="display:none;color:black;">
resend in <span>10</span> s..
</div>
</div>
</form>
<br>
<!-- <form action="" id="verify-otp"> -->
<div class="input-group mb-3 otp-form">
<input type="number" class="form-control" name="otp" id="otp" required placeholder="enter otp">
<div class="input-group-append">
<div class="input-group-text">
<span class="fas fa-envelope"></span>
</div>
</div>
</div>
<div class="row otp-form">
<div class="col-4">
<button type="submit" class="btn btn-primary btn-block" id="verify_otp_btn" disabled>Verify OTP</button>
</div>
</div>
<!-- </form> -->
</div>
<div class="card-body login-card-body" >
<form action="" id="password-form" style="display: none;">
<div class="input-group mb-3">
<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>
// Function to start the resend OTP timer
function startResendOTPTimer(seconds) {
var timerInterval = setInterval(function() {
$('#send_otp_btn').prop('disabled',true);
$('.resend-timer').show().find('span').text(seconds);
seconds--;
if (seconds < 0) {
clearInterval(timerInterval);
$('#send_otp_btn').prop('disabled',false);
$('.resend-timer').hide();
}
}, 1000);
}
$(document).ready(function() {
//open correct forms if page is reloded accidently
//verifying email address and sending otp on registered mail
$('#send-otp').submit(function(e){
e.preventDefault();
start_load();
if ($(this).find('.alert-danger').length > 0)
$(this).find('.alert-danger').remove();
$.ajax({
url:'mailer.php?action=send_otp',
method:'POST',
data:$(this).serialize(),
error: err=>{
console.log(err);
end_load();
},
success:function(resp){
if(resp == 0){
//otp sent
alert_toast("OTP sent successfully", 'success');
$('#verify_otp_btn').prop('disabled',false);
startResendOTPTimer(10);
}else if(resp == 1){
//email is not registered
$('#send-otp').prepend('<div class="alert alert-danger">Email is not registered.</div>');
}else if(resp == 2){
//new user
alert_toast('You first need to set your password',"error");
setTimeout(function(){
location.href = 'setPassword.php?email='+$('#email').val();
},2000)
}else{
//system error
$('#send-otp').prepend('<div class="alert alert-danger">Some error occured.</div>');
}
end_load();
}
})
})
//verifying otp
$('#verify_otp_btn').click(function(e){
// e.preventDefault();
start_load();
if ($(this).find('.alert-danger').length > 0)
$(this).find('.alert-danger').remove();
$.ajax({
url:'mailer.php?action=verify_otp',
method:'POST',
data: {otp : $("#otp").val()},
error:err=>{
console.log(err);
end_load();
},
success:function(resp){
// console.log(resp);
if(resp == 0){
//otp verified
alert_toast("OTP verified successfully", 'success');
$('#send-otp').css('display','none');
$('.otp-form').css('display','none');
$('#password-form').show();
}else{
//not -verifed
$('#send-otp').prepend('<div class="alert alert-danger">OTP not verified.</div>');
}
end_load();
}
})
})
$('#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: 'mailer.php?action=reset_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 {
$('#password-form').prepend('<div class="alert alert-danger">Some Error occured.</div>')
end_load();
}
}
})
} //end else
})
})
</script>
<?php include 'footer.php' ?>
</body>
</html>