From 3fa2c2de3aa205b18174e147bfd6291c20f93cab Mon Sep 17 00:00:00 2001 From: Elson Costa Date: Tue, 28 May 2024 15:05:26 -0300 Subject: [PATCH] feat: resend account verify and check login (#88) --- config.php | 15 ++-- index.php | 1 + login.php | 4 ++ system/pages/account/resend_verify.php | 58 +++++++++++++++ system/pages/accountmanagement.php | 9 +++ ...ccount.generate_new_recovery_key.html.twig | 17 ++++- .../account.resend_verify_email.html.twig | 71 +++++++++++++++++++ .../tibiacom/account.management.html.twig | 38 ++++++---- 8 files changed, 191 insertions(+), 22 deletions(-) create mode 100644 system/pages/account/resend_verify.php create mode 100644 system/templates/account.resend_verify_email.html.twig diff --git a/config.php b/config.php index 2fc8b52a8b..a175bf22f7 100644 --- a/config.php +++ b/config.php @@ -97,13 +97,14 @@ '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 - 'account_mail_confirmed_reward' => [ // reward users for confirming their E-Mails - // account_mail_verify needs to be enabled too - 'premium_days' => 0, - 'coins_transferable' => 0, - 'coins' => 0, - 'message' => 'You received %d %s for confirming your E-Mail address.' // example: You received 20 coins for confirming your E-Mail address. - ], + 'account_verified_only' => false, // force users to confirm their email to login in game + 'account_mail_confirmed_reward' => [ // reward users for confirming their E-Mails + // account_mail_verify needs to be enabled too + 'premium_days' => 0, + 'coins_transferable' => 0, + 'coins' => 0, + 'message' => 'You received %d %s for confirming your E-Mail address.' // example: You received 20 coins for confirming your E-Mail address. + ], 'account_mail_unique' => true, // email addresses cannot be duplicated? (one account = one email) 'account_premium_days' => 0, // default premium days on new account 'account_premium_coins' => 0, // default coins on new account diff --git a/index.php b/index.php index 65a64c69c8..b174fd7a12 100644 --- a/index.php +++ b/index.php @@ -92,6 +92,7 @@ '/^account\/password\/?$/' => array('subtopic' => 'accountmanagement', 'action' => 'change_password'), '/^account\/register\/?$/' => array('subtopic' => 'accountmanagement', 'action' => 'register'), '/^account\/register\/new\/?$/' => array('subtopic' => 'accountmanagement', 'action' => 'register_new'), + '/^account\/resend\/verify\/?$/' => array('subtopic' => 'accountmanagement', 'action' => 'resend_verify'), '/^account\/email\/?$/' => array('subtopic' => 'accountmanagement', 'action' => 'change_email'), '/^account\/info\/?$/' => array('subtopic' => 'accountmanagement', 'action' => 'change_info'), '/^account\/character\/create\/?$/' => array('subtopic' => 'accountmanagement', 'action' => 'create_character'), diff --git a/login.php b/login.php index d1a3e9f919..1c6a671d1b 100644 --- a/login.php +++ b/login.php @@ -116,6 +116,10 @@ function parseEvent($table1, $date, $table2) sendError('Email or password is not correct.'); } + if ($config['account_verified_only'] && $config['mail_enabled'] && $config['account_mail_verify'] && $account->getCustomField('email_verified') != '1') { + sendError('You need to verify your account, enter in our site and resend verify e-mail!'); + } + // common columns $columns = 'name, level, sex, vocation, looktype, lookhead, lookbody, looklegs, lookfeet, lookaddons, lastlogin, isreward, istutorial, ismain, hidden'; $players = $db->query("SELECT {$columns} FROM players WHERE account_id = {$account->getId()} AND deletion = 0"); diff --git a/system/pages/account/resend_verify.php b/system/pages/account/resend_verify.php new file mode 100644 index 0000000000..71e8ae7b94 --- /dev/null +++ b/system/pages/account/resend_verify.php @@ -0,0 +1,58 @@ +getName(); + $accEmail = $account_logged->getEMail(); + + if ($account_logged->getCustomField('email_verified') == '1') { + echo "You account is already verified!"; + return; + } + + if (isset($_POST['confirmresend']) && $_POST['confirmresend'] == '1') { + $hash = md5(generateRandomString(16, true, true) . $accEmail); + $account_logged->setCustomField('email_hash', $hash); + + $verify_url = getLink('account/confirm_email/' . $hash); + $body_html = $twig->render('mail.account.verify.html.twig', array( + 'account' => $accName, + 'verify_url' => generateLink($verify_url, $verify_url, true) + )); + + if (_mail($accEmail, configLua('serverName') . ' - Verify Account', $body_html)) { + $message = "
Your request was sent on email address {$accEmail}"; + $show_form = false; + } else { + $message = "

An error occurred while sending email ( {$accEmail} )! Try again later. For Admin: More info can be found in system/logs/mailer-error.log

"; + } + + $twig->display('success.html.twig', array( + 'title' => 'Verify Email Sent', + 'description' => "" + )); + } + + //show errors if not empty + if (!empty($errors)) { + $twig->display('error_box.html.twig', array('errors' => $errors)); + } + + if ($show_form) { + $twig->display('account.resend_verify_email.html.twig', array( + 'name' => $accName, + 'email' => $accEmail, + )); + } +} diff --git a/system/pages/accountmanagement.php b/system/pages/accountmanagement.php index 5b69f7faf7..0bd7b45c40 100644 --- a/system/pages/accountmanagement.php +++ b/system/pages/accountmanagement.php @@ -1,4 +1,5 @@ getCustomField('email_verified') != '1') { + $verifyLink = getLink('account/resend/verify'); + $type = ($config['account_verified_only'] ?? false) ? 'required' : 'optional'; + $verify_message = "Verification is {$type}! Please Verify your Account!"; + } + $email_change = ''; $email_request = false; if ($email_new_time > 1) { @@ -128,6 +136,7 @@ $twig->display('account.management.html.twig', array( 'welcome_message' => $welcome_message, + 'verify_message' => $verify_message, 'recovery_key' => $recovery_key, 'email_change' => $email_change, 'email_request' => $email_request, diff --git a/system/templates/account.generate_new_recovery_key.html.twig b/system/templates/account.generate_new_recovery_key.html.twig index 563e902d1b..45c1a26497 100644 --- a/system/templates/account.generate_new_recovery_key.html.twig +++ b/system/templates/account.generate_new_recovery_key.html.twig @@ -1,6 +1,21 @@ To generate new recovery key for your account please enter your password.
-New recovery key cost {{ config.generate_new_reckey_price }} {{ coin_type }}. You have {{ coins }} {{ coin_type }}. You will receive e-mail with this recovery key. +New recovery key cost: {{ config.generate_new_reckey_price }} {{ coin_name }}. You will receive e-mail with this recovery key.
+ + Coins Balance: + {% if coins > 0 %} + {{ coins }} {{ coin_name }} + {% if coins < config.account_change_character_name_coins %} + (you do not have {{ coin_name }} enough, + donate now) + {% endif %} + + {% else %} + You do not have {{ coin_name }}, + donate now + {% endif %} +

+
diff --git a/system/templates/account.resend_verify_email.html.twig b/system/templates/account.resend_verify_email.html.twig new file mode 100644 index 0000000000..839c8df60e --- /dev/null +++ b/system/templates/account.resend_verify_email.html.twig @@ -0,0 +1,71 @@ +Check your information and confirm to send verify e-mail. +

+ + +
+ +
+
+ + + + +
Confirm Send Verify Email
+ + + + +
+
+ + + +
+
+ + + + + + + + + +
Account name:{{ name }}
E-mail:{{ email }}
+
+
+
+
+ + + + + +
+ + + + + +
+ {{ include('buttons.submit.html.twig') }} +
+
+ + + + + + +
+ {{ include('buttons.back.html.twig') }} +
+
diff --git a/templates/tibiacom/account.management.html.twig b/templates/tibiacom/account.management.html.twig index 095fa5ba47..713c921483 100644 --- a/templates/tibiacom/account.management.html.twig +++ b/templates/tibiacom/account.management.html.twig @@ -2,15 +2,24 @@ - +
- + {{ welcome_message|raw }}
-
+ {% if verify_message is not empty %} + + + + +
{{ verify_message|raw }} +
+ {% endif %} +
-
+
{% endif %}
@@ -474,13 +484,13 @@ style="background-image:url({{ template_path }}/images/content/box-frame-edge.gif);">
-
+
{% endif %} @@ -542,7 +552,7 @@ Tibia Coins: {{ account_coins }} + class="VSCCoinImages" /> (Including: {{ account_coins_transferable }} ) @@ -584,7 +594,7 @@
- + {{ include('buttons.change_email.html.twig') }} @@ -618,13 +628,13 @@ -
+
@@ -708,13 +718,13 @@ -
+