From 85422b4201a283763a24a4c417df3c706c8480bf Mon Sep 17 00:00:00 2001 From: AntonLV Date: Mon, 23 Sep 2024 15:05:02 +0300 Subject: [PATCH] Ticket #4810 - Add default value for Remember Me feature. --- inc/profiles.inc.php | 5 +++++ install/sql/system.sql | 4 +++- member.php | 6 +++--- modules/boonex/english/data/langs/system/en.xml | 1 + modules/boonex/russian/data/langs/system/ru.xml | 1 + template/scripts/BxBaseAccountForms.php | 4 ++-- template/scripts/BxBaseFormLogin.php | 5 +++++ template/scripts/BxBaseServiceAccount.php | 2 +- template/scripts/BxBaseServiceLogin.php | 2 +- 9 files changed, 22 insertions(+), 8 deletions(-) diff --git a/inc/profiles.inc.php b/inc/profiles.inc.php index 4306695ff9..9d7e34f223 100644 --- a/inc/profiles.inc.php +++ b/inc/profiles.inc.php @@ -188,6 +188,11 @@ function bx_logout($bNotify = true) BxDolSession::getInstance()->setUserId(0); } +function bx_is_remember_me() +{ + return getParam('sys_account_remember_me') == 'on'; +} + /** * Check if user is logged in (necessary cookies are present) and set some global variables */ diff --git a/install/sql/system.sql b/install/sql/system.sql index f51c88f6bc..5c3a839641 100644 --- a/install/sql/system.sql +++ b/install/sql/system.sql @@ -649,7 +649,9 @@ INSERT INTO `sys_options`(`category_id`, `name`, `caption`, `value`, `type`, `ex (@iCategoryId, 'sys_account_accounts_force_password_change_after_expiration', '_adm_stg_cpt_option_sys_accounts_force_password_change_after_expiration', '', 'checkbox', '', '', '', 58), (@iCategoryId, 'sys_account_switch_to_profile_redirect', '_adm_stg_cpt_option_sys_account_switch_to_profile_redirect', 'back', 'select', 'a:3:{s:6:"module";s:6:"system";s:6:"method";s:38:"get_options_switch_to_profile_redirect";s:5:"class";s:18:"BaseServiceAccount";}', '', '', 60), -(@iCategoryId, 'sys_account_switch_to_profile_redirect_custom', '_adm_stg_cpt_option_sys_account_switch_to_profile_redirect_custom', '', 'digit', '', '', '', 61); +(@iCategoryId, 'sys_account_switch_to_profile_redirect_custom', '_adm_stg_cpt_option_sys_account_switch_to_profile_redirect_custom', '', 'digit', '', '', '', 61), + +(@iCategoryId, 'sys_account_remember_me', '_adm_stg_cpt_option_sys_account_remember_me', 'on', 'checkbox', '', '', '', 70); -- -- CATEGORY: ACL -- diff --git a/member.php b/member.php index 6f51bd2283..bfb87c1a1a 100644 --- a/member.php +++ b/member.php @@ -28,7 +28,7 @@ if ($bLoginSuccess) { $s = 'OK'; $oAccount = BxDolAccount::getInstance(trim($oForm->getCleanValue('ID'))); - $aAccount = bx_login($oAccount->id(), ($oForm->getCleanValue('rememberMe') ? true : false)); + $aAccount = bx_login($oAccount->id(), $oForm->getRememberMe()); } else { $s = $oForm->getLoginError(); @@ -56,12 +56,12 @@ && (getParam('sys_account_activation_2fa_lifetime') == 0 || (time() - $aAccountInfo['logged'] > getParam('sys_account_activation_2fa_lifetime')))){ $oSession = BxDolSession::getInstance(); $oSession->setValue(BX_ACCOUNT_SESSION_KEY_FOR_2FA_LOGIN_ACCOUNT_ID, trim($oForm->getCleanValue('ID'))); - $oSession->setValue(BX_ACCOUNT_SESSION_KEY_FOR_2FA_LOGIN_IS_REMEMBER, ($oForm->getCleanValue('rememberMe') ? true : false)); + $oSession->setValue(BX_ACCOUNT_SESSION_KEY_FOR_2FA_LOGIN_IS_REMEMBER, $oForm->getRememberMe()); header('Location: ' . BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=login-step2')); } else{ - $aAccount = bx_login($oAccount->id(), ($oForm->getCleanValue('rememberMe') ? true : false)); + $aAccount = bx_login($oAccount->id(), $oForm->getRememberMe()); $sUrlRelocate = $oForm->getCleanValue('relocate'); if (!$sUrlRelocate || 0 !== strncmp($sUrlRelocate, BX_DOL_URL_ROOT, strlen(BX_DOL_URL_ROOT))) diff --git a/modules/boonex/english/data/langs/system/en.xml b/modules/boonex/english/data/langs/system/en.xml index 42b3c352e5..52f5a3ae7f 100644 --- a/modules/boonex/english/data/langs/system/en.xml +++ b/modules/boonex/english/data/langs/system/en.xml @@ -1603,6 +1603,7 @@ + diff --git a/modules/boonex/russian/data/langs/system/ru.xml b/modules/boonex/russian/data/langs/system/ru.xml index f9783efe1a..504504c2d4 100644 --- a/modules/boonex/russian/data/langs/system/ru.xml +++ b/modules/boonex/russian/data/langs/system/ru.xml @@ -1579,6 +1579,7 @@ + diff --git a/template/scripts/BxBaseAccountForms.php b/template/scripts/BxBaseAccountForms.php index 777d5ba5fe..c5443e3f7c 100644 --- a/template/scripts/BxBaseAccountForms.php +++ b/template/scripts/BxBaseAccountForms.php @@ -220,7 +220,7 @@ public function onAccountCreated ($iAccountId, $isSetPendingApproval, $iAction = // login to the created account automatically if ($bNeedToLogin) - bx_login($iAccountId); + bx_login($iAccountId, bx_is_remember_me()); return $iProfileId; } @@ -328,7 +328,7 @@ protected function _editAccountForm ($iAccountId, $sDisplayName) // relogin with new password bx_alert('account', 'edited', $aAccountInfo['id'], $aAccountInfo['id'], array('action' => 'change_password')); bx_logout(); - bx_login($aAccountInfo['id']); + bx_login($aAccountInfo['id'], bx_is_remember_me()); } // check if other text info was changed - if auto-appproval is off diff --git a/template/scripts/BxBaseFormLogin.php b/template/scripts/BxBaseFormLogin.php index 420270345c..cda2f244f0 100644 --- a/template/scripts/BxBaseFormLogin.php +++ b/template/scripts/BxBaseFormLogin.php @@ -112,6 +112,11 @@ public function setRole ($iRole) $this->_iRole = $iRole == BX_DOL_ROLE_ADMIN ? BX_DOL_ROLE_ADMIN : BX_DOL_ROLE_MEMBER; } + public function getRememberMe() + { + return isset($this->aInputs['rememberMe']) ? (bool)$this->getCleanValue('rememberMe') : bx_is_remember_me(); + } + public function getLoginError () { return isset($this->aInputs['ID']['error']) ? $this->aInputs['ID']['error'] : ''; diff --git a/template/scripts/BxBaseServiceAccount.php b/template/scripts/BxBaseServiceAccount.php index 3e64f9581b..0426cbde66 100644 --- a/template/scripts/BxBaseServiceAccount.php +++ b/template/scripts/BxBaseServiceAccount.php @@ -886,7 +886,7 @@ protected function _confirmEmail($sKey) return _t("_sys_txt_confirm_email_error_occured"); // login to user's account automatically - bx_login($aData['account_id']); + bx_login($aData['account_id'], bx_is_remember_me()); return (int)$aData['account_id']; } diff --git a/template/scripts/BxBaseServiceLogin.php b/template/scripts/BxBaseServiceLogin.php index 9ed1447e32..efcf9d619a 100644 --- a/template/scripts/BxBaseServiceLogin.php +++ b/template/scripts/BxBaseServiceLogin.php @@ -186,7 +186,7 @@ public function serviceLoginForm ($sParams = '', $sForceRelocate = '') if ($oForm->isSubmittedAndValid()) { $oAccount = BxDolAccount::getInstance(trim($oForm->getCleanValue('ID'))); - bx_login($oAccount->id(), ($oForm->getCleanValue('rememberMe') ? true : false)); + bx_login($oAccount->id(), $oForm->getRememberMe()); return [ //bx_api_get_block('login', ['session' => BxDolSession::getInstance()->getId()], ['id' => 2]), bx_api_get_block('redirect', ['uri' => '/']),