Explorar el Código

Ticket #4810 - Add default value for Remember Me feature.

AntonLV hace 2 años
padre
commit
85422b4201

+ 5 - 0
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
  */

+ 3 - 1
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
 --

+ 3 - 3
member.php

@@ -28,7 +28,7 @@ if (isset($_POST['ID'])) { // login form is submitted
         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 @@ if (isset($_POST['ID'])) { // login form is submitted
             && (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)))

+ 1 - 0
modules/boonex/english/data/langs/system/en.xml

@@ -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>

+ 1 - 0
modules/boonex/russian/data/langs/system/ru.xml

@@ -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>

+ 2 - 2
template/scripts/BxBaseAccountForms.php

@@ -220,7 +220,7 @@ class BxBaseAccountForms extends BxDolProfileForms
 
         // login to the created account automatically
         if ($bNeedToLogin)
-            bx_login($iAccountId);
+            bx_login($iAccountId, bx_is_remember_me());
 
         return $iProfileId;
     }
@@ -328,7 +328,7 @@ class BxBaseAccountForms extends BxDolProfileForms
             // 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

+ 5 - 0
template/scripts/BxBaseFormLogin.php

@@ -112,6 +112,11 @@ class BxBaseFormLogin extends BxTemplFormView
         $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'] : '';

+ 1 - 1
template/scripts/BxBaseServiceAccount.php

@@ -886,7 +886,7 @@ class BxBaseServiceAccount extends BxDol
             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'];
     }

+ 1 - 1
template/scripts/BxBaseServiceLogin.php

@@ -186,7 +186,7 @@ class BxBaseServiceLogin extends BxDol
             
             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' => '/']),