Skip to content

Commit

Permalink
Patching from develop
Browse files Browse the repository at this point in the history
* Allow account_create_character_create even if account_mail_verify is activated
* Fixes to account verify - do not allow login without verified email (Thanks @anyeor)
  • Loading branch information
slawkens committed Jul 9, 2024
1 parent 0ffc5f6 commit 1edf883
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 33 deletions.
2 changes: 1 addition & 1 deletion system/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
$config['highscores_ids_hidden'] = array(0);
}

$config['account_create_character_create'] = config('account_create_character_create') && (!config('mail_enabled') || !config('account_mail_verify'));
$config['account_mail_verify'] = config('account_mail_verify') && config('mail_enabled');

// POT
require_once SYSTEM . 'libs/pot/OTS.php';
Expand Down
40 changes: 22 additions & 18 deletions system/login.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,28 +88,32 @@
&& (!isset($t) || $t['attempts'] < 5)
)
{
session_regenerate_id();
setSession('account', $account_logged->getId());
setSession('password', encrypt(($config_salt_enabled ? $account_logged->getCustomField('salt') : '') . $login_password));
if($remember_me) {
setSession('remember_me', true);
if (config('mail_enabled') && config('account_mail_verify') && (int)$account_logged->getCustomField('email_verified') !== 1) {
$errors[] = 'Your account is not verified. Please verify your email address. If the message is not coming check the SPAM folder in your E-Mail client.';
}
else {
session_regenerate_id();
setSession('account', $account_logged->getId());
setSession('password', encrypt(($config_salt_enabled ? $account_logged->getCustomField('salt') : '') . $login_password));
if ($remember_me) {
setSession('remember_me', true);
}

$logged = true;
$logged_flags = $account_logged->getWebFlags();
$logged = true;
$logged_flags = $account_logged->getWebFlags();

if (isset($_POST['admin']) && !admin()) {
$errors[] = 'This account has no admin privileges.';
unsetSession('account');
unsetSession('password');
unsetSession('remember_me');
$logged = false;
} else {
$account_logged->setCustomField('web_lastlogin', time());
}

if(isset($_POST['admin']) && !admin()) {
$errors[] = 'This account has no admin privileges.';
unsetSession('account');
unsetSession('password');
unsetSession('remember_me');
$logged = false;
$hooks->trigger(HOOK_LOGIN, array('account' => $account_logged, 'password' => $login_password, 'remember_me' => $remember_me));
}
else {
$account_logged->setCustomField('web_lastlogin', time());
}

$hooks->trigger(HOOK_LOGIN, array('account' => $account_logged, 'password' => $login_password, 'remember_me' => $remember_me));
}
else
{
Expand Down
10 changes: 6 additions & 4 deletions system/pages/account/confirm_email.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@
$account = new OTS_Account();
$account->load($query['id']);
if ($account->isLoaded()) {
$db->update('accounts', ['email_verified' => '1'], ['email_hash' => $hash]);
success('You have now verified your e-mail, this will increase the security of your account. Thank you for doing this. You can now <a href=' . getLink('account/manage') . '>log in</a>.');

$hooks->trigger(HOOK_EMAIL_CONFIRMED, ['account' => $account]);
}
}

$db->update('accounts', array('email_verified' => '1'), array('email_hash' => $hash));
success('You have now verified your e-mail, this will increase the security of your account. Thank you for doing this.');
else {
error('Link has expired.');
}
}
?>
21 changes: 12 additions & 9 deletions system/pages/createaccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@
if(_mail($email, 'New account on ' . $config['lua']['serverName'], $body_html))
{
echo 'Your account has been created.<br/><br/>';

warning("Before you can login - you need to verify your E-Mail. The verification link has been sent to $email. If the message is not coming - remember to check the SPAM folder.");

$twig->display('success.html.twig', array(
'title' => 'Account Created',
'description' => 'Your account ' . $account_type . ' is <b>' . $tmp_account . '</b><br/>You will need the account ' . $account_type . ' and your password to play on ' . configLua('serverName') . '.
Expand All @@ -227,15 +230,6 @@
}
else
{
if(config('account_create_character_create')) {
// character creation
$character_created = $createCharacter->doCreate($character_name, $character_sex, $character_vocation, $character_town, $new_account, $errors);
if (!$character_created) {
error('There was an error creating your character. Please create your character later in account management page.');
error(implode(' ', $errors));
}
}

if($config['account_create_auto_login']) {
$_POST['account_login'] = USE_ACCOUNT_NAME ? $account_name : $account_id;
$_POST['password_login'] = $password2;
Expand Down Expand Up @@ -280,6 +274,15 @@
}
}

if(config('account_create_character_create')) {
// character creation
$character_created = $createCharacter->doCreate($character_name, $character_sex, $character_vocation, $character_town, $new_account, $errors);
if (!$character_created) {
error('There was an error creating your character. Please create your character later in account management page.');
error(implode(' ', $errors));
}
}

return;
}
}
Expand Down
2 changes: 1 addition & 1 deletion system/templates/account.create.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@

{{ hook('HOOK_ACCOUNT_CREATE_BETWEEN_BOXES_1') }}

{% if (not config.mail_enabled or not config.account_mail_verify) and config.account_create_character_create %}
{% if config.account_create_character_create %}
<tr>
<td>
<div class="TableShadowContainerRightTop">
Expand Down

0 comments on commit 1edf883

Please sign in to comment.