-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchange-password.php
More file actions
178 lines (155 loc) · 5.89 KB
/
change-password.php
File metadata and controls
178 lines (155 loc) · 5.89 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
<?php
include './components/header.php';
if(!isset($_SESSION['change_pass_email'])) {
?>
<script>
location.href = 'index.php';
</script>
<?php
} else {
unset($_SESSION['forgot_email']);
unset($_SESSION['otp']);
unset($_SESSION['time']);
$email = $_SESSION['change_pass_email'];
}
?>
<style>
body {
background-image: url('assets/img/dental.jpg');
background-attachment: fixed;
background-size: cover;
}
</style>
<section class="mt-5 mx-4">
<!--APPOINTMENT FORM-->
<div class="row d-flex justify-content-center">
<div class="col-sm-10 col-md-8 col-lg-6 col-xl-4">
<form id="change_pass_form" class="p-5 bg-white">
<p class="text-center h1 fw-bold mb-1 mx-1 mx-md-1 mt-2">CHANGE PASSWORD</p>
<!-- Email input -->
<div class="form-outline mb-1">
<label class="form-label" for="form2Example1">Email Address</label>
<input type="email" id="email" name="email" class="form-control" value="<?= $email ?>" readonly/>
</div>
<!-- Password input -->
<div class="form-outline mb-3">
<label class="form-label" for="form2Example1">New Password</label>
<input type="password" id="password" name="password" class="form-control" value="" />
<span class="text-danger error error_password"
style="font-size: 14px; font-weight: 500;"></span>
<!--<label class="form-label" for="form2Example2">Password</label>-->
</div>
<div class="form-outline">
<label class="form-label" for="form2Example1">Confirm Password</label>
<input type="password" id="c_password" name="c_password" class="form-control" value="" />
<span class="text-danger error error_c_password"
style="font-size: 14px; font-weight: 500;"></span>
<!--<label class="form-label" for="form2Example2">Password</label>-->
</div>
<div class="form-outline my-3">
<input type="checkbox" onclick="myFunction()"> Show Password
</div>
<!-- Submit button -->
<button type="submit" class="btn btn-dark btn-block w-100 mb-3" name="change_pass_btn" id="change_pass_btn">SUBMIT</button>
</form>
</div>
</div>
</section>
<script>
function myFunction() {
var x = document.getElementById("password");
var y = document.getElementById("c_password");
if (x.type === "password") {
x.type = "text";
} else {
x.type = "password";
}
if (y.type === "password") {
y.type = "text";
} else {
y.type = "password";
}
}
// VALIDATIONS
var $regexpass = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}$/;
$('#password').on('keypress keydown keyup', function() {
if (!$.trim($(this).val()).match($regexpass)) {
$('.error_password').html('<i class="bi bi-exclamation-circle"></i> Invalid format');
$('#password').addClass('border-danger');
} else {
$('.error_password').text('');
$('#password').removeClass('border-danger');
}
})
$('#c_password').on('keypress keydown keyup', function() {
if (!$.trim($(this).val()).match($regexpass)) {
$('.error_c_password').html('<i class="bi bi-exclamation-circle"></i> Invalid format');
$('#c_password').addClass('border-danger');
} else {
$('.error_c_password').text('');
$('#c_password').removeClass('border-danger');
}
})
// SUBMIT LOGIN
$('#change_pass_form').on('submit', function(e) {
e.preventDefault();
if($('#password').val() != $('#c_password').val()) {
Swal.fire({
icon: 'error',
title: 'Failed',
text: 'The password confirmation does not match!'
});
} else {
var form = new FormData(this);
form.append('change_pass', true);
$.ajax({
type: "POST",
url: "./functions/change-password.php",
data: form,
dataType: 'text',
contentType: false,
cache: false,
processData: false,
beforeSend: function() {
$('#change_pass_btn').prop('disabled', true);
$('#change_pass_btn').text('Processing...');
},
complete: function() {
$('#change_pass_btn').prop('disabled', false);
$('#change_pass_btn').text('SUBMIT');
},
success: function(response) {
if (response.includes('success')) {
Swal.fire({
icon: 'success',
title: 'Password updated successfully! You can now login.',
showDenyButton: true,
confirmButtonText: 'Login',
denyButtonText: 'Cancel',
}).then((result) => {
if (result.isConfirmed) {
location.href = 'login.php';
} else if (result.isDenied) {
location.href = 'index.php';
}
})
} else if (response.includes('invalid')) {
Swal.fire({
icon: 'error',
title: 'Failed',
text: 'Invalid email!'
});
} else {
Swal.fire({
icon: 'error',
title: 'Failed',
text: 'Something went wrong!'
});
}
console.log(response);
}
})
}
})
</script>
<?php include './components/bottom.php'; ?>