mirror of
https://github.com/slawkens/myaac.git
synced 2025-04-26 09:19:22 +02:00
feat: Login By Email
This commit is contained in:
parent
f9302d4f9d
commit
02f993baea
@ -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
|
||||
|
@ -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';
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -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
|
||||
));
|
||||
|
||||
|
@ -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 : ''
|
||||
));
|
||||
|
@ -30,6 +30,7 @@
|
||||
|
||||
{{ hook('HOOK_ACCOUNT_CREATE_BEFORE_ACCOUNT') }}
|
||||
|
||||
{% if not config.account_login_by_email %}
|
||||
<tr>
|
||||
<td class="LabelV" style="width: 150px">
|
||||
<span{% if errors.account is defined %} class="red"{% endif %}>Account {% if constant('USE_ACCOUNT_NAME') %}Name{% else %}Number{% endif %}:</span>
|
||||
@ -39,6 +40,7 @@
|
||||
<img id="account_indicator" src="images/global/general/{% if not save or errors.account is defined %}n{% endif %}ok.gif" style="display: none;" />
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
<tr><td></td><td><span id="account_error" class="FormFieldError">{% if errors.account is defined %}{{ errors.account }}{% endif %}</span></td></tr>
|
||||
{{ hook('HOOK_ACCOUNT_CREATE_AFTER_ACCOUNT') }}
|
||||
<tr>
|
||||
|
@ -24,7 +24,7 @@ Please enter your account {{ account|lower }} and your password.<br/><a href="?s
|
||||
<table style="width:100%;" >
|
||||
<tr>
|
||||
<td class="LabelV" >
|
||||
<span{% if error is not null %} class="red"{% endif %}>Account {{ account }}:</span>
|
||||
<span{% if error is not null %} class="red"{% endif %}>{{ account_login_by }}:</span>
|
||||
</td>
|
||||
<td style="width:100%;" ><input type="text" name="account_login" size="30" maxlength="30" autofocus/></td>
|
||||
</tr>
|
||||
@ -73,4 +73,4 @@ Please enter your account {{ account|lower }} and your password.<br/><a href="?s
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</table>
|
||||
|
@ -23,8 +23,7 @@
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-lock"></i></span>
|
||||
</div>
|
||||
<input type="text" class="form-control" id="account-name-input" name="account_login"
|
||||
placeholder="Account {{ account }}" required autofocus>
|
||||
<input type="text" class="form-control" id="account-name-input" name="account_login" placeholder="{{ account_login_by }}" required autofocus>
|
||||
</div>
|
||||
|
||||
<div class="input-group mb-3">
|
||||
|
@ -33,7 +33,9 @@
|
||||
<td>
|
||||
<table style="float: left; width: 370px;" cellpadding="0" cellspacing="0" >
|
||||
<tr>
|
||||
<td class="LabelV" ><span{% if error is not null %} class="red"{% endif %}>Account {{ account }}:</span></td>
|
||||
<td class="LabelV">
|
||||
<span{% if error is not null %} class="red"{% endif %}>{{ account_login_by }}:</span>
|
||||
</td>
|
||||
<td><input type="text" name="account_login" size="35" maxlength="30" autofocus /></td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
Loading…
x
Reference in New Issue
Block a user