Skip to content

Commit

Permalink
Ticket #4810 - Add default value for Remember Me feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonLV committed Sep 23, 2024
1 parent fb53c1a commit 85422b4
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 8 deletions.
5 changes: 5 additions & 0 deletions inc/profiles.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
4 changes: 3 additions & 1 deletion install/sql/system.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
--
Expand Down
6 changes: 3 additions & 3 deletions member.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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)))
Expand Down
1 change: 1 addition & 0 deletions modules/boonex/english/data/langs/system/en.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1603,6 +1603,7 @@
<string name="_adm_stg_cpt_option_sys_account_reset_password_redirect_custom"><![CDATA[URL for 'Custom Page' redirect]]></string>
<string name="_adm_stg_cpt_option_sys_account_switch_to_profile_redirect"><![CDATA[Redirect after profile switch to]]></string>
<string name="_adm_stg_cpt_option_sys_account_switch_to_profile_redirect_custom"><![CDATA[URL for 'Custom Page' redirect]]></string>
<string name="_adm_stg_cpt_option_sys_account_remember_me"><![CDATA[Default value for 'Remember me' feature]]></string>
<string name="_adm_stg_cpt_option_value_sys_account_switch_to_profile_redirect_back"><![CDATA[Current page]]></string>
<string name="_adm_stg_cpt_option_value_sys_account_switch_to_profile_redirect_home"><![CDATA[Home page]]></string>
<string name="_adm_stg_cpt_option_value_sys_account_switch_to_profile_redirect_profile"><![CDATA[View profile page]]></string>
Expand Down
1 change: 1 addition & 0 deletions modules/boonex/russian/data/langs/system/ru.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1579,6 +1579,7 @@
<string name="_adm_stg_cpt_option_value_sys_account_pruning_no_profile_delete"><![CDATA[Удалить учетную запись, которая не создавала ни одного профиля в течение N дней]]></string>
<string name="_adm_stg_cpt_option_sys_account_switch_to_profile_redirect"><![CDATA[После смены профиля перенаправить на]]></string>
<string name="_adm_stg_cpt_option_sys_account_switch_to_profile_redirect_custom"><![CDATA[URL для перенаправления 'Пользовательская страница']]></string>
<string name="_adm_stg_cpt_option_sys_account_remember_me"><![CDATA[Значение по умолчанию для функции «Запомнить меня»]]></string>
<string name="_adm_stg_cpt_option_value_sys_account_switch_to_profile_redirect_back"><![CDATA[Текущая страница]]></string>
<string name="_adm_stg_cpt_option_value_sys_account_switch_to_profile_redirect_home"><![CDATA[Главная страница]]></string>
<string name="_adm_stg_cpt_option_value_sys_account_switch_to_profile_redirect_profile"><![CDATA[Страница профиля]]></string>
Expand Down
4 changes: 2 additions & 2 deletions template/scripts/BxBaseAccountForms.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions template/scripts/BxBaseFormLogin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] : '';
Expand Down
2 changes: 1 addition & 1 deletion template/scripts/BxBaseServiceAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}
Expand Down
2 changes: 1 addition & 1 deletion template/scripts/BxBaseServiceLogin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => '/']),
Expand Down

0 comments on commit 85422b4

Please sign in to comment.