* @author Slawkens * @copyright 2017 MyAAC * @link http://my-aac.org */ defined('MYAAC') or die('Direct access not allowed!'); $title = 'Lost Account Interface'; if(!$config['mail_enabled']) { echo 'Account maker is not configured to send e-mails, you can\'t use Lost Account Interface. Contact with admin to get help.'; return; } $config_salt_enabled = $db->hasColumn('accounts', 'salt'); $action_type = isset($_REQUEST['action_type']) ? $_REQUEST['action_type'] : ''; if($action == '') { echo $twig->render('account.lost.form.html.twig'); } else if($action == 'step1' && $action_type == '') { echo $twig->render('account.lost.noaction.html.twig'); } elseif($action == 'step1' && $action_type == 'email') { $nick = stripslashes($_REQUEST['nick']); if(Validator::characterName($nick)) { $player = new OTS_Player(); $account = new OTS_Account(); $player->find($nick); if($player->isLoaded()) $account = $player->getAccount(); if($account->isLoaded()) { if($account->getCustomField('email_next') < time()) echo 'Please enter e-mail to account with this character.
Please enter e-mail to account
Character:
E-mail to account:

' . $twig->render('buttons.submit.html.twig') . '
'; else { $insec = $account->getCustomField('email_next') - time(); $minutesleft = floor($insec / 60); $secondsleft = $insec - ($minutesleft * 60); $timeleft = $minutesleft.' minutes '.$secondsleft.' seconds'; echo 'Account of selected character ('.$nick.') received e-mail in last '.ceil($config['email_lai_sec_interval'] / 60).' minutes. You must wait '.$timeleft.' before you can use Lost Account Interface again.'; } } else echo 'Player or account of player ' . $nick . ' doesn\'t exist.'; } else echo 'Invalid player name format. If you have other characters on account try with other name.'; echo '
Back
'; } elseif($action == 'sendcode') { $email = $_REQUEST['email']; $nick = stripslashes($_REQUEST['nick']); if(Validator::characterName($nick)) { $player = new OTS_Player(); $account = new OTS_Account(); $player->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 = ' You asked to reset your ' . $config['lua']['serverName'] . ' password.

Account name: '.$account->getName().'


To do so, please click this link:

'.BASE_URL.'/?subtopic=lostaccount&action=checkcode&code='.$newcode.'&character='.urlencode($nick).'

or open page: ' . BASE_URL . '?subtopic=lostaccount&action=checkcode 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.'; $account_mail = $account->getCustomField('email'); if(_mail($account_mail, $config['lua']['serverName'].' - Recover your account', $mailBody)) { $account->setCustomField('email_code', $newcode); $account->setCustomField('email_next', (time() + $config['email_lai_sec_interval'])); echo '
Details about steps required to recover your account has been sent to ' . $account_mail . '. You should receive this email within 15 minutes. Please check your inbox/spam directory.'; } else { $account->setCustomField('email_next', (time() + 60)); echo '

An error occorred while sending email! Try again or contact with admin. Error:
' . $mailer->ErrorInfo . '

'; } } else echo 'Invalid e-mail to account of character '.$nick.'. Try again.'; } else { $insec = $account->getCustomField('email_next') - time(); $minutesleft = floor($insec / 60); $secondsleft = $insec - ($minutesleft * 60); $timeleft = $minutesleft.' minutes '.$secondsleft.' seconds'; echo 'Account of selected character ('.$nick.') received e-mail in last '.ceil($config['email_lai_sec_interval'] / 60).' minutes. You must wait '.$timeleft.' before you can use Lost Account Interface again.'; } } else echo 'Player or account of player '.$nick.' doesn\'t exist.'; } else echo 'Invalid player name format. If you have other characters on account try with other name.'; echo '
Back
'; } elseif($action == 'step1' && $action_type == 'reckey') { $nick = stripslashes($_REQUEST['nick']); if(Validator::characterName($nick)) { $player = new OTS_Player(); $account = new OTS_Account(); $player->find($nick); if($player->isLoaded()) $account = $player->getAccount(); if($account->isLoaded()) { $account_key = $account->getCustomField('key'); if(!empty($account_key)) { echo '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.
Please enter your recovery key
Character name: 
Recovery key:    

' . $twig->render('buttons.submit.html.twig') . '
'; } else echo 'Account of this character has no recovery key!'; } else echo 'Player or account of player '.$nick.' doesn\'t exist.'; } else echo 'Invalid player name format. If you have other characters on account try with other name.'; echo '
Back
'; } elseif($action == 'step2') { $rec_key = trim($_REQUEST['key']); $nick = stripslashes($_REQUEST['nick']); if(Validator::characterName($nick)) { $player = new OTS_Player(); $account = new OTS_Account(); $player->find($nick); if($player->isLoaded()) $account = $player->getAccount(); if($account->isLoaded()) { $account_key = $account->getCustomField('key'); if(!empty($account_key)) { if($account_key == $rec_key) { echo ''; echo 'Set new password and e-mail to your account.
Please enter new password and e-mail
Account of character:  
New password:            
Repeat new password:  
New e-mail address:     

' . $twig->render('buttons.submit.html.twig') . '
'; } else echo 'Wrong recovery key!'; } else echo 'Account of this character has no recovery key!'; } else echo 'Player or account of player '.$nick.' doesn\'t exist.'; } else echo 'Invalid player name format. If you have other characters on account try with other name.'; echo '
Back
'; } elseif($action == 'step3') { $rec_key = trim($_REQUEST['key']); $nick = stripslashes($_REQUEST['nick']); $new_pass = trim($_REQUEST['passor']); $new_email = trim($_REQUEST['email']); if(Validator::characterName($nick)) { $player = new OTS_Player(); $account = new OTS_Account(); $player->find($nick); if($player->isLoaded()) $account = $player->getAccount(); if($account->isLoaded()) { $account_key = $account->getCustomField('key'); if(!empty($account_key)) { if($account_key == $rec_key) { if(Validator::password($new_pass)) { if(Validator::email($new_email)) { $account->setEMail($new_email); $tmp_new_pass = $new_pass; if($config_salt_enabled) { $salt = generateRandomString(10, false, true, true); $tmp_new_pass = $salt . $new_pass; } $account->setPassword(encrypt($tmp_new_pass)); $account->save(); if($config_salt_enabled) $account->setCustomField('salt', $salt); echo 'Your account name, new password and new e-mail.
Your account name, new password and new e-mail
Account name:     '.$account->getName().'
New password:        '.$new_pass.'
New e-mail address: '.$new_email.'
'; if($account->getCustomField('email_next') < time()) { $mailBody = '

Your account name and new password!

Changed password and e-mail to your account in Lost Account Interface on server '.$config['lua']['serverName'].'

Account name: '.$account->getName().'

New password: '.$new_pass.'

E-mail: '.$new_email.' (this e-mail)


It\'s automatic e-mail from OTS Lost Account System. Do not reply!

'; if(_mail($account->getCustomField('email'), $config['lua']['serverName']." - New password to your account", $mailBody)) { echo '
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 { echo '

An error occorred while sending email! You will not receive e-mail with this informations. Error:
' . $mailer->ErrorInfo . '

'; } } else { echo '
You will not receive e-mail with this informations.'; } echo '

'; } else echo Validator::getLastError(); } else echo Validator::getLastError(); } else echo 'Wrong recovery key!'; } else echo 'Account of this character has no recovery key!'; } else echo 'Player or account of player '.$nick.' doesn\'t exist.'; } else echo 'Invalid player name format. If you have other characters on account try with other name.'; echo '
Back
'; } elseif($action == 'checkcode') { $code = trim($_REQUEST['code']); $character = stripslashes(trim($_REQUEST['character'])); if(empty($code) || empty($character)) echo 'Please enter code from e-mail and name of one character from account. Then press Submit.
Code & character name
Your code: 
Character: 

' . $twig->render('buttons.submit.html.twig') . '
'; 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) { echo ' Please enter new password to your account and repeat to make sure you remember password.
Code & account name
New password:      
Repeat new password: 

' . $twig->render('buttons.submit.html.twig') . '
'; } else $error= 'Wrong code to change password.'; } else $error = 'Account of this character or this character doesn\'t exist.'; } if(!empty($error)) echo ''.$error.'
Please enter code from e-mail and name of one character from account. Then press Submit.
Code & character name
Your code: 
Character: 

' . $twig->render('buttons.submit.html.twig') . '
'; } elseif($action == 'setnewpassword') { $newpassword = $_REQUEST['passor']; $code = $_REQUEST['code']; $character = stripslashes($_REQUEST['character']); echo ''; if(empty($code) || empty($character) || empty($newpassword)) echo 'Error. Try again.
Please enter code from e-mail and name of one character from account. Then press Submit.

'; 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($config_salt_enabled) { $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', ''); echo 'New password to your account is below. Now you can login.
Changed password
New password: '.$newpassword.'
Account name:   (Already on your e-mail)
'; $mailBody = '

Your account name and password!

Changed password to your account in Lost Account Interface on server '.$config['lua']['serverName'].'

Account name: '.$account->getName().'

New password: '.$newpassword.'


It\'s automatic e-mail from OTS Lost Account System. Do not reply!

'; if(_mail($account->getCustomField('email'), $config['lua']['serverName']." - Your new password", $mailBody)) { echo '
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 { echo '

New password work! An error occorred while sending email! You will not receive e-mail with new password. Error:
' . $mailer->ErrorInfo . '

'; } echo '

'; } else $error= Validator::getLastError(); } else $error= 'Wrong code to change password.'; } else $error = 'Account of this character or this character doesn\'t exist.'; } if(!empty($error)) echo ''.$error.'
Please enter code from e-mail and name of one character from account. Then press Submit.
Code & character name
Your code: 
Character: 

' . $twig->render('buttons.submit.html.twig') . '
'; } ?>