';
-}
+$twig->display('account/lost/form.html.twig');
diff --git a/system/pages/account/lost/base.php b/system/pages/account/lost/base.php
new file mode 100644
index 00000000..58f115ce
--- /dev/null
+++ b/system/pages/account/lost/base.php
@@ -0,0 +1,18 @@
+display('error_box.html.twig', [
+ 'errors' => ["Account of selected character (" . escapeHtml($nick) . ") received e-mail in last $timeRounded minutes. You must wait $timeLeft before you can use Lost Account Interface again."]
+ ]);
+}
diff --git a/system/pages/account/lost/check-code.php b/system/pages/account/lost/check-code.php
new file mode 100644
index 00000000..44c3c622
--- /dev/null
+++ b/system/pages/account/lost/check-code.php
@@ -0,0 +1,51 @@
+display('account/lost/check-code.html.twig', [
+ 'code' => $code,
+ 'characters' => $character,
+ ]);
+}
+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) {
+ $twig->display('account/lost/check-code.finish.html.twig', [
+ 'character' => $character,
+ 'code' => $code,
+ ]);
+ }
+ else {
+ $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', [
+ 'errors' => [$error],
+ ]);
+
+ echo ' ';
+
+ $twig->display('account/lost/check-code.html.twig', [
+
+ ]);
+}
diff --git a/system/pages/account/lost/email/send-code.php b/system/pages/account/lost/email/send-code.php
new file mode 100644
index 00000000..8dec8274
--- /dev/null
+++ b/system/pages/account/lost/email/send-code.php
@@ -0,0 +1,75 @@
+find($nick);
+if($player->isLoaded()) {
+ $account = $player->getAccount();
+}
+
+if($account->isLoaded()) {
+ if($account->getCustomField('email_next') < time()) {
+ if($account->getEMail() == $email) {
+ $newCode = generateRandomString(30, true, false, true);
+ $mailBody = $twig->render('mail.account.lost.code.html.twig', [
+ 'newCode' => $newCode,
+ 'account' => $account,
+ 'nick' => $nick,
+ ]);
+
+ $accountEMail = $account->getCustomField('email');
+ if(_mail($accountEMail, configLua('serverName') . ' - Recover your account', $mailBody)) {
+ $account->setCustomField('email_code', $newCode);
+ $account->setCustomField('email_next', (time() + setting('core.mail_lost_account_interval')));
+
+ $twig->display('success.html.twig', [
+ 'title' => 'Email has been sent',
+ 'description' => 'Details about steps required to recover your account has been sent to ' . $accountEMail . '. You should receive this email within 15 minutes. Please check your inbox/spam directory.',
+ 'custom_buttons' => '',
+ ]);
+
+ $twig->display('account.back_button.html.twig', [
+ 'new_line' => true,
+ 'center' => true,
+ 'action' => getLink('news'),
+ ]);
+
+ return;
+ }
+
+ $account->setCustomField('email_next', (time() + 60));
+ error('An error occurred while sending email! Try again later or contact with admin. For Admin: More info can be found in system/logs/mailer-error.log');
+ }
+ else {
+ $errors[] = 'Invalid e-mail to account of character ' . escapeHtml($nick) . '. Try again.';
+ }
+ }
+ else {
+ lostAccountWriteCooldown($nick, (int)$account->getCustomField('email_next'));
+ }
+}
+else {
+ $errors[] = "Player or account of player " . escapeHtml($nick) . " 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/step-1') . '?action=email&nick=' . urlencode($nick),
+]);
diff --git a/system/pages/account/lost/email/set-new-password.php b/system/pages/account/lost/email/set-new-password.php
new file mode 100644
index 00000000..f4801ad6
--- /dev/null
+++ b/system/pages/account/lost/email/set-new-password.php
@@ -0,0 +1,128 @@
+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 = ' 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 = '
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 ' ';
+
+ $template = 'account/lost/check-code.html.twig';
+ if($passwordFailed) {
+ $template = 'account/lost/check-code.finish.html.twig';
+ }
+
+ $twig->display($template, [
+ 'code' => $code,
+ 'character' => $character,
+ ]);
+}
diff --git a/system/pages/account/lost/email/step-1.php b/system/pages/account/lost/email/step-1.php
new file mode 100644
index 00000000..d36e3b4d
--- /dev/null
+++ b/system/pages/account/lost/email/step-1.php
@@ -0,0 +1,36 @@
+isLoaded()) {
+ if($account->getCustomField('email_next') < time()) {
+ $twig->display('account/lost/email.html.twig', [
+ 'nick' => $nick,
+ ]);
+ }
+ else {
+ lostAccountWriteCooldown($nick, (int)$account->getCustomField('email_next'));
+ }
+}
+else {
+ $errors[] = "Player or account of player " . escapeHtml($nick) . " 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'),
+]);
diff --git a/system/pages/account/lost/recovery-key/step-1.php b/system/pages/account/lost/recovery-key/step-1.php
new file mode 100644
index 00000000..6ced04fc
--- /dev/null
+++ b/system/pages/account/lost/recovery-key/step-1.php
@@ -0,0 +1,38 @@
+isLoaded()) {
+ $account_key = $account->getCustomField('key');
+
+ if(!empty($account_key)) {
+ $twig->display('account/lost/recovery-key.step-1.html.twig', [
+ 'nick' => $nick,
+ 'key' => $key,
+ ]);
+ }
+ else {
+ $errors[] = 'Account of this character has no recovery key!';
+ }
+}
+else {
+ $errors[] = "Player or account of player " . escapeHtml($nick) . " 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'),
+]);
diff --git a/system/pages/account/lost/recovery-key/step-2.php b/system/pages/account/lost/recovery-key/step-2.php
new file mode 100644
index 00000000..347e9612
--- /dev/null
+++ b/system/pages/account/lost/recovery-key/step-2.php
@@ -0,0 +1,49 @@
+find($nick);
+if($player->isLoaded()) {
+ $account = $player->getAccount();
+}
+
+if($account->isLoaded()) {
+ $accountKey = $account->getCustomField('key');
+ if(!empty($accountKey)) {
+ if($accountKey == $key) {
+ $twig->display('account/lost/recovery-key.step-2.html.twig', [
+ 'nick' => $nick,
+ 'key' => $key,
+ ]);
+ }
+ else {
+ $errors[] = 'Wrong recovery key!';
+ }
+ }
+ else {
+ $errors[] = 'Account of this character has no recovery key!';
+ }
+}
+else {
+ $errors[] = "Player or account of player " . escapeHtml($nick) . " 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/step-1') . '?action=recovery-key&nick=' . urlencode($nick) . '&key=' . urlencode($key),
+]);
diff --git a/system/pages/account/lost/recovery-key/step-3.php b/system/pages/account/lost/recovery-key/step-3.php
new file mode 100644
index 00000000..ddf8bdff
--- /dev/null
+++ b/system/pages/account/lost/recovery-key/step-3.php
@@ -0,0 +1,117 @@
+find($nick);
+if($player->isLoaded()) {
+ $account = $player->getAccount();
+}
+
+if($account->isLoaded()) {
+ $accountKey = $account->getCustomField('key');
+
+ if(!empty($accountKey)) {
+ if($accountKey == $key) {
+ if(Validator::password($newPassword)) {
+ if ($newPassword == $passwordRepeat) {
+ if (Validator::email($newEmail)) {
+ $emailExists = AccountModel::where('email', $newEmail)->count() > 0;
+ if (!$emailExists) {
+
+ $hooks->trigger(HOOK_ACCOUNT_LOST_RECOVERY_KEY_STEP_3_POST);
+
+ if (empty($errors)) {
+ $account->setEMail($newEmail);
+
+ $tmp_new_pass = $newPassword;
+ if (USE_ACCOUNT_SALT) {
+ $salt = generateRandomString(10, false, true, true);
+ $tmp_new_pass = $salt . $newPassword;
+ }
+
+ $account->setPassword(encrypt($tmp_new_pass));
+ $account->save();
+
+ if (USE_ACCOUNT_SALT) {
+ $account->setCustomField('salt', $salt);
+ }
+
+ $statusMsg = '';
+ if ($account->getCustomField('email_next') < time()) {
+ $mailBody = $twig->render('mail.account.lost.new-email.html.twig', [
+ 'account' => $account,
+ 'newPassword' => $newPassword,
+ 'newEmail' => $newEmail,
+ ]);
+
+ if (_mail($account->getCustomField('email'), configLua('serverName') . ' - New password to your account', $mailBody)) {
+ $statusMsg = ' 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!';
+ } else {
+ $statusMsg = '
An error occurred while sending email! You will not receive e-mail with this informations. For Admin: More info can be found in system/logs/mailer-error.log
+{% endif %}
diff --git a/system/templates/account.lost.form.html.twig b/system/templates/account.lost.form.html.twig
deleted file mode 100644
index fd3c1312..00000000
--- a/system/templates/account.lost.form.html.twig
+++ /dev/null
@@ -1,36 +0,0 @@
-The Lost Account Interface can help you to get back your account name and password. Please enter your character name and select what you want to do.
-
\ No newline at end of file
diff --git a/system/templates/account/lost/check-code.finish.html.twig b/system/templates/account/lost/check-code.finish.html.twig
new file mode 100644
index 00000000..51ff2e4e
--- /dev/null
+++ b/system/templates/account/lost/check-code.finish.html.twig
@@ -0,0 +1,56 @@
+Please enter new password to your account and repeat to make sure you remember password.
+
diff --git a/system/templates/account/lost/check-code.html.twig b/system/templates/account/lost/check-code.html.twig
new file mode 100644
index 00000000..e394ecbb
--- /dev/null
+++ b/system/templates/account/lost/check-code.html.twig
@@ -0,0 +1,33 @@
+Please enter code from e-mail and name of one character from account. Then press Submit.
+
diff --git a/system/templates/account/lost/email.html.twig b/system/templates/account/lost/email.html.twig
new file mode 100644
index 00000000..4f43efea
--- /dev/null
+++ b/system/templates/account/lost/email.html.twig
@@ -0,0 +1,54 @@
+Please enter e-mail to account with this character.
+
diff --git a/system/templates/account/lost/finish.new-email.html.twig b/system/templates/account/lost/finish.new-email.html.twig
new file mode 100644
index 00000000..e4a5f1ee
--- /dev/null
+++ b/system/templates/account/lost/finish.new-email.html.twig
@@ -0,0 +1,58 @@
+Your account name, new password and new e-mail.
+
+
+
+
+
+ Your account name, new password and new e-mail
+
+
+
+
+
+
+
+
+
+
+
+ Account name:
+
+
+ {{ account.getName() }}
+
+
+
+
+ New password:
+
+
+ {{ newPassword }}
+
+
+
+
+ New e-mail address:
+
+
+ {{ newEmail }}
+
+
+
+
+ {{ statusMsg|raw }}
+
+
+
+
+
+
+
+
+
+
+ {{ include('buttons.login.html.twig') }}
+
+
+
+
diff --git a/system/templates/account/lost/finish.new-password.html.twig b/system/templates/account/lost/finish.new-password.html.twig
new file mode 100644
index 00000000..2f7c2134
--- /dev/null
+++ b/system/templates/account/lost/finish.new-password.html.twig
@@ -0,0 +1,30 @@
+New password to your account is below. Now you can log in.
+
+
+
+
+
Changed password
+
+
+
+
+
+
+ New password: {{ newPassword }}
+ Account name: (Already on your e-mail)
+ {{ statusMsg|raw }}
+
diff --git a/system/templates/account/lost/form.html.twig b/system/templates/account/lost/form.html.twig
new file mode 100644
index 00000000..7eafa047
--- /dev/null
+++ b/system/templates/account/lost/form.html.twig
@@ -0,0 +1,43 @@
+The Lost Account Interface can help you to get back your account name and password. Please enter your character name and select what you want to do.
+
diff --git a/system/templates/account/lost/recovery-key.step-1.html.twig b/system/templates/account/lost/recovery-key.step-1.html.twig
new file mode 100644
index 00000000..fc05c2bd
--- /dev/null
+++ b/system/templates/account/lost/recovery-key.step-1.html.twig
@@ -0,0 +1,57 @@
+If you enter right recovery key you will see form to set new e-mail and password to account. To this e-mail will be send your new password and account name.
+
diff --git a/system/templates/account/lost/recovery-key.step-2.html.twig b/system/templates/account/lost/recovery-key.step-2.html.twig
new file mode 100644
index 00000000..d3732b28
--- /dev/null
+++ b/system/templates/account/lost/recovery-key.step-2.html.twig
@@ -0,0 +1,90 @@
+Set new password and e-mail to your account.
+
or open page: {{ getLink('account/lost/check-code') }} and in field "code" write {{ newCode }}
+
+
If you did not request a password change, you may ignore this message and your password will remain unchanged.
diff --git a/system/templates/mail.account.lost.new-email.html.twig b/system/templates/mail.account.lost.new-email.html.twig
new file mode 100644
index 00000000..bbf901f0
--- /dev/null
+++ b/system/templates/mail.account.lost.new-email.html.twig
@@ -0,0 +1,7 @@
+