-
Notifications
You must be signed in to change notification settings - Fork 1
/
reset-password.php
282 lines (256 loc) · 12.1 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
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
<?php include_once 'head.php';
session_start();
?>
<link rel="stylesheet" type="text/css" href="assets/libs/bootstrap-validator/css/bootstrapValidator.css">
<link rel="stylesheet" type="text/css" href="assets/libs/lobibox/css/lobibox.min.css">
<style type="text/css">
.form-control {
height: 42px;
border-radius: 5px;
box-shadow: none;
font-family: sans-serif;
}
</style>
<body onload="preloader();">
<?php
if (!isset($_GET['t']) || empty($_GET['t'])) {
$prevUrl = empty($_SERVER['HTTP_REFERER']) ? 'index.php' : $_SERVER['HTTP_REFERER'];
$_SESSION['error'] = 'Please login';
header('Location: '.$prevUrl);
}else {
$token = $_GET['t'];
include_once 'api/config/database.php';
include_once 'api/classes/User.php';
include_once 'api/classes/Student.php';
include_once 'api/classes/Lecturer.php';
$conn = Database::getInstance();
$user = new User($conn);
$user->setToken($token);
$phone = '';
if ($user->verifyToken()){
if ($user->getLevel() == 3) {
$student = new Student($conn);
$student->setRegNo($user->getUsername());
$studentDetails = $student->getUser();
$phone = $student->getUser()['phone_no'];
$uploadDir = 'student/assets/images/users/';
$image = empty($studentDetails['profile']) ? $uploadDir.'avatar-st.png': $uploadDir. $studentDetails['profile'];
if (!file_exists($image)){
$image = $uploadDir.'avatar-st.png';
}
}else{
$lecturer = new Lecturer($conn);
$lecturer->setUsername($user->getUsername());
$lecDetails = $lecturer->getUser();
$uploadDir = 'coordinator/assets/images/users/';
$image = empty($lecDetails['profile']) ? $uploadDir.'avatar-lec.png': $uploadDir. $lecDetails['profile'];
if (!file_exists($image)){
$image = $uploadDir.'avatar-lec.png';
}
}
}else{
header('Location: confirm-username.php');
die();
}
}
?>
<!-- preloader -->
<div class="la-anim-1"></div>
<div class="account-pages mt-3 pt-5">
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8 col-lg-6 col-xl-5">
<div class="card overflow-hidden">
<div class="bg-primary">
<div class="text-primary text-center p-4">
<h5 class="text-white font-size-20">Set Password</h5>
<p class="text-white-50">Hello <?= $user->getUsername() ?>, enter your new password!</p>
<a href="javascript:void(0)" class="logo logo-admin">
<img src="<?= $image ?>" class="rounded-circle" height="70" alt="logo">
</a>
</div>
</div>
<div class="card-body p-4">
<div class="p-3">
<form class="form-horizontal mt-3 password-form">
<div class="form-group">
<label for="otp">OTP Code</label>
<input type="text" class="form-control" id="otp" name="otp"placeholder="Enter the code sent to your phone number">
<div class="text-right">
<a href="javascript:void(0)" class="text-underline" onclick="sendMsg()">resend code</a>
</div>
</div>
<div class="form-group">
<label for="userpassword">Password</label>
<input type="password" class="form-control" id="userpassword" name="password"placeholder="Enter password">
</div>
<div class="form-group">
<label for="cpassword">Confirm Password</label>
<input type="password" class="form-control" id="cpassword" name="repeat-password" placeholder="Confirm your password">
</div>
<div class="form-group row mb-0">
<div class="col-12 text-right">
<button class="btn btn-primary w-md waves-effect waves-light p-b-8 p-t-8" type="submit" id="btn-save">Save Password</button>
</div>
</div>
</form>
</div>
</div>
</div>
<div class="mt-3 text-center">
<p>Not you ? return <a href="index.php" class="font-weight-medium text-primary"> Sign In </a> </p>
<p class="mb-0 text-success">© <script>document.write(new Date().getFullYear())</script> FYPMS.
</div>
</div>
</div>
</div>
</div>
<!-- JAVASCRIPT -->
<script src="assets/libs/jquery/jquery.min.js"></script>
<script src="assets/libs/bootstrap/js/bootstrap.bundle.min.js"></script>
<script type="text/javascript" src="assets/libs/bootstrap-validator/js/bootstrapValidator.min.js"></script>
<script src="assets/libs/metismenu/metisMenu.min.js"></script>
<script src="assets/libs/simplebar/simplebar.min.js"></script>
<script src="assets/libs/node-waves/waves.min.js"></script>
<script type="text/javascript" src="assets/libs/lobibox/js/lobibox.min.js"></script>
<script src="assets/js/app.js"></script>
</body>
</html>
<script type="text/javascript">
let inProgress = false;
let preloader = function() {
if (inProgress) return false;
inProgress = true;
$('.account-pages').css({
'opacity': '0.5',
'pointer-events': 'none'
});
$('.account-pages').addClass('disabled');
$('.la-anim-1').addClass('la-animate')
setTimeout(function() {
$('.account-pages').css({
opacity: '1',
'pointer-events': 'auto'
});
$('.account-pages').removeClass('disabled');
$('.la-anim-1').removeClass('la-animate');
inProgress = false;
Lobibox.notify('success', {
position: 'top right',
// delayIndicator: false,
icon: 'fa fa-check',
msg: 'Your code was successfully sent to your phone number and email'
});
}, 1800);
}
function sendMsg(){
$('#btn-save').prop('disabled', true).html('<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span> Loading...')
$name = '<?= $user->getUsername() ?>'
$.post('api/signup.php', {name: $name}, function(data, textStatus, xhr) {
console.log(data);
if (typeof data['success']['message'] != 'undefined') {
let token = data['success']['message']
if (token != '') {
Lobibox.notify('success', {
position: 'top right',
// delayIndicator: false,
icon: 'fa fa-check',
msg: 'Your code was successfully sent to your phone number and email'
});
}
}
}).fail(function(data){
console.log(data);
let message = typeof data['responseJSON']['error']['message'] != 'undefined'? data['responseJSON']['error']['message'] : 'Some unexpected error occured';
Swal.fire({
title: "Sorry!",
text: message,
showClass: {popup: 'animated fadeInDown faster'},
hideClass: {popup: 'animated fadeOutUp faster'},
icon: "error",
confirmButtonColor: "#025",
})
}).always(()=>{
$('#btn-save').prop('disabled', false).html('Save Password')
});
}
$(document).ready(function() {
$('.password-form').on('submit', function(event) {
event.preventDefault();
});
$('.password-form').bootstrapValidator({
message: 'This value is not valid',
feedbackIcons: {
valid: 'fa fa-check',
invalid: 'fa fa-times',
validating: 'fa fa-refresh'
},
fields:{
'otp':{
excluded: 'false',
validators:{
notEmpty: {
message: 'Please provide a code sent to your phone.'
}
}
},
'password':{
excluded: 'false',
validators:{
notEmpty: {
message: 'Please provide a password to login.'
},
identical: {
field: 'repeat-password',
message: 'The two passwords are not the same'
}
}
},
'repeat-password':{
excluded: 'false',
validators:{
notEmpty: {
message: 'Please provide a password to login.'
},
identical: {
field: 'password',
message: 'The two passwords are not the same'
}
}
}
},
onSuccess: function (e,data) {
$form = $(e.target);
$('#btn-save').prop('disabled', true).html('<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span> Loading...')
$form = $(e.target);
$pass = $.trim($('input[name="password"]').val())
$otp = $.trim($('input[name="otp"]').val())
$token = '<?php echo $token ?>';
$.post('api/ResetPassword.php', {token: $token,otp: $otp,password: $pass}, function(data, textStatus, xhr) {
if (typeof data.success.message != 'undefined') {
Lobibox.notify('success', {
position: 'top right',
// delayIndicator: false,
icon: 'fa fa-check',
msg: data.success.message
});
}
}).fail(function(data){
console.log(data);
let message = typeof data['responseJSON']['error']['message'] != 'undefined'? data['responseJSON']['error']['message'] : 'Some unexpected error occured';
Lobibox.notify('error', {
position: 'top right',
// delayIndicator: false,
icon: 'fa fa-times',
msg: message
});
}).always(()=>{$('#btn-save').prop('disabled', false).html('Save Password')});
$form
.bootstrapValidator('disableSubmitButtons', false)
.bootstrapValidator('resetForm', true);
}
}).on('status.field.bv', function(e, data) {
data.bv.disableSubmitButtons(false);
});
});
</script>