diff --git a/config.php b/config.php index 58ef4b46..a4fa1ac3 100644 --- a/config.php +++ b/config.php @@ -99,6 +99,8 @@ $config = array( // account 'account_management' => true, // disable if you're using other method to manage users (fe. tfs account manager) + 'account_login_by_email' => false, // use email instead of Account Name like in latest Tibia + 'account_login_by_email_fallback' => false, // allow also additionally login by Account Name/Number (for users that might forget their email) 'account_create_auto_login' => false, // auto login after creating account? 'account_create_character_create' => true, // allow directly to create character on create account page? 'account_mail_verify' => false, // force users to confirm their email addresses when registering account diff --git a/system/functions.php b/system/functions.php index fee72b27..b1f4e77f 100644 --- a/system/functions.php +++ b/system/functions.php @@ -1464,6 +1464,23 @@ function truncate($string, $length) return $string; } +function getAccountLoginByLabel() +{ + $ret = ''; + if (config('account_login_by_email')) { + $ret = 'Email Address'; + if (config('account_login_by_email_fallback')) { + $ret .= ' or '; + } + } + + if (!config('account_login_by_email') || config('account_login_by_email_fallback')) { + $ret .= 'Account ' . (USE_ACCOUNT_NAME ? 'Name' : 'Number'); + } + + return $ret; +} + // validator functions require_once LIBS . 'validator.php'; require_once SYSTEM . 'compat.php'; diff --git a/system/login.php b/system/login.php index 330efd13..c004f03c 100644 --- a/system/login.php +++ b/system/login.php @@ -85,10 +85,17 @@ else } $account_logged = new OTS_Account(); - if(USE_ACCOUNT_NAME) - $account_logged->find($login_account); - else - $account_logged->load($login_account, true); + if (config('account_login_by_email')) { + $account_logged->findByEMail($login_account); + } + + if (!config('account_login_by_email') || config('account_login_by_email_fallback')) { + if(USE_ACCOUNT_NAME) { + $account_logged->find($login_account); + } else { + $account_logged->load($login_account, true); + } + } $config_salt_enabled = $db->hasColumn('accounts', 'salt'); if($account_logged->isLoaded() && encrypt(($config_salt_enabled ? $account_logged->getCustomField('salt') : '') . $login_password) == $account_logged->getPassword() @@ -121,6 +128,8 @@ else { $hooks->trigger(HOOK_LOGIN_ATTEMPT, array('account' => $login_account, 'password' => $login_password, 'remember_me' => $remember_me)); + $errorMessage = getAccountLoginByLabel() . ' or password is not correct.'; + // temporary solution for blocking failed login attempts if($cache->enabled()) { @@ -132,24 +141,24 @@ else if($t['attempts'] >= 5) $errors[] = 'A wrong password has been entered 5 times in a row. You are unable to log into your account for the next 5 minutes. Please wait.'; else - $errors[] = 'Account name or password is not correct.'; + $errors[] = $errorMessage; } else { $t = array('attempts' => 1, 'last' => time()); - $errors[] = 'Account name or password is not correct.'; + $errors[] = $errorMessage; } $tmp[$ip] = $t; $cache->set('failed_logins', serialize($tmp), 60 * 60); // save for 1 hour } else { - $errors[] = 'Account name or password is not correct.'; + $errors[] = $errorMessage; } } } else { - $errors[] = 'Please enter your account ' . (USE_ACCOUNT_NAME ? 'name' : 'number') . ' and password.'; + $errors[] = 'Please enter your ' . getAccountLoginByLabel() . ' and password.'; $hooks->trigger(HOOK_LOGIN_ATTEMPT, array('account' => $login_account, 'password' => $login_password, 'remember_me' => $remember_me)); } diff --git a/system/pages/accountmanagement.php b/system/pages/accountmanagement.php index e3444a73..1a4cb583 100644 --- a/system/pages/accountmanagement.php +++ b/system/pages/accountmanagement.php @@ -40,6 +40,7 @@ if(!$logged) $twig->display('account.login.html.twig', array( 'redirect' => isset($_REQUEST['redirect']) ? $_REQUEST['redirect'] : null, 'account' => USE_ACCOUNT_NAME ? 'Name' : 'Number', + 'account_login_by' => getAccountLoginByLabel(), 'error' => isset($errors[0]) ? $errors[0] : null )); diff --git a/system/pages/admin/login.php b/system/pages/admin/login.php index 2c6d4e9f..24c1e9b5 100644 --- a/system/pages/admin/login.php +++ b/system/pages/admin/login.php @@ -13,5 +13,6 @@ $title = 'Login'; $twig->display('admin.login.html.twig', array( 'logout' => ($action == 'logout' ? 'You have been logged out!' : ''), 'account' => USE_ACCOUNT_NAME ? 'Name' : 'Number', + 'account_login_by' => getAccountLoginByLabel(), 'errors' => isset($errors)? $errors : '' )); diff --git a/system/templates/account.create.html.twig b/system/templates/account.create.html.twig index 8d9d57f9..245adc4e 100644 --- a/system/templates/account.create.html.twig +++ b/system/templates/account.create.html.twig @@ -30,6 +30,7 @@ {{ hook('HOOK_ACCOUNT_CREATE_BEFORE_ACCOUNT') }} + {% if not config.account_login_by_email %}
Account {{ account }}: | ++ {{ account_login_by }}: + | |