-
Notifications
You must be signed in to change notification settings - Fork 0
/
processreset.php
69 lines (42 loc) · 2.08 KB
/
processreset.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
<?php session_start();
require_once('functions/user.php');
require_once('functions/alert.php');
require_once('functions/redirect.php');
//Collecting the data
$errorCount = 0;
if(!is_user_loggedIn()){
$token = $_POST['token'] != "" ? $_POST['token'] : $errorCount++;
$_SESSION['token'] = $token;
}
$email = $_POST['email'] != "" ? $_POST['email'] : $errorCount++;
$password = $_POST['password'] != "" ? $_POST['password'] : $errorCount++;
$_SESSION['email'] = $email;
if($errorCount > 0){
$session_error = "You have " . $errorCount . " error";
if($errorCount > 1) {
$session_error .= "s";
}
$session_error .= " in your form submission";
set_alert('error',$session_error);
redirect_to("reset.php");
}else{
$checkToken = is_user_loggedIn() ? true : find_token($email);
if($checkToken){
$userExists = find_user($email);
if($userExists){
$userObject = find_user($email);
$userObject->password = password_hash($password, PASSWORD_DEFAULT);
unlink("db/users/".$currentUser); //file delete, user data delete
unlink("db/token/".$currentUser); //file delete, token data delete
save_user($userObject);
set_alert('message',"Password Reset Successful, you can now login ");
$subject = "Password Reset Successful";
$message = "Your account on snh has just been updated, your password has changed. if you did not initiate the password change, please visit snh.org and reset your password immediatly";
send_mail($subject,$message,$email);
redirect_to("login.php");
return;
}
}
set_alert('error',"Password Reset Failed, token/email invalid or expired");
redirect_to("login.php");
}