diff --git a/system/login.php b/system/login.php index 52424c35..0b5d0f4b 100644 --- a/system/login.php +++ b/system/login.php @@ -118,7 +118,7 @@ else // stay-logged with sessions if(isset($_SESSION['account'])) { - $account_logged = $ots->createObject('Account'); + $account_logged = new OTS_Account(); $account_logged->load($_SESSION['account']); if($account_logged->isLoaded() && $account_logged->getPassword() == $_SESSION['password'] //&& (!isset($_SESSION['admin']) || admin()) @@ -131,8 +131,10 @@ else } } - if($logged) + if($logged) { $logged_flags = $account_logged->getWebFlags(); + $twig->addGlobal('account_logged', $account_logged); + } } $_SESSION['last_visit'] = time(); diff --git a/system/pages/accountmanagement.php b/system/pages/accountmanagement.php index 502e531b..e1f121bb 100644 --- a/system/pages/accountmanagement.php +++ b/system/pages/accountmanagement.php @@ -170,11 +170,7 @@ if(!$logged) } if(!empty($show_msgs)){ //show errors - echo '
The Following Errors Have Occurred:
'; - foreach($show_msgs as $show_msg) { - echo '
  • '.$show_msg; - } - echo '

  • '; + echo $twig->render('error_box.html', array('errors' => $show_msg)); //show form echo $twig->render('account.change_password.html'); @@ -198,10 +194,10 @@ if(!$logged) $message = ''; if($config['mail_enabled'] && $config['send_mail_when_change_password']) { - $mailBody = ' -

    Password to account changed!

    -

    You or someone else changed password to your account on server '.$config['lua']['serverName'].'.

    -

    New password: '.$org_pass.'

    '; + $mailBody = $twig->render('mail.password_changed.html', array( + 'config' => $config, + 'new_password' => $org_pass + )); if(_mail($account_logged->getEMail(), $config['lua']['serverName']." - Changed password", $mailBody)) $message = '
    Your new password were send on email address '.$account_logged->getEMail().'.'; @@ -449,12 +445,8 @@ if(!$logged) if(!$dontshowtableagain) { //show errors if not empty - if(!empty($reg_errors)) - { - echo '
    The Following Errors Have Occurred:
    '; - foreach($reg_errors as $reg_error) - echo '
  • '.$reg_error; - echo '

  • '; + if(!empty($reg_errors)) { + echo $twig->render('error_box.html', array('errors' => $reg_errors)); } //show form echo 'To generate NEW recovery key for your account please enter your password.
    New recovery key cost '.$config['generate_new_reckey_price'].' Premium Points. You have '.$points.' premium points. You will receive e-mail with this recovery key.
    Generate recovery key
    Password:

    '; @@ -515,7 +507,7 @@ if(!$logged) $name_changed = false; $player_id = isset($_POST['player_id']) ? (int)$_POST['player_id'] : NULL; - $newcharname = isset($_POST['newcharname']) ? stripslashes(ucwords(strtolower($_POST['newcharname']))) : NULL; + $name = isset($_POST['name']) ? stripslashes(ucwords(strtolower($_POST['name']))) : NULL; if((!$config['account_change_character_name'])) echo 'You cant change your character name'; else @@ -525,18 +517,18 @@ if(!$logged) if($points < $config['account_change_character_name_points']) $errors[] = 'You need ' . $config['account_change_character_name_points'] . ' premium points to change name. You have '.$points.' premium points.'; - if(empty($errors) && empty($newcharname)) + if(empty($errors) && empty($name)) $errors[] = 'Please enter a name for your character!'; - if(empty($errors) && strlen($newcharname) > 25) + if(empty($errors) && strlen($name) > 25) $errors[] = 'Name is too long. Max. lenght 25 letters.'; - else if(empty($errors) && strlen($newcharname) < 3) + else if(empty($errors) && strlen($name) < 3) $errors[] = 'Name is too short. Min. lenght 25 letters.'; if(empty($errors)) { $error = ''; - if(!admin() && !check_name_new_char($newcharname, $error)) + if(!admin() && !check_name_new_char($name, $error)) $errors[] = $error; } @@ -553,21 +545,22 @@ if(!$logged) if(empty($errors)) { $name_changed = true; $old_name = $player->getName(); - $player->setName($newcharname); + $player->setName($name); $player->save(); $account_logged->setCustomField("premium_points", $points - $config['account_change_character_name_points']); $account_logged->logAction('Changed name from ' . $old_name . ' to ' . $player->getName() . '.'); - echo '
    Character Name Changed
    The character '.$old_name.' name has been changed to ' . $player->getName() . '.

    '; + echo $twig->render('success.html', array( + 'title' => 'Character Name Changed', + 'description' => 'The character '.$old_name.' name has been changed to ' . $player->getName() . '.' + )); } } - else - { - $errors[] = 'Character '.$player_name.' is not on your account.'; + else { + $errors[] = 'Character ' . $player_name . ' is not on your account.'; } } - else - { - $errors[] = 'Character with this name doesn\'t exist.'; + else { + $errors[] = "Character with this name doesn't exist."; } } } @@ -593,7 +586,7 @@ if(!$logged) New Name: - +
    Please enter your character name.
    @@ -744,36 +737,36 @@ if(!$logged) //## CREATE CHARACTER on account ### if($action == "createcharacter") { echo ''; - $newchar_name = isset($_POST['newcharname']) ? stripslashes(ucwords(strtolower($_POST['newcharname']))) : NULL; - $newchar_sex = isset($_POST['newcharsex']) ? $_POST['newcharsex'] : NULL; - $newchar_vocation = isset($_POST['newcharvocation']) ? $_POST['newcharvocation'] : NULL; - $newchar_town = isset($_POST['newchartown']) ? $_POST['newchartown'] : NULL; - $newchar_errors = array(); + $newchar_name = isset($_POST['name']) ? stripslashes(ucwords(strtolower($_POST['name']))) : NULL; + $newchar_sex = isset($_POST['sex']) ? $_POST['sex'] : NULL; + $newchar_vocation = isset($_POST['vocation']) ? $_POST['vocation'] : NULL; + $newchar_town = isset($_POST['town']) ? $_POST['town'] : NULL; + $errors = array(); $newchar_created = false; if(isset($_POST['savecharacter']) && $_POST['savecharacter'] == 1) { if(empty($newchar_name)) - $newchar_errors[] = 'Please enter a name for your character!'; + $errors[] = 'Please enter a name for your character!'; if(strlen($newchar_name) > 25) - $newchar_errors[] = 'Name is too long. Max. lenght 25 letters.'; + $errors[] = 'Name is too long. Max. lenght 25 letters.'; else if(strlen($newchar_name) < 3) - $newchar_errors[] = 'Name is too short. Min. lenght 25 letters.'; + $errors[] = 'Name is too short. Min. lenght 25 letters.'; if(empty($newchar_sex) && $newchar_sex != "0") - $newchar_errors[] = 'Please select the sex for your character!'; + $errors[] = 'Please select the sex for your character!'; if(count($config['character_samples']) > 1) { if(!isset($newchar_vocation)) - $newchar_errors[] = 'Please select a vocation for your character.'; + $errors[] = 'Please select a vocation for your character.'; } else $newchar_vocation = $config['character_samples'][0]; if(count($config['character_towns']) > 1) { if(!isset($newchar_town)) - $newchar_errors[] = 'Please select a town for your character.'; + $errors[] = 'Please select a town for your character.'; } else { $newchar_town = $config['character_towns'][0]; @@ -782,18 +775,18 @@ if(!$logged) $exist = new OTS_Player(); $exist->find($newchar_name); if($exist->isLoaded()) { - $newchar_errors[] .= 'Character with this name already exist.'; + $errors[] .= 'Character with this name already exist.'; } - if(empty($newchar_errors)) { + if(empty($errors)) { $error = ''; if(!admin() && !check_name_new_char($newchar_name, $error)) { - $newchar_errors[] = $error; + $errors[] = $error; } if(!isset($config['genders'][$newchar_sex])) - $newchar_errors[] = 'Sex is invalid.'; + $errors[] = 'Sex is invalid.'; if(!in_array($newchar_town, $config['character_towns'])) - $newchar_errors[] = 'Please select valid town.'; + $errors[] = 'Please select valid town.'; if(count($config['character_samples']) > 1) { $newchar_vocation_check = false; @@ -801,29 +794,29 @@ if(!$logged) if($newchar_vocation == $char_vocation_key) $newchar_vocation_check = true; if(!$newchar_vocation_check) - $newchar_errors[] = 'Unknown vocation. Please fill in form again.'; + $errors[] = 'Unknown vocation. Please fill in form again.'; } else $newchar_vocation = 0; } - if(empty($newchar_errors)) + if(empty($errors)) { $number_of_players_on_account = $account_logged->getPlayersList()->count(); if($number_of_players_on_account >= $config['characters_per_account']) - $newchar_errors[] .= 'You have too many characters on your account ('.$number_of_players_on_account.'/'.$config['characters_per_account'].')!'; + $errors[] .= 'You have too many characters on your account ('.$number_of_players_on_account.'/'.$config['characters_per_account'].')!'; } - if(empty($newchar_errors)) + if(empty($errors)) { $char_to_copy_name = $config['character_samples'][$newchar_vocation]; $char_to_copy = new OTS_Player(); $char_to_copy->find($char_to_copy_name); if(!$char_to_copy->isLoaded()) - $newchar_errors[] .= 'Wrong characters configuration. Try again or contact with admin. ADMIN: Edit file config/config.php and set valid characters to copy names. Character to copy: '.$char_to_copy_name.' doesn\'t exist.'; + $errors[] .= 'Wrong characters configuration. Try again or contact with admin. ADMIN: Edit file config/config.php and set valid characters to copy names. Character to copy: '.$char_to_copy_name.' doesn\'t exist.'; } - if(empty($newchar_errors)) + if(empty($errors)) { if($newchar_sex == "0") $char_to_copy->setLookType(136); @@ -924,46 +917,27 @@ if(!$logged) } } - if(count($newchar_errors) > 0) { - echo $twig->render('error_box.html', array('errors' => $newchar_errors)); + if(count($errors) > 0) { + echo $twig->render('error_box.html', array('errors' => $errors)); } if(!$newchar_created) { - echo 'Please choose a name'; - if(count($config['character_samples']) > 1) - echo ', vocation'; - echo ' and sex for your character.
    In any case the name must not violate the naming conventions stated in the '.$config['lua']['serverName'].' Rules, or your character might get deleted or name locked.'; - if($account_logged->getPlayersList()->count() >= $config['characters_per_account']) { - echo ' You have maximum number of characters per account on your account. Delete one before you make new.'; - } - echo '

    Create Character
    - -
    NameSex
    -
    - -
    Please enter your character name.
    -
    -
    '; + echo $twig->render('account.create_character.html', array( + 'config' => $config, + 'newchar_name' => $newchar_name + + )); - $i = 0; - foreach(array_reverse($config['genders'], true) as $id => $name) { - echo '
    '; - } - - echo '
    '; echo '
    '; if(count($config['character_samples']) > 1) { echo '

    Select your vocation:
    '; - foreach($config['character_samples'] as $char_vocation_key => $sample_char) + foreach($config['character_samples'] as $key => $sample_char) { - echo ''; + echo '>'; } echo '
    '; } @@ -972,10 +946,10 @@ if(!$logged) echo '

    Select your city:
    '; foreach($config['character_towns'] as $town_id) { - echo ''; + echo '>'; } echo '
    '; } diff --git a/system/templates/account.create_character.html b/system/templates/account.create_character.html new file mode 100644 index 00000000..da871aaf --- /dev/null +++ b/system/templates/account.create_character.html @@ -0,0 +1,66 @@ +Please choose a name{% if config.character_samples|length > 1 %}, vocation{% endif %} +{% if config.character_towns|length > 1 %}, town{% endif %} + and sex for your character.
    +In any case the name must not violate the naming conventions stated in the {{ config.lua.serverName }} Rules, or your character might get deleted or name locked. +{% if account_logged.getPlayersList()|length >= config.characters_per_account %} + You have maximum number of characters per account on your account. Delete one before you make new. +{% endif %} +

    + + +
    + +
    +
    + + + + +
    Create Character
    + + + + +
    +
    + +
    +
    + + +
    +
    +
    +
    +
    +
    + + + + + + + + + +
    + Name + + Sex +
    +
    + +
    Please enter your character name.
    +
    +
    + {% set i = 0 %} + {% for id, _sex in config.genders|reverse(true) %} + {% set i = i + 1 %} +
    + {% endfor %} +
    +
    +
    +
    +
    \ No newline at end of file diff --git a/system/templates/mail.password_changed.html b/system/templates/mail.password_changed.html new file mode 100644 index 00000000..806a7edf --- /dev/null +++ b/system/templates/mail.password_changed.html @@ -0,0 +1,3 @@ +

    Password to account changed!

    +

    You or someone else changed password to your account on server {{ config.lua.serverName }}.

    +

    New password: {{ new_password }}

    ' \ No newline at end of file diff --git a/tools/check_name.js b/tools/check_name.js index 8e92fc68..f2a314f1 100644 --- a/tools/check_name.js +++ b/tools/check_name.js @@ -9,7 +9,7 @@ function checkName() eventId = 0; } - if(document.getElementById("newcharname").value=="") + if(document.getElementById("name").value=="") { document.getElementById("name_check").innerHTML = 'Please enter new character name.'; return; @@ -28,8 +28,8 @@ function checkName() } } - var newcharname = document.getElementById("newcharname").value; - $.get("tools/validate.php", { name: newcharname, uid: Math.random() }, + var name = document.getElementById("name").value; + $.get("tools/validate.php", { name: name, uid: Math.random() }, function(data){ document.getElementById("name_check").innerHTML = data; lastSend = timeNow;