mirror of
https://github.com/slawkens/myaac.git
synced 2025-10-14 01:34:55 +02:00
Refactor code, better $error messages
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
<?php
|
||||
defined('MYAAC') or die('Direct access not allowed!');
|
||||
|
||||
function lostAccountCooldown(string $nick, int $time): string
|
||||
function lostAccountWriteCooldown(string $nick, int $time): void
|
||||
{
|
||||
global $twig;
|
||||
|
||||
$inSec = $time - time();
|
||||
$minutesLeft = floor($inSec / 60);
|
||||
$secondsLeft = $inSec - ($minutesLeft * 60);
|
||||
@@ -10,5 +12,7 @@ function lostAccountCooldown(string $nick, int $time): string
|
||||
|
||||
$timeRounded = ceil(setting('core.mail_lost_account_interval') / 60);
|
||||
|
||||
return "Account of selected character (<b>" . escapeHtml($nick) . "</b>) received e-mail in last $timeRounded minutes. You must wait $timeLeft before you can use Lost Account Interface again.";
|
||||
$twig->display('error_box.html.twig', [
|
||||
'errors' => ["Account of selected character (<b>" . escapeHtml($nick) . "</b>) received e-mail in last $timeRounded minutes. You must wait $timeLeft before you can use Lost Account Interface again."]
|
||||
]);
|
||||
}
|
||||
|
@@ -32,7 +32,11 @@ if($account->isLoaded()) {
|
||||
$account->setCustomField('email_code', $newCode);
|
||||
$account->setCustomField('email_next', (time() + setting('core.mail_lost_account_interval')));
|
||||
|
||||
echo '<br />Details about steps required to recover your account has been sent to <b>' . $accountEMail . '</b>. You should receive this email within 15 minutes. Please check your inbox/spam directory.';
|
||||
$twig->display('success.html.twig', [
|
||||
'title' => 'Email has been sent',
|
||||
'description' => 'Details about steps required to recover your account has been sent to <b>' . $accountEMail . '</b>. You should receive this email within 15 minutes. Please check your inbox/spam directory.',
|
||||
'custom_buttons' => '',
|
||||
]);
|
||||
}
|
||||
else {
|
||||
$account->setCustomField('email_next', (time() + 60));
|
||||
@@ -40,19 +44,25 @@ if($account->isLoaded()) {
|
||||
}
|
||||
}
|
||||
else {
|
||||
echo 'Invalid e-mail to account of character <b>' . htmlspecialchars($nick) . '</b>. Try again.';
|
||||
$errors[] = 'Invalid e-mail to account of character <b>' . escapeHtml($nick) . '</b>. Try again.';
|
||||
}
|
||||
}
|
||||
else {
|
||||
echo lostAccountCooldown($nick, (int)$account->getCustomField('email_next'));
|
||||
lostAccountWriteCooldown($nick, (int)$account->getCustomField('email_next'));
|
||||
}
|
||||
}
|
||||
else {
|
||||
echo "Player or account of player <b>" . htmlspecialchars($nick) . "</b> doesn't exist.";
|
||||
$errors[] = "Player or account of player <b>" . escapeHtml($nick) . "</b> doesn't exist.";
|
||||
}
|
||||
|
||||
if (!empty($errors)) {
|
||||
$twig->display('error_box.html.twig', [
|
||||
'errors' => $errors,
|
||||
]);
|
||||
}
|
||||
|
||||
$twig->display('account.back_button.html.twig', [
|
||||
'new_line' => true,
|
||||
'center' => true,
|
||||
'action' => getLink('account/lost') . '?action=step1&action_type=email&nick=' . urlencode($nick),
|
||||
'action' => getLink('account/lost/step-1') . '?action=email&nick=' . urlencode($nick),
|
||||
]);
|
||||
|
@@ -10,67 +10,71 @@ $code = $_REQUEST['code'];
|
||||
$character = stripslashes($_REQUEST['character']);
|
||||
|
||||
if(empty($code) || empty($character) || empty($newPassword)) {
|
||||
echo '<span style="color: red"><b>Error. Try again.</b></span><br/>Please enter code from e-mail and name of one character from account. Then press Submit.<br>';
|
||||
$errors[] = 'Please enter code from e-mail and name of one character from account. Then press Submit.';
|
||||
|
||||
$twig->display('error_box.html.twig', [
|
||||
'errors' => $errors,
|
||||
]);
|
||||
|
||||
$twig->display('account.back_button.html.twig', [
|
||||
'new_line' => true,
|
||||
'center' => true,
|
||||
'action' => getLink('account/lost/check-code')
|
||||
]);
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
$player = new OTS_Player();
|
||||
$account = new OTS_Account();
|
||||
$player->find($character);
|
||||
if($player->isLoaded()) {
|
||||
$account = $player->getAccount();
|
||||
}
|
||||
|
||||
if($account->isLoaded()) {
|
||||
if($account->getCustomField('email_code') == $code) {
|
||||
if(Validator::password($newPassword)) {
|
||||
$tmp_new_pass = $newPassword;
|
||||
if(USE_ACCOUNT_SALT) {
|
||||
$salt = generateRandomString(10, false, true, true);
|
||||
$tmp_new_pass = $salt . $newPassword;
|
||||
$account->setCustomField('salt', $salt);
|
||||
}
|
||||
$player = new OTS_Player();
|
||||
$account = new OTS_Account();
|
||||
$player->find($character);
|
||||
if($player->isLoaded()) {
|
||||
$account = $player->getAccount();
|
||||
}
|
||||
|
||||
$account->setPassword(encrypt($tmp_new_pass));
|
||||
$account->save();
|
||||
$account->setCustomField('email_code', '');
|
||||
if($account->isLoaded()) {
|
||||
if($account->getCustomField('email_code') == $code) {
|
||||
if(Validator::password($newPassword)) {
|
||||
$tmp_new_pass = $newPassword;
|
||||
if(USE_ACCOUNT_SALT) {
|
||||
$salt = generateRandomString(10, false, true, true);
|
||||
$tmp_new_pass = $salt . $newPassword;
|
||||
$account->setCustomField('salt', $salt);
|
||||
}
|
||||
|
||||
$mailBody = $twig->render('mail.account.lost.new-password.html.twig', [
|
||||
'account' => $account,
|
||||
'newPassword' => $newPassword,
|
||||
]);
|
||||
$account->setPassword(encrypt($tmp_new_pass));
|
||||
$account->save();
|
||||
$account->setCustomField('email_code', '');
|
||||
|
||||
$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';
|
||||
}
|
||||
$mailBody = $twig->render('mail.account.lost.new-password.html.twig', [
|
||||
'account' => $account,
|
||||
'newPassword' => $newPassword,
|
||||
]);
|
||||
|
||||
$twig->display('account/lost/finish.new-password.html.twig', [
|
||||
'statusMsg' => $statusMsg,
|
||||
'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 {
|
||||
$error = Validator::getLastError();
|
||||
$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 {
|
||||
$error = 'Wrong code to change password.';
|
||||
$error = Validator::getLastError();
|
||||
}
|
||||
}
|
||||
else {
|
||||
$error = "Account of this character or this character doesn't exist.";
|
||||
$error = 'Wrong code to change password.';
|
||||
}
|
||||
}
|
||||
else {
|
||||
$error = "Account of this character or this character doesn't exist.";
|
||||
}
|
||||
|
||||
if(!empty($error)) {
|
||||
$twig->display('error_box.html.twig', [
|
||||
|
@@ -14,11 +14,17 @@ if($account->isLoaded()) {
|
||||
]);
|
||||
}
|
||||
else {
|
||||
echo lostAccountCooldown($nick, (int)$account->getCustomField('email_next'));
|
||||
lostAccountWriteCooldown($nick, (int)$account->getCustomField('email_next'));
|
||||
}
|
||||
}
|
||||
else {
|
||||
echo "Player or account of player <b>" . escapeHtml($nick) . "</b> doesn't exist.";
|
||||
$errors[] = "Player or account of player <b>" . escapeHtml($nick) . "</b> doesn't exist.";
|
||||
}
|
||||
|
||||
if (!empty($errors)) {
|
||||
$twig->display('error_box.html.twig', [
|
||||
'errors' => $errors,
|
||||
]);
|
||||
}
|
||||
|
||||
$twig->display('account.back_button.html.twig', [
|
||||
|
@@ -14,11 +14,17 @@ if($account->isLoaded()) {
|
||||
]);
|
||||
}
|
||||
else {
|
||||
echo 'Account of this character has no recovery key!';
|
||||
$errors[] = 'Account of this character has no recovery key!';
|
||||
}
|
||||
}
|
||||
else {
|
||||
echo "Player or account of player <b>" . escapeHtml($nick) . "</b> doesn't exist.";
|
||||
$errors[] = "Player or account of player <b>" . escapeHtml($nick) . "</b> doesn't exist.";
|
||||
}
|
||||
|
||||
if (!empty($errors)) {
|
||||
$twig->display('error_box.html.twig', [
|
||||
'errors' => $errors,
|
||||
]);
|
||||
}
|
||||
|
||||
$twig->display('account.back_button.html.twig', [
|
||||
|
@@ -5,7 +5,7 @@ csrfProtect();
|
||||
|
||||
$title = 'Lost Account';
|
||||
|
||||
$recKey = trim($_REQUEST['key']);
|
||||
$key = trim($_REQUEST['key']);
|
||||
$nick = stripslashes($_REQUEST['nick']);
|
||||
|
||||
$player = new OTS_Player();
|
||||
@@ -18,25 +18,31 @@ if($player->isLoaded()) {
|
||||
if($account->isLoaded()) {
|
||||
$accountKey = $account->getCustomField('key');
|
||||
if(!empty($accountKey)) {
|
||||
if($accountKey == $recKey) {
|
||||
$twig->display('account/lost/step2.html.twig', [
|
||||
if($accountKey == $key) {
|
||||
$twig->display('account/lost/recovery-key.step-2.html.twig', [
|
||||
'nick' => $nick,
|
||||
'recKey' => $recKey,
|
||||
'key' => $key,
|
||||
]);
|
||||
}
|
||||
else {
|
||||
echo 'Wrong recovery key!';
|
||||
$errors[] = 'Wrong recovery key!';
|
||||
}
|
||||
}
|
||||
else {
|
||||
echo 'Account of this character has no recovery key!';
|
||||
$errors[] = 'Account of this character has no recovery key!';
|
||||
}
|
||||
}
|
||||
else
|
||||
echo "Player or account of player <b>" . escapeHtml($nick) . "</b> doesn't exist.";
|
||||
$errors[] = "Player or account of player <b>" . escapeHtml($nick) . "</b> doesn't exist.";
|
||||
|
||||
if (!empty($errors)) {
|
||||
$twig->display('error_box.html.twig', [
|
||||
'errors' => $errors,
|
||||
]);
|
||||
}
|
||||
|
||||
$twig->display('account.back_button.html.twig', [
|
||||
'new_line' => true,
|
||||
'center' => true,
|
||||
'action' => getLink('account/lost') . '?action=step1&action_type=reckey&nick=' . urlencode($nick),
|
||||
'action' => getLink('account/lost/step-1') . '?action=recovery-key&nick=' . urlencode($nick),
|
||||
]);
|
||||
|
@@ -5,7 +5,7 @@ csrfProtect();
|
||||
|
||||
$title = 'Lost Account';
|
||||
|
||||
$recKey = trim($_REQUEST['key']);
|
||||
$key = trim($_REQUEST['key']);
|
||||
$nick = stripslashes($_REQUEST['nick']);
|
||||
$newPassword = trim($_REQUEST['passor']);
|
||||
$newEmail = trim($_REQUEST['email']);
|
||||
@@ -21,7 +21,7 @@ if($account->isLoaded()) {
|
||||
$accountKey = $account->getCustomField('key');
|
||||
|
||||
if(!empty($accountKey)) {
|
||||
if($accountKey == $recKey) {
|
||||
if($accountKey == $key) {
|
||||
if(Validator::password($newPassword)) {
|
||||
if(Validator::email($newEmail)) {
|
||||
$account->setEMail($newEmail);
|
||||
@@ -48,7 +48,7 @@ if($account->isLoaded()) {
|
||||
'newEmail' => $newEmail,
|
||||
]);
|
||||
|
||||
if(_mail($account->getCustomField('email'), $config['lua']['serverName']." - New password to your account", $mailBody)) {
|
||||
if(_mail($account->getCustomField('email'), configLua('serverName') . ' - New password to your account', $mailBody)) {
|
||||
$statusMsg = '<br /><small>Sent e-mail with your account name and password to new e-mail. You should receive this e-mail in 15 minutes. You can login now with new password!</small>';
|
||||
}
|
||||
else {
|
||||
@@ -67,27 +67,33 @@ if($account->isLoaded()) {
|
||||
]);
|
||||
}
|
||||
else {
|
||||
echo Validator::getLastError();
|
||||
$errors[] = Validator::getLastError();
|
||||
}
|
||||
}
|
||||
else {
|
||||
echo Validator::getLastError();
|
||||
$errors[] = Validator::getLastError();
|
||||
}
|
||||
}
|
||||
else {
|
||||
echo 'Wrong recovery key!';
|
||||
$errors[] = 'Wrong recovery key!';
|
||||
}
|
||||
}
|
||||
else {
|
||||
echo 'Account of this character has no recovery key!';
|
||||
$errors[] = 'Account of this character has no recovery key!';
|
||||
}
|
||||
}
|
||||
else {
|
||||
echo "Player or account of player <b>" . escapeHtml($nick) . "</b> doesn't exist.";
|
||||
$errors[] = "Player or account of player <b>" . escapeHtml($nick) . "</b> doesn't exist.";
|
||||
}
|
||||
|
||||
if (!empty($errors)) {
|
||||
$twig->display('error_box.html.twig', [
|
||||
'errors' => $errors,
|
||||
]);
|
||||
}
|
||||
|
||||
$twig->display('account.back_button.html.twig', [
|
||||
'new_line' => true,
|
||||
'center' => true,
|
||||
'action' => getLink('account/lost') . '?action=step1&action_type=reckey&nick=' . urlencode($nick),
|
||||
'action' => getLink('account/lost/step-1') . '?action=recovery-key&nick=' . urlencode($nick),
|
||||
]);
|
||||
|
71
system/templates/account/lost/recovery-key.step-2.html.twig
Normal file
71
system/templates/account/lost/recovery-key.step-2.html.twig
Normal file
@@ -0,0 +1,71 @@
|
||||
Set new password and e-mail to your account.<br>
|
||||
<form action="{{ getLink('account/lost/recovery-key/step-3') }}" method="post">
|
||||
|
||||
{{ csrf() }}
|
||||
|
||||
<input type="hidden" name="key" VALUE="{{ key }}">
|
||||
|
||||
<input type="hidden" name="character" value="">
|
||||
<table class="myaac-table" style="width: 100%">
|
||||
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="white">
|
||||
<b>Please enter new password and e-mail</b>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="nick">Account of character:</label>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" id="nick" name="nick" value="{{ nick }}" size="40" readonly="readonly">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="nick">New password:</label>
|
||||
</td>
|
||||
<td>
|
||||
<input id="passor" type="password" name="passor" value="" size="40">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="nick">Repeat new password:</label>
|
||||
</td>
|
||||
<td>
|
||||
<input id="passor2" type="password" name="passor" value="" size="40">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="nick">New e-mail address:</label>
|
||||
</td>
|
||||
<td>
|
||||
<input id="email" type="text" name="email" value="" size="40">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<br>
|
||||
<table style="width: 100%">
|
||||
<tr>
|
||||
<td align="center">
|
||||
{% set button_name = 'Submit' %}
|
||||
{% include('buttons.base.html.twig') %}
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
@@ -1,35 +0,0 @@
|
||||
Set new password and e-mail to your account.<br>
|
||||
<form action="{{ getLink('account/lost/step-3') }}" method="post">
|
||||
<input type="hidden" name="character" value="">
|
||||
<table class="myaac-table" style="width: 100%">
|
||||
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="white">
|
||||
<b>Please enter new password and e-mail</b>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
Account of character: <input type="text" name="nick" value="{{ nick }}" size="40" readonly="readonly"><br/>
|
||||
New password: <input id="passor" type="password" name="passor" value="" size="40"><br/>
|
||||
Repeat new password: <input id="passor2" type="password" name="passor" value="" size="40"><br/>
|
||||
New e-mail address: <input id="email" type="text" name="email" value="" size="40"><br/>
|
||||
<input type="hidden" name="key" VALUE="{{ recKey }}">
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<br>
|
||||
<table style="width: 100%">
|
||||
<tr>
|
||||
<td align="center">
|
||||
{% set button_name = 'Submit' %}
|
||||
{% include('buttons.base.html.twig') %}
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
Reference in New Issue
Block a user