forked from userfrosting/UserFrosting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_resend_activation.php
188 lines (163 loc) · 5.38 KB
/
user_resend_activation.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
<?php
/*
UserFrosting Version: 0.1
By Alex Weissman
Copyright (c) 2014
Based on the UserCake user management system, v2.0.2.
Copyright (c) 2009-2012
UserFrosting, like UserCake, is 100% free and open-source.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the 'Software'), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
// Resend the activation email for a user that has registered an account. Note that this is enabled regardless of whether or not email activation is enabled.
// This is to prevent "orphaned" accounts, who registered while email activation was still required.
// Request method: POST
require_once("models/config.php");
set_error_handler('logAllErrors');
if (!securePage($_SERVER['PHP_SELF'])){
addAlert("danger", "Whoops, looks like you don't have permission to resend activation.");
if (isset($_POST['ajaxMode']) and $_POST['ajaxMode'] == "true" ){
echo json_encode(array("errors" => 1, "successes" => 0));
} else {
header("Location: " . getReferralPage());
}
exit();
}
//Prevent the user visiting the logged in page if he/she is already logged in
if(isUserLoggedIn()) {
addAlert("danger", "I'm sorry, you cannot register for an account while logged in. Please log out first.");
if (isset($_POST['ajaxMode']) and $_POST['ajaxMode'] == "true" ){
echo json_encode(array("errors" => 1, "successes" => 0));
} else {
header("Location: account.php");
}
exit();
}
//Forms posted
if(!empty($_POST))
{
$email = $_POST["email"];
$username = $_POST["username"];
//Perform some validation
//Feel free to edit / change as required
if(trim($email) == "")
{
$errors[] = lang("ACCOUNT_SPECIFY_EMAIL");
}
//Check to ensure email is in the correct format / in the db
else if(!isValidEmail($email) || !emailExists($email))
{
$errors[] = lang("ACCOUNT_INVALID_EMAIL");
}
if(trim($username) == "")
{
$errors[] = lang("ACCOUNT_SPECIFY_USERNAME");
}
else if(!usernameExists($username))
{
$errors[] = lang("ACCOUNT_INVALID_USERNAME");
}
if(count($errors) == 0)
{
//Check that the username / email are associated to the same account
if(!emailUsernameLinked($email,$username))
{
$errors[] = lang("ACCOUNT_USER_OR_EMAIL_INVALID");
}
else
{
$userdetails = fetchUserDetails($username);
//See if the user's account is activation
if($userdetails["active"]==1)
{
$errors[] = lang("ACCOUNT_ALREADY_ACTIVE");
}
else
{
if ($resend_activation_threshold == 0) {
$hours_diff = 0;
}
else {
$last_request = $userdetails["last_activation_request"];
$hours_diff = round((time()-$last_request) / (3600*$resend_activation_threshold),0);
}
if($resend_activation_threshold!=0 && $hours_diff <= $resend_activation_threshold)
{
$errors[] = lang("ACCOUNT_LINK_ALREADY_SENT",array($resend_activation_threshold));
}
else
{
//For security create a new activation url;
$new_activation_token = generateActivationToken();
if(!updateLastActivationRequest($new_activation_token,$username,$email))
{
$errors[] = lang("SQL_ERROR");
}
else
{
$mail = new userCakeMail();
$activation_url = $websiteUrl."activate_account.php?token=".$new_activation_token;
//Setup our custom hooks
$hooks = array(
"searchStrs" => array("#ACTIVATION-URL","#USERNAME#"),
"subjectStrs" => array($activation_url,$userdetails["display_name"])
);
if(!$mail->newTemplateMsg("resend-activation.txt",$hooks))
{
$errors[] = lang("MAIL_TEMPLATE_BUILD_ERROR");
}
else
{
if(!$mail->sendMail($userdetails["email"],"Activate your ".$websiteName." Account"))
{
$errors[] = lang("MAIL_ERROR");
}
else
{
//Success, user details have been updated in the db now mail this information out.
$successes[] = lang("ACCOUNT_NEW_ACTIVATION_SENT");
}
}
}
}
}
}
}
} else {
$errors[] = lang("NO_DATA");
}
restore_error_handler();
foreach ($errors as $error){
addAlert("danger", $error);
}
foreach ($successes as $success){
addAlert("success", $success);
}
if (isset($_POST['ajaxMode']) and $_POST['ajaxMode'] == "true" ){
echo json_encode(array(
"errors" => count($errors),
"successes" => count($successes)));
} else {
// Send successes to the home page, while errors should return them to the activation page.
if(count($errors) == 0) {
header('Location: index.php');
exit();
} else {
header('Location: resend_activation.php');
exit();
}
}
?>