-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathverify_code.php
More file actions
226 lines (187 loc) · 5.62 KB
/
verify_code.php
File metadata and controls
226 lines (187 loc) · 5.62 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
<?php
session_start();
$randomNumber = $_SESSION['random_number'];
?>
<!DOCTYPE html>
<html>
<head>
<title>Forgot Password</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="assets/css/forgot_password_style.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<script src="https://code.jquery.com/jquery-3.7.0.js"></script>
<style>
.container {
position: relative;
width: 300px; /* Adjust the width as needed */
box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
animation: fadeInUp 1s ease-in-out; /* Animation */
}
@keyframes fadeInUp {
0% {
opacity: 0;
transform: translateY(20px);
}
100% {
opacity: 1;
transform: translateY(0);
}
}
#loading-spinner {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 1;
transition: opacity 0.5s ease;
display: none;
}
input[type="number"] {
padding: 10px;
font-size: 16px;
border: 1px solid #ccc;
border-radius: 5px;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
transition: border-color 0.3s ease;
}
input[type="number"]:focus {
outline: none;
border-color: #2980b9; /* Change the border color on focus */
}
#verify:hover {
/* background-color: #2980b9; */
/* color:green; */
transform: scale(1.1);
box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
}
button {
padding: 10px 20px;
font-size: 16px;
background-color: #3498db;
color: #fff;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s ease;
}
button:hover {
background-color: #2980b9; /* Change the background color on hover */
transform: scale(1.1);
box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
}
</style>
</head>
<body>
<div class="container">
<div class="logo">
<img src="assets/img/GCU_logo.png" alt="Logo" width="90" height="90">
</div>
<img id="loading-spinner" src="assets/img/GCU_LOGO.gif">
<h2 style="color:black; font-family: 'Lucida Console', Courier, monospace;">FORGOT PASSWORD</h2>
<form id="verify_code" method="post">
<label for="code" style="color:black;">Input 4 digit code*</label>
<input type="number" id="code" name="number" oninput="validateInput(this)" required>
<br>
<br>
<input id="verify"style="background-color:black;color:white;" type="submit" value="Verify">
<br>
<br>
</form>
<button onclick="resend()">Resend Code</button>
</div>
</body>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<script>
function validateInput(input) {
// Get the input value and remove any non-digit characters
let inputValue = input.value.replace(/\D/g, '');
// Limit the input to 4 digits
inputValue = inputValue.slice(0, 4);
// Update the input value
input.value = inputValue;
}
</script>
<script>
function resend(){
// Show loading spinner
Swal.fire({
title: 'Sending Email',
allowOutsideClick: false,
allowEscapeKey: false,
didOpen: () => {
Swal.showLoading();
},
});
$.ajax({
type: 'POST',
url: 'backend/resend.php',
success: function(data) {
// Hide loading spinner on success
swal.close();
Swal.fire({
icon: "sucess",
title: "Code Sent!",
text: "Go to your email to retrieve the code",
confirmButtonText: "OK",
}).then((result) => {
/* Read more about isConfirmed, isDenied below */
if (result.isConfirmed) {
window.location.reload();
}
});
// add location to enter code
},
error: function (xhr, status, error) {
console.error("Error:", error);
alert("Error: " + error);
},
});
}
$("#verify_code").on("submit", function(event) {
event.preventDefault();
console.log("performing ajax");
$.ajax({
type: 'POST',
url: 'backend/verify.php',
data: {
code: $("#code").val()
},
success: function(data) {
if (data === "Code Verified") {
Swal.fire({
icon: "sucess",
title: "Code verified",
confirmButtonText: "OK",
}).then((result) => {
/* Read more about isConfirmed, isDenied below */
if (result.isConfirmed) {
window.location.href = "update_pass.php";
}
});
} else {
// alert('Error, Invalid Code', data);
Swal.fire({
icon: "error",
title: "Invalid Code",
text:"please try again",
confirmButtonText: "OK",
}).then((result) => {
/* Read more about isConfirmed, isDenied below */
if (result.isConfirmed) {
}
});
console.log(data);
}
// add location to enter code
},
error: function (xhr, status, error) {
console.error("Error:", error);
alert("Error: " + error);
},
});
});
</script>
<?php
// unset($_SESSION['random_number']);//it shold clear once used for verification
?>
</html>