|
@@ -37,16 +37,13 @@ if (check_perms('site_advanced_search')) {
|
37
|
37
|
$Val->SetFields('searchtype', 1, "number", "You forgot to select your default search preference.", ['minlength' => 0, 'maxlength' => 1]);
|
38
|
38
|
}
|
39
|
39
|
|
40
|
|
-$Err = $Val->ValidateForm($_POST);
|
41
|
|
-
|
42
|
|
-if (!apcu_exists('DBKEY')) {
|
43
|
|
- $Err = "Cannot edit profile until database fully decrypted.";
|
|
40
|
+$ValErr = $Val->ValidateForm($_POST);
|
|
41
|
+if ($ValErr) {
|
|
42
|
+ error($ValErr);
|
44
|
43
|
}
|
45
|
44
|
|
46
|
|
-if ($Err) {
|
47
|
|
- error($Err);
|
48
|
|
- header("Location: user.php?action=edit&userid=$UserID");
|
49
|
|
- die();
|
|
45
|
+if (!apcu_exists('DBKEY')) {
|
|
46
|
+ error("Cannot edit profile until database fully decrypted");
|
50
|
47
|
}
|
51
|
48
|
|
52
|
49
|
// Begin building $Paranoia
|
|
@@ -136,121 +133,96 @@ if (isset($_POST['p_donor_stats'])) {
|
136
|
133
|
|
137
|
134
|
// End building $Paranoia
|
138
|
135
|
|
139
|
|
-
|
140
|
|
-// Email change
|
141
|
136
|
$DB->query("
|
142
|
|
- SELECT Email
|
|
137
|
+ SELECT Email, PassHash, TwoFactor, PublicKey, IRCKey
|
143
|
138
|
FROM users_main
|
144
|
139
|
WHERE ID = $UserID");
|
145
|
|
-list($CurEmail) = $DB->next_record();
|
|
140
|
+list($CurEmail, $CurPassHash, $CurTwoFA, $CurPublicKey, $CurIRCKey) = $DB->next_record();
|
|
141
|
+
|
|
142
|
+function require_password($Setting = false) {
|
|
143
|
+ global $CurPassHash;
|
|
144
|
+ if (empty($_POST['cur_pass'])) {
|
|
145
|
+ error('A setting you changed requires you to enter your current password'.($Setting ? ' (Setting: '.$Setting.')' : ''));
|
|
146
|
+ }
|
|
147
|
+ if (!Users::check_password($_POST['cur_pass'], $CurPassHash)) {
|
|
148
|
+ error('The password you entered was incorrect'.($Setting ? ' (Required by setting: '.$Setting.')' : ''));
|
|
149
|
+ }
|
|
150
|
+}
|
|
151
|
+
|
|
152
|
+// Email change
|
146
|
153
|
$CurEmail = DBCrypt::decrypt($CurEmail);
|
147
|
154
|
if ($CurEmail != $_POST['email']) {
|
148
|
|
- if (!check_perms('users_edit_profiles')) { // Non-admins have to authenticate to change email
|
149
|
|
- $DB->query("
|
150
|
|
- SELECT PassHash
|
151
|
|
- FROM users_main
|
152
|
|
- WHERE ID = '".db_string($UserID)."'");
|
153
|
|
- list($PassHash)=$DB->next_record();
|
154
|
|
- if (!Users::check_password($_POST['cur_pass'], $PassHash)) {
|
155
|
|
- $Err = 'You did not enter the correct password.';
|
156
|
|
- }
|
|
155
|
+
|
|
156
|
+ // Non-admins have to authenticate to change email
|
|
157
|
+ if (!check_perms('users_edit_profiles')) {
|
|
158
|
+ require_password("Change Email");
|
157
|
159
|
}
|
158
|
|
- if (!$Err) {
|
159
|
|
- $NewEmail = db_string($_POST['email']);
|
160
|
160
|
|
|
161
|
+ $NewEmail = db_string($_POST['email']);
|
161
|
162
|
|
162
|
|
- //This piece of code will update the time of their last email change to the current time *not* the current change.
|
163
|
|
- $ChangerIP = db_string($LoggedUser['IP']);
|
164
|
|
- $DB->query("
|
165
|
|
- UPDATE users_history_emails
|
166
|
|
- SET Time = '".sqltime()."'
|
167
|
|
- WHERE UserID = '$UserID'
|
168
|
|
- AND Time IS NULL");
|
169
|
|
- $DB->query("
|
170
|
|
- INSERT INTO users_history_emails
|
171
|
|
- (UserID, Email, Time, IP)
|
172
|
|
- VALUES
|
173
|
|
- ('$UserID', '".DBCrypt::encrypt($NewEmail)."', NULL, '".DBCrypt::encrypt($_SERVER['REMOTE_ADDR'])."')");
|
|
163
|
+ // Update the time of their last email change to the current time *not* the current change.
|
|
164
|
+ $ChangerIP = db_string($LoggedUser['IP']);
|
|
165
|
+ $DB->query("
|
|
166
|
+ UPDATE users_history_emails
|
|
167
|
+ SET Time = '".sqltime()."'
|
|
168
|
+ WHERE UserID = '$UserID'
|
|
169
|
+ AND Time IS NULL");
|
|
170
|
+ $DB->query("
|
|
171
|
+ INSERT INTO users_history_emails
|
|
172
|
+ (UserID, Email, Time, IP)
|
|
173
|
+ VALUES
|
|
174
|
+ ('$UserID', '".DBCrypt::encrypt($NewEmail)."', NULL, '".DBCrypt::encrypt($_SERVER['REMOTE_ADDR'])."')");
|
174
|
175
|
|
175
|
|
- } else {
|
176
|
|
- error($Err);
|
177
|
|
- header("Location: user.php?action=edit&userid=$UserID");
|
178
|
|
- die();
|
179
|
|
- }
|
180
|
176
|
}
|
181
|
|
-//End email change
|
182
|
177
|
|
183
|
|
-//2FA activation
|
184
|
|
-if (!empty($_POST['twofa'])) {
|
|
178
|
+// PGP Key
|
|
179
|
+if ($CurPublicKey != $_POST['publickey']) {
|
|
180
|
+ require_password("Change Public Key");
|
185
|
181
|
$DB->query("
|
186
|
|
- SELECT TwoFactor, PassHash
|
187
|
|
- FROM users_main
|
|
182
|
+ UPDATE users_main
|
|
183
|
+ SET PublicKey = '".db_string($_POST['publickey'])."'
|
188
|
184
|
WHERE ID = $UserID");
|
189
|
|
- list($TwoFactor, $PassHash) = $DB->next_record();
|
190
|
|
- if (empty($TwoFactor)) {
|
191
|
|
- if (!Users::check_password($_POST['cur_pass'], $PassHash)) {
|
192
|
|
- error('You did not enter the correct password.');
|
193
|
|
- header("Location: user.php?action=edit&userid=$UserID");
|
194
|
|
- die();
|
195
|
|
- }
|
196
|
|
- require_once SERVER_ROOT.'/classes/twofa.class.php';
|
197
|
|
- $TwoFA = new TwoFactorAuth(SITE_NAME);
|
198
|
|
- if ($TwoFA->verifyCode($_POST['twofasecret'], $_POST['twofa'])) {
|
199
|
|
- $DB->query("
|
200
|
|
- UPDATE users_main
|
201
|
|
- SET TwoFactor='".db_string($_POST['twofasecret'])."'
|
202
|
|
- WHERE ID = $UserID");
|
203
|
|
- } else {
|
204
|
|
- error('Invalid 2FA verification code.');
|
205
|
|
- header("Location: user.php?action=edit&userid=$UserID");
|
206
|
|
- die();
|
207
|
|
- }
|
|
185
|
+}
|
|
186
|
+
|
|
187
|
+// 2FA activation
|
|
188
|
+if (!empty($_POST['twofa']) && empty($CurTwoFA)) {
|
|
189
|
+ require_password("Enable 2-Factor");
|
|
190
|
+ require_once SERVER_ROOT.'/classes/twofa.class.php';
|
|
191
|
+ $TwoFA = new TwoFactorAuth(SITE_NAME);
|
|
192
|
+ if ($TwoFA->verifyCode($_POST['twofasecret'], $_POST['twofa'])) {
|
|
193
|
+ $DB->query("
|
|
194
|
+ UPDATE users_main
|
|
195
|
+ SET TwoFactor='".db_string($_POST['twofasecret'])."'
|
|
196
|
+ WHERE ID = $UserID");
|
|
197
|
+ } else {
|
|
198
|
+ error('Invalid 2FA verification code.');
|
208
|
199
|
}
|
209
|
200
|
}
|
210
|
201
|
|
211
|
|
-//2FA deactivation
|
|
202
|
+// 2FA deactivation
|
212
|
203
|
if (isset($_POST['disable2fa'])) {
|
213
|
|
- $DB->query("
|
214
|
|
- SELECT PassHash
|
215
|
|
- FROM users_main
|
216
|
|
- WHERE ID = $UserID");
|
217
|
|
- list($PassHash) = $DB->next_record();
|
218
|
|
- if (!Users::check_password($_POST['cur_pass'], $PassHash)) {
|
219
|
|
- error('You did not enter the correct password.');
|
220
|
|
- header("Location: user.php?action=edit&userid=$UserID");
|
221
|
|
- die();
|
222
|
|
- }
|
|
204
|
+ require_password("Disable 2-Factor");
|
223
|
205
|
$DB->query("
|
224
|
206
|
UPDATE users_main
|
225
|
|
- SET TwoFactor=NULL
|
|
207
|
+ SET TwoFactor = NULL
|
226
|
208
|
WHERE ID = $UserID");
|
227
|
209
|
}
|
228
|
|
-//End 2FA
|
229
|
210
|
|
230
|
|
-if (!$Err && ($_POST['cur_pass'] || $_POST['new_pass_1'] || $_POST['new_pass_2'])) {
|
231
|
|
- $DB->query("
|
232
|
|
- SELECT PassHash
|
233
|
|
- FROM users_main
|
234
|
|
- WHERE ID = '".db_string($UserID)."'");
|
235
|
|
- list($PassHash) = $DB->next_record();
|
236
|
|
-
|
237
|
|
- if (Users::check_password($_POST['cur_pass'], $PassHash)) {
|
238
|
|
- if ($_POST['new_pass_1'] && $_POST['new_pass_2']) {
|
239
|
|
- $ResetPassword = true;
|
240
|
|
- }
|
241
|
|
- } else {
|
242
|
|
- $Err = 'You did not enter the correct password.';
|
243
|
|
- }
|
|
211
|
+if (!empty($_POST['new_pass_1']) && !empty($_POST['new_pass_2'])) {
|
|
212
|
+ require_password("Change Password");
|
|
213
|
+ $ResetPassword = true;
|
244
|
214
|
}
|
245
|
215
|
|
246
|
|
-if ($LoggedUser['DisableAvatar'] && $_POST['avatar'] != $U['Avatar']) {
|
247
|
|
- $Err = 'Your avatar privileges have been revoked.';
|
|
216
|
+if ($CurIRCKey != $_POST['irckey']) {
|
|
217
|
+ require_password("Change IRC Key");
|
248
|
218
|
}
|
249
|
219
|
|
250
|
|
-if ($Err) {
|
251
|
|
- error($Err);
|
252
|
|
- header("Location: user.php?action=edit&userid=$UserID");
|
253
|
|
- die();
|
|
220
|
+if (isset($_POST['resetpasskey'])) {
|
|
221
|
+ require_password("Reset Passkey");
|
|
222
|
+}
|
|
223
|
+
|
|
224
|
+if ($LoggedUser['DisableAvatar'] && $_POST['avatar'] != $U['Avatar']) {
|
|
225
|
+ error('Your avatar privileges have been revoked.');
|
254
|
226
|
}
|
255
|
227
|
|
256
|
228
|
if (!empty($LoggedUser['DefaultSearch'])) {
|