* @author Slawkens * @copyright 2017 MyAAC * @version 0.0.6 * @link http://my-aac.org */ defined('MYAAC') or die('Direct access not allowed!'); $title = 'Lost Account Interface'; $config_salt_enabled = fieldExist('salt', 'accounts'); if($config['mail_enabled']) { if($action == '') { echo '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.
Please enter your character name

What do you want?



'; ?>
Back
'; elseif($action == 'step1' && $_REQUEST['action_type'] == 'email') { $nick = stripslashes($_REQUEST['nick']); if(check_name($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:

'; 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(check_name($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' && $_REQUEST['action_type'] == 'reckey') { $nick = stripslashes($_REQUEST['nick']); if(check_name($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:    

'; } 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(check_name($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:     

'; } 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(check_name($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(check_password($new_pass)) { if(check_mail($new_email)) { $account->setEMail($new_email); if($config_salt_enabled) { $salt = generateRandomString(10, false, true, true); $new_pass_with_salt = $salt . $new_pass; $account->setSalt($salt); } $account->setPassword(encrypt($new_pass_with_salt)); $account->save(); 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 'Wrong e-mail format.'; } else echo 'Wrong password format. Use only a-Z, A-Z, 0-9. Minimum password length is 7 characters and maximum 32.'; } 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: 

'; 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: 

'; } 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: 

'; } 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(check_password($newpassword)) { if($config_salt_enabled) { $salt = generateRandomString(10, false, true, true); $newpassword_with_salt = $salt . $newpassword; $account->setSalt($salt); } $account->setPassword(encrypt($newpassword_with_salt)); $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= 'Wrong password format. Use only a-z, A-Z, 0-9. Minimum password length is 7 characters and maximum 32.'; } 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: 

'; } } else echo 'Account maker is not configured to send e-mails, you can\'t use Lost Account Interface. Contact with admin to get help.'; ?>