-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchange-password.php
135 lines (125 loc) · 5.23 KB
/
change-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
<?php
$title = "Change Password | SN";
include_once("classes/DB.php");
include_once("classes/Login.php");
include_once('assets/templates/header.php');
include_once('assets/templates/navbar.php');
if(!Login::isLoggedin()) {
if(isset($_GET['token'])) {
$token = filter_var($_GET['token'] ,FILTER_SANITIZE_STRING);
$getUser = DB::query("SELECT User_ID FROM password_tokens WHERE Token = ?", array(md5($token)));
if($getUser) { // now you have a valid token
?>
<form class="login">
<h2>Reset Password</h2>
<div class="form-group">
<input type="password" class="form-control" name="newpassword" placeholder="New Password" autofocus />
</div>
<div class="form-group">
<input type="password" class="form-control" name="newpasswordrepeat" placeholder="Repeat New Password" />
</div>
<div class="form-group">
<input type="submit" class="btn btn-sn" name="resetpassword" value="Reset Password" />
<div class="alert alert-success">Password Changed Successfully!<br /><a href="#">Go Profile</a></div>
</div>
</form>
<script type="text/javascript">
$(function () {
"use strict";
$('input[name=resetpassword]').click(function () {
var resetButton = $(this);
$.ajax({
url: "api/?resetForgottenPassword",
type: "POST",
data : {
newpassword: $("input[name=newpassword]").val(),
newpasswordrepeat: $("input[name=newpasswordrepeat]").val(),
userid: <?= $getUser[0]['User_ID'] ?>
},
success: function () {
resetButton.next().fadeIn();
},
error: function (r) {
resetButton.addClass('shake');
setTimeout(function() {
resetButton.removeClass('shake');
}, 600);
$('form').trigger('reset');
console.log(r);
}
});
});
});
</script>
<?php
} else {
header("location:index.php");
die("invalid token");
}
} else {
header("location:index.php");
die("not loggedin");
}
} else {
?>
<form class="login">
<h2>Change Password</h2>
<div class="form-group">
<input type="password" class="form-control" name="oldpassword" placeholder="Old Password" autofocus />
</div>
<div class="form-group">
<input type="password" class="form-control" name="newpassword" placeholder="New Password" />
</div>
<div class="form-group">
<input type="password" class="form-control" name="newpasswordrepeat" placeholder="Repeat New Password" />
</div>
<div class="form-group">
<input type="submit" class="btn btn-sn" name="changepassword" value="Change Password" />
<div class="alert alert-success changepassword-alert">Password Changed Successfully!</div>
</div>
</form>
<script type="text/javascript">
$("input[name=changepassword]").click(function () {
var changeButton = $(this);
$.ajax({
url: "api/?changepassword",
type: "POST",
data: {
oldpassword: $("input[name=oldpassword]").val(),
newpassword: $("input[name=newpassword]").val(),
newpasswordrepeat: $("input[name=newpasswordrepeat]").val()
},
success: function (r) {
changeButton.next().fadeIn();
$("form").trigger('reset');
// logut from all devieces
setTimeout(function () {
$.ajax({
url: "api/?logout",
type: "POST",
data : {
alldevices: 'TRUE'
},
success: function () {
location.reload();
},
error: function (r) {
console.log(r);
}
});
}, 600);
},
error: function (r) {
changeButton.addClass('shake');
setTimeout(function() {
changeButton.removeClass('shake');
}, 600);
$('form').trigger('reset');
console.log(r);
}
});
});
</script>
<?php
}
include_once('assets/templates/footer.php');