mirror of
https://github.com/slawkens/myaac.git
synced 2026-03-16 16:03:31 +01:00
Feature/refactor account lost (#326)
* [WIP] Account Lost refactor * [WIP] Refactor account/lost * Update form.html.twig * Use myaac-table class for tables * Set $title to 'Lost Account' * Remove duplicated code - extract lostAccountCooldown function * [WIP] Add csrfProtect() * Refactor code, better $error messages * Formatting * Refactor Add missing password check Formatting * [WIP] Refactor * [WIP] Refactor account lost * [WIP] Refactor account lost - fixes * [WIP] Account lost refactor * Fixes * Add account lost hooks for password strength plugin
This commit is contained in:
128
system/pages/account/lost/email/set-new-password.php
Normal file
128
system/pages/account/lost/email/set-new-password.php
Normal file
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
defined('MYAAC') or die('Direct access not allowed!');
|
||||
|
||||
csrfProtect();
|
||||
|
||||
$title = 'Lost Account';
|
||||
|
||||
$newPassword = $_POST['password'] ?? '';
|
||||
$passwordRepeat = $_POST['password_repeat'] ?? '';
|
||||
$code = $_POST['code'] ?? '';
|
||||
$character = $_POST['character'] ?? '';
|
||||
|
||||
if(empty($code) || empty($character)) {
|
||||
$errors[] = 'Please enter code from e-mail and name of one character from account.';
|
||||
|
||||
$twig->display('error_box.html.twig', [
|
||||
'errors' => $errors,
|
||||
]);
|
||||
|
||||
$twig->display('account/lost/check-code.html.twig', [
|
||||
'code' => $code,
|
||||
'character' => $character,
|
||||
]);
|
||||
|
||||
$twig->display('account.back_button.html.twig', [
|
||||
'new_line' => true,
|
||||
'center' => true,
|
||||
'action' => getLink('account/lost/check-code')
|
||||
]);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (empty($newPassword) || empty($passwordRepeat)) {
|
||||
$errors[] = 'Please enter both passwords.';
|
||||
|
||||
$twig->display('error_box.html.twig', [
|
||||
'errors' => $errors,
|
||||
]);
|
||||
|
||||
$twig->display('account/lost/check-code.finish.html.twig', [
|
||||
'character' => $character,
|
||||
'code' => $code,
|
||||
]);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$player = new OTS_Player();
|
||||
$account = new OTS_Account();
|
||||
$player->find($character);
|
||||
if($player->isLoaded()) {
|
||||
$account = $player->getAccount();
|
||||
}
|
||||
|
||||
$passwordFailed = false;
|
||||
|
||||
if($account->isLoaded()) {
|
||||
if($account->getCustomField('email_code') == $code) {
|
||||
if ($newPassword == $passwordRepeat) {
|
||||
if (Validator::password($newPassword)) {
|
||||
|
||||
$hooks->trigger(HOOK_ACCOUNT_LOST_EMAIL_SET_NEW_PASSWORD_POST);
|
||||
|
||||
if (empty($errors)) {
|
||||
$tmp_new_pass = $newPassword;
|
||||
if (USE_ACCOUNT_SALT) {
|
||||
$salt = generateRandomString(10, false, true, true);
|
||||
$tmp_new_pass = $salt . $newPassword;
|
||||
$account->setCustomField('salt', $salt);
|
||||
}
|
||||
|
||||
$account->setPassword(encrypt($tmp_new_pass));
|
||||
$account->save();
|
||||
$account->setCustomField('email_code', '');
|
||||
|
||||
$mailBody = $twig->render('mail.account.lost.new-password.html.twig', [
|
||||
'account' => $account,
|
||||
'newPassword' => $newPassword,
|
||||
]);
|
||||
|
||||
$statusMsg = '';
|
||||
if (_mail($account->getCustomField('email'), configLua('serverName') . ' - Your new password', $mailBody)) {
|
||||
$statusMsg = '<br /><small>New password work! Sent e-mail with your password and account name. You should receive this e-mail in 15 minutes. You can login now with new password!';
|
||||
} else {
|
||||
$statusMsg = '<br /><p class="error">New password work! An error occurred while sending email! You will not receive e-mail with new password. For Admin: More info can be found in system/logs/mailer-error.log';
|
||||
}
|
||||
|
||||
$twig->display('account/lost/finish.new-password.html.twig', [
|
||||
'statusMsg' => $statusMsg,
|
||||
'newPassword' => $newPassword,
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
$passwordFailed = true;
|
||||
$errors[] = Validator::getLastError();
|
||||
}
|
||||
}
|
||||
else {
|
||||
$passwordFailed = true;
|
||||
$errors[] = 'Passwords are not the same!';
|
||||
}
|
||||
}
|
||||
else {
|
||||
$errors[] = 'Wrong code to change password.';
|
||||
}
|
||||
}
|
||||
else {
|
||||
$errors[] = "Account of this character or this character doesn't exist.";
|
||||
}
|
||||
|
||||
if(!empty($errors)) {
|
||||
$twig->display('error_box.html.twig', [
|
||||
'errors' => $errors,
|
||||
]);
|
||||
|
||||
echo '<br/>';
|
||||
|
||||
$template = 'account/lost/check-code.html.twig';
|
||||
if($passwordFailed) {
|
||||
$template = 'account/lost/check-code.finish.html.twig';
|
||||
}
|
||||
|
||||
$twig->display($template, [
|
||||
'code' => $code,
|
||||
'character' => $character,
|
||||
]);
|
||||
}
|
||||
Reference in New Issue
Block a user