Skip to content

Commit

Permalink
Updates coding style
Browse files Browse the repository at this point in the history
Signed-off-by: Jon Stovell <[email protected]>
  • Loading branch information
Sesquipedalian committed Nov 15, 2023
1 parent d02e6d2 commit a86ccb8
Show file tree
Hide file tree
Showing 293 changed files with 52,437 additions and 53,606 deletions.
101 changes: 51 additions & 50 deletions Sources/Actions/Activate.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
namespace SMF\Actions;

use SMF\BackwardCompatibility;

use SMF\Config;
use SMF\Db\DatabaseApi as Db;
use SMF\ErrorHandler;
use SMF\IntegrationHook;
use SMF\Lang;
Expand All @@ -25,7 +25,6 @@
use SMF\Theme;
use SMF\User;
use SMF\Utils;
use SMF\Db\DatabaseApi as Db;

/**
* Activates a user's account.
Expand All @@ -39,11 +38,11 @@ class Activate implements ActionInterface
*
* BackwardCompatibility settings for this class.
*/
private static $backcompat = array(
'func_names' => array(
private static $backcompat = [
'func_names' => [
'call' => 'Activate',
),
);
],
];


/*******************
Expand All @@ -66,10 +65,10 @@ class Activate implements ActionInterface
*
* Available sub-actions.
*/
public static array $subactions = array(
public static array $subactions = [
'activate' => 'activate',
'resend' => 'resend',
);
];

/****************************
* Internal static properties
Expand All @@ -94,36 +93,37 @@ class Activate implements ActionInterface
*/
public function execute(): void
{
if (empty($_REQUEST['u']) && empty($_POST['user']))
{
if (empty(Config::$modSettings['registration_method']) || Config::$modSettings['registration_method'] == '3')
if (empty($_REQUEST['u']) && empty($_POST['user'])) {
if (empty(Config::$modSettings['registration_method']) || Config::$modSettings['registration_method'] == '3') {
ErrorHandler::fatalLang('no_access', false);
}

Utils::$context['member_id'] = 0;
Utils::$context['sub_template'] = 'resend';
Utils::$context['page_title'] = Lang::$txt['invalid_activation_resend'];
Utils::$context['can_activate'] = empty(Config::$modSettings['registration_method']) || Config::$modSettings['registration_method'] == '1';
Utils::$context['default_username'] = isset($_GET['user']) ? $_GET['user'] : '';
Utils::$context['default_username'] = $_GET['user'] ?? '';

return;
}

// Get the code from the database...
$request = Db::$db->query('', '
$request = Db::$db->query(
'',
'
SELECT id_member, validation_code, member_name, real_name, email_address, is_activated, passwd, lngfile
FROM {db_prefix}members' . (empty($_REQUEST['u']) ? '
WHERE member_name = {string:email_address} OR email_address = {string:email_address}' : '
WHERE id_member = {int:id_member}') . '
LIMIT 1',
array(
[
'id_member' => isset($_REQUEST['u']) ? (int) $_REQUEST['u'] : 0,
'email_address' => isset($_POST['user']) ? $_POST['user'] : '',
)
'email_address' => $_POST['user'] ?? '',
],
);

// Does this user exist at all?
if (Db::$db->num_rows($request) == 0)
{
if (Db::$db->num_rows($request) == 0) {
Utils::$context['sub_template'] = 'retry_activate';
Utils::$context['page_title'] = Lang::$txt['invalid_userid'];
Utils::$context['member_id'] = 0;
Expand All @@ -143,33 +143,37 @@ public function execute(): void
$row['is_activated'] == 0
|| $row['is_activated'] == 2
)
)
{
if (empty(Config::$modSettings['registration_method']) || Config::$modSettings['registration_method'] == 3)
) {
if (empty(Config::$modSettings['registration_method']) || Config::$modSettings['registration_method'] == 3) {
ErrorHandler::fatalLang('no_access', false);
}

if (!filter_var($_POST['new_email'], FILTER_VALIDATE_EMAIL))
if (!filter_var($_POST['new_email'], FILTER_VALIDATE_EMAIL)) {
ErrorHandler::fatal(sprintf(Lang::$txt['valid_email_needed'], Utils::htmlspecialchars($_POST['new_email'])), false);
}

// Make sure their email isn't banned.
User::isBannedEmail($_POST['new_email'], 'cannot_register', Lang::$txt['ban_register_prohibited']);

// Ummm... don't even dare try to take someone else's email!!
$request = Db::$db->query('', '
$request = Db::$db->query(
'',
'
SELECT id_member
FROM {db_prefix}members
WHERE email_address = {string:email_address}
LIMIT 1',
array(
[
'email_address' => $_POST['new_email'],
)
],
);

if (Db::$db->num_rows($request) != 0)
ErrorHandler::fatalLang('email_in_use', false, array(Utils::htmlspecialchars($_POST['new_email'])));
if (Db::$db->num_rows($request) != 0) {
ErrorHandler::fatalLang('email_in_use', false, [Utils::htmlspecialchars($_POST['new_email'])]);
}
Db::$db->free_result($request);

User::updateMemberData($row['id_member'], array('email_address' => $_POST['new_email']));
User::updateMemberData($row['id_member'], ['email_address' => $_POST['new_email']]);
$row['email_address'] = $_POST['new_email'];

$email_change = true;
Expand All @@ -181,16 +185,15 @@ public function execute(): void
&& $_REQUEST['sa'] == 'resend'
&& ($row['is_activated'] == 0 || $row['is_activated'] == 2)
&& (!isset($_REQUEST['code']) || $_REQUEST['code'] == '')
)
{
$replacements = array(
) {
$replacements = [
'REALNAME' => $row['real_name'],
'USERNAME' => $row['member_name'],
'ACTIVATIONLINK' => Config::$scripturl . '?action=activate;u=' . $row['id_member'] . ';code=' . $row['validation_code'],
'ACTIVATIONLINKWITHOUTCODE' => Config::$scripturl . '?action=activate;u=' . $row['id_member'],
'ACTIVATIONCODE' => $row['validation_code'],
'FORGOTPASSWORDLINK' => Config::$scripturl . '?action=reminder',
);
];

$emaildata = Mail::loadEmailTemplate('resend_activate_message', $replacements, empty($row['lngfile']) || empty(Config::$modSettings['userLanguage']) ? Lang::$default : $row['lngfile']);

Expand All @@ -201,18 +204,14 @@ public function execute(): void
// This will ensure we don't actually get an error message if it works!
Utils::$context['error_title'] = Lang::$txt['invalid_activation_resend'];

ErrorHandler::fatalLang(!empty($email_change) ? 'change_email_success' : 'resend_email_success', false, array(), false);
ErrorHandler::fatalLang(!empty($email_change) ? 'change_email_success' : 'resend_email_success', false, [], false);
}

// Quit if this code is not right.
if (empty($_REQUEST['code']) || $row['validation_code'] != $_REQUEST['code'])
{
if (!empty($row['is_activated']))
{
if (empty($_REQUEST['code']) || $row['validation_code'] != $_REQUEST['code']) {
if (!empty($row['is_activated'])) {
ErrorHandler::fatalLang('already_activated', false);
}
elseif ($row['validation_code'] == '')
{
} elseif ($row['validation_code'] == '') {
Lang::load('Profile');
ErrorHandler::fatal(sprintf(Lang::$txt['registration_not_approved'], Config::$scripturl . '?action=activate;user=' . $row['member_name']), false);
}
Expand All @@ -225,28 +224,27 @@ public function execute(): void
}

// Let the integration know that they've been activated!
IntegrationHook::call('integrate_activate', array($row['member_name']));
IntegrationHook::call('integrate_activate', [$row['member_name']]);

// Validation complete - update the database!
User::updateMemberData($row['id_member'], array('is_activated' => 1, 'validation_code' => ''));
User::updateMemberData($row['id_member'], ['is_activated' => 1, 'validation_code' => '']);

// Also do a proper member stat re-evaluation.
Logging::updateStats('member', false);

// Notify the admin about new activations, but not re-activations.
if (empty($row['is_activated']))
{
if (empty($row['is_activated'])) {
Mail::adminNotify('activation', $row['id_member'], $row['member_name']);
}

Utils::$context += array(
Utils::$context += [
'page_title' => Lang::$txt['registration_successful'],
'sub_template' => 'login',
'default_username' => $row['member_name'],
'default_password' => '',
'never_expire' => false,
'description' => Lang::$txt['activate_success']
);
'description' => Lang::$txt['activate_success'],
];
}

/***********************
Expand All @@ -260,8 +258,9 @@ public function execute(): void
*/
public static function load(): object
{
if (!isset(self::$obj))
if (!isset(self::$obj)) {
self::$obj = new self();
}

return self::$obj;
}
Expand All @@ -284,16 +283,18 @@ public static function call(): void
protected function __construct()
{
// Logged in users should not bother to activate their accounts
if (!empty(User::$me->id))
if (!empty(User::$me->id)) {
Utils::redirectexit();
}

Lang::load('Login');
Theme::loadTemplate('Login');
}
}

// Export public static functions and properties to global namespace for backward compatibility.
if (is_callable(__NAMESPACE__ . '\Activate::exportStatic'))
if (is_callable(__NAMESPACE__ . '\\Activate::exportStatic')) {
Activate::exportStatic();
}

?>
Loading

0 comments on commit a86ccb8

Please sign in to comment.