forked from corgus/eas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
forgotpassword.php
160 lines (119 loc) · 4.06 KB
/
forgotpassword.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
<?php
/*
Template Name: Forgot Password
*/
?>
<?php
$v = 0;
$new = false;
if (!empty($_GET['new'])) {
$new = true;
}
if (isset($_POST['reset'])) {
$email = trim($_POST['user_email']);
$v = 2;
if (is_email($email)) {
$reset_user = get_user_by('email', $_POST['user_email']);
if ($reset_user !== false) {
$v_from_db = get_user_meta($reset_user->ID,'pwreset',true);
if (trim($v_from_db) == trim($_POST['v'])) {
wp_update_user(array(
'ID' => $reset_user->ID,
'user_pass' => $_POST['new_pass']
));
delete_user_meta($reset_user->ID, 'pwreset');
wp_set_auth_cookie($reset_user->ID);
if ($new) {
$action = 'register';
} else {
$action = 'passreset';
}
wp_redirect(get_bloginfo('siteurl').'?action='.$action);
exit;
} else {
$_GET['action'] = 'invalidreset';
}
} else {
$_GET['action'] = 'invalidreset';
}
} else {
$_GET['action'] = 'invalidemail';
}
} else if (isset($_POST['user_email'])) {
if (is_email($_POST['user_email'])) {
$reset_user = get_user_by('email',$_POST['user_email']);
if ($reset_user !== false) {
if (eas_do_pass_reset_email($reset_user->ID, $_POST['user_email'], true)) {
$_GET['action'] = 'emailsent';
} else {
$_GET['action'] = 'couldnotreset';
}
}
} else {
$_GET['action'] = 'notemail';
}
} else if (isset($_GET['v'])) {
$v = 1;
}
?>
<?php get_header(); ?>
<?php roots_content_before(); ?>
<div id="content" class="<?php echo CONTAINER_CLASSES; ?>">
<?php roots_main_before(); ?>
<div id="main" class="<?php echo FULLWIDTH_CLASSES; ?>" role="main">
<?php roots_loop_before(); ?>
<?php get_template_part('loop', 'page'); ?>
<?php roots_loop_after(); ?>
<?php if (!is_user_logged_in()) { ?>
<?php if (!$v) { ?>
<p>Enter the email address you used to register for this site and we'll email a link that will enable you to reset your password.</p>
<form class="form-inline" method="post" action="">
<input type="email" name="user_email">
<input class="btn btn-primary" type="submit" value="Send Password Reset Email">
</form>
<?php } else if ($v == 1) { ?>
<?php
if (!$new) {
?>
<p>Please enter your email address (just to double-check it's really you!) and your desired new password.</p>
<?php
} else {
?>
<p>Welcome! Enter the email address this link was sent to and your desired password and you can start exploring.</p>
<?php
}
?>
<form method="post" action="" autocomplete="off">
<?php
if ($new) {
?>
<input type="hidden" name="new" value="1">
<?php
}
?>
<input type="hidden" name="reset" value="1">
<input type="hidden" name="v" value="<?php echo urlencode($_GET['v']); ?>">
<p><input type="email" name="user_email" placeholder="email address"></p>
<p><input type="password" name="new_pass" placeholder="new password"></p>
<p><input class="btn btn-primary" type="submit" value="Reset Password"></p>
</form>
<?php } else { ?>
<p>You are already logged in.</p>
<?php } ?>
<?php } else {
if ($new) {
?>
<p>You must <a href="/login?action=logout&redirect=<?php echo $_SERVER['REQUEST_URI']; ?>" title="Log Out">log out</a> before activating your new account.</p>
<?php
} else {
?>
<p>You must <a href="/login?action=logout&redirect=<?php echo $_SERVER['REQUEST_URI']; ?>">log out</a> to recover your password.</p>
<?php
}
}
?>
</div><!-- /#main -->
<?php roots_main_after(); ?>
</div><!-- /#content -->
<?php roots_content_after(); ?>
<?php get_footer(); ?>