RomanL 6 лет назад
Родитель
Сommit
0c824e4b70

+ 9 - 6
install/sql/system.sql

@@ -519,6 +519,7 @@ INSERT INTO `sys_options`(`category_id`, `name`, `caption`, `value`, `type`, `ex
 (@iCategoryId, 'sys_account_autoapproval', '_adm_stg_cpt_option_sys_account_autoapproval', 'on', 'checkbox', '', '', '', 10),
 (@iCategoryId, 'sys_account_confirmation_type', '_adm_stg_cpt_option_sys_account_confirmation_type', 'email', 'select', 'a:3:{s:6:"module";s:6:"system";s:6:"method";s:22:"get_confirmation_types";s:5:"class";s:18:"BaseServiceAccount";}', '', '', 12),
 (@iCategoryId, 'sys_account_activation_2fa_enable', '_adm_stg_cpt_option_sys_account_2fa_enable', '', 'checkbox', '', '', '', 13),
+(@iCategoryId, 'sys_account_activation_2fa_lifetime', '_adm_stg_cpt_option_sys_account_2fa_lifetime', '0', 'digit', '', '', '', 14),
 (@iCategoryId, 'sys_account_auto_profile_creation', '_adm_stg_cpt_option_sys_account_auto_profile_creation', 'on', 'checkbox', '', '', '', 15),
 (@iCategoryId, 'sys_account_hide_unconfirmed_accounts', '_adm_stg_cpt_option_sys_account_hide_unconfirmed_accounts', 'on', 'checkbox', '', '', '', 17),
 (@iCategoryId, 'sys_account_default_profile_type', '_adm_stg_cpt_option_sys_account_default_profile_type', '', 'select', 'a:3:{s:6:"module";s:6:"system";s:6:"method";s:17:"get_profile_types";s:5:"class";s:20:"TemplServiceProfiles";}', '', '', 20),
@@ -3257,6 +3258,7 @@ INSERT INTO `sys_form_inputs` (`object`, `module`, `name`, `value`, `values`, `c
 ('sys_login', 'system', 'do_sendsms', '_sys_form_login_input_sendsms', '', 0, 'submit', '_sys_form_login_input_caption_system_sendsms', '', '', 0, 0, 0, '', '', '', '', '', '', '', '', 0, 0),
 
 ('sys_account', 'system', 'email', '', '', 0, 'text', '_sys_form_login_input_caption_system_email', '_sys_form_account_input_email', '', 1, 0, 0, '', '', '', 'EmailUniq', '', '_sys_form_account_input_email_error', 'Xss', '', 0, 0),
+('sys_account', 'system', 'phone', '', '', 0, 'text', '_sys_form_login_input_caption_system_phone', '_sys_form_login_input_phone', '_sys_form_login_input_phone_info', 1, 0, 0, '', '', '', 'PhoneExist', '', '_sys_form_login_input_phone_error_format', 'Xss', '', 1, 0),
 ('sys_account', 'system', 'password', '', '', 0, 'password', '_sys_form_login_input_caption_system_password', '_sys_form_account_input_password', '', 1, 0, 0, '', '', '', 'Preg', 'a:1:{s:4:"preg";s:38:"~^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d).{8,}~";}', '_sys_form_account_input_password_error', '', '', 0, 0),
 ('sys_account', 'system', 'password_confirm', '', '', 0, 'password', '_sys_form_login_input_caption_system_password_confirm', '_sys_form_account_input_password_confirm', '', 1, 0, 0, '', '', '', 'PasswordConfirm', '', '_sys_form_account_input_password_confirm_error', '', '', 0, 0),
 ('sys_account', 'system', 'do_submit', '_sys_form_account_input_submit', '', 0, 'submit', '_sys_form_login_input_caption_system_do_submit', '', '', 0, 0, 0, '', '', '', '', '', '', '', '', 0, 0),
@@ -3394,16 +3396,17 @@ INSERT INTO `sys_form_display_inputs` (`display_name`, `input_name`, `visible_fo
 ('sys_login_step2', 'relocate', 2147483647, 1, 3),
 
 ('sys_login_step3', 'code', 2147483647, 1, 1),
-('sys_login_step3', 'back', 2147483647, 1, 2),
-('sys_login_step3', 'do_checkcode', 2147483647, 1, 3),
+('sys_login_step3', 'do_checkcode', 2147483647, 1, 2),
+('sys_login_step3', 'back', 2147483647, 1, 3),
 ('sys_login_step3', 'relocate', 2147483647, 1, 4),
 
 ('sys_account_create', 'name', 2147483647, 1, 1),
 ('sys_account_create', 'email', 2147483647, 1, 2),
-('sys_account_create', 'password', 2147483647, 1, 3),
-('sys_account_create', 'receive_news', 2147483647, 1, 4),
-('sys_account_create', 'do_submit', 2147483647, 1, 5),
-('sys_account_create', 'agreement', 2147483647, 1, 6),
+('sys_account_create', 'phone', 2147483647, 0, 3),
+('sys_account_create', 'password', 2147483647, 1, 4),
+('sys_account_create', 'receive_news', 2147483647, 1, 5),
+('sys_account_create', 'do_submit', 2147483647, 1, 6),
+('sys_account_create', 'agreement', 2147483647, 1, 7),
 
 ('sys_account_settings_email', 'email', 2147483647, 1, 1),
 ('sys_account_settings_email', 'password_current', 2147483647, 1, 2),

+ 7 - 4
member.php

@@ -48,16 +48,19 @@ if (isset($_POST['ID'])) { // login form is submitted
 
     } 
     elseif ($bLoginSuccess) {
-        if (getParam('sys_account_activation_2fa_enable') == 'on' && getParam('sys_twilio_gate_sid') != '' && getParam('sys_twilio_gate_token') != '' && getParam('sys_twilio_gate_from_number') != ''){
+        $sId = trim($oForm->getCleanValue('ID'));
+        $oAccount = BxDolAccount::getInstance($sId);
+        $aAccountInfo = $oAccount->getInfo();
+        if (
+            (getParam('sys_account_activation_2fa_enable') == 'on' && getParam('sys_twilio_gate_sid') != '' && getParam('sys_twilio_gate_token') != '' && getParam('sys_twilio_gate_from_number') != '') 
+            && (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));
             header('Location: ' . BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=login-step2'));
         }
         else{
-    	    $sId = trim($oForm->getCleanValue('ID'));
-
-            $oAccount = BxDolAccount::getInstance($sId);
+    	   
             $aAccount = bx_login($oAccount->id(), ($oForm->getCleanValue('rememberMe') ? true : false));
 
             $sUrlRelocate = $oForm->getCleanValue('relocate');

+ 4 - 2
modules/boonex/english/data/langs/system/en.xml

@@ -1390,6 +1390,7 @@
 	<string name="_adm_stg_cpt_option_sys_account_confirmation_type"><![CDATA[Account is confirmed when]]></string>
 	<string name="_adm_stg_cpt_option_sys_account_hide_unconfirmed_accounts"><![CDATA[Hide profiles which have unconfirmed account]]></string>
 	<string name="_adm_stg_cpt_option_sys_account_2fa_enable"><![CDATA[Enable 2 Factor Authentication]]></string>
+  <string name="_adm_stg_cpt_option_sys_account_2fa_lifetime"><![CDATA[2FA code lifetime, in seconds (0 - send code upon each login)]]></string>
 	<string name="_adm_stg_cpt_option_sys_account_autoapproval"><![CDATA[Automatic account activation after creation]]></string>
 	<string name="_adm_stg_cpt_option_sys_account_auto_profile_creation"><![CDATA[Automatic profile creation from account name]]></string>
 	<string name="_adm_stg_cpt_option_sys_account_online_time"><![CDATA[Online status timeframe (minutes)]]></string>
@@ -2163,6 +2164,7 @@ If it is not enabled then please consider implement this optimization, since it
 	<string name="_sys_form_account_input_email_error"><![CDATA[Email is not valid]]></string>
 	<string name="_sys_form_account_input_email_uniq_error"><![CDATA[This email address is already registered. Please, use <a href="{0}">Forgot password</a> to restore access to your account.]]></string>
 	<string name="_sys_form_account_input_email_uniq_error_loggedin"><![CDATA[This email is already used by someone.]]></string>
+  <string name="_sys_form_account_input_phone_uniq_error_loggedin"><![CDATA[This phone number is already used by someone.]]></string>
 	<string name="_sys_form_account_input_name"><![CDATA[Account name]]></string>
 	<string name="_sys_form_account_input_name_error"><![CDATA[This is a required field.]]></string>
 	<string name="_sys_form_account_input_password"><![CDATA[Create a password]]></string>
@@ -2272,7 +2274,7 @@ If it is not enabled then please consider implement this optimization, since it
 	<string name="_sys_form_login_input_caption_system_captcha"><![CDATA[Captcha]]></string>
 	<string name="_sys_form_login_input_caption_system_checkcode"><![CDATA[Submit]]></string>
 	<string name="_sys_form_login_input_caption_system_code"><![CDATA[Code from SMS]]></string>
-	<string name="_sys_form_login_input_caption_system_back"><![CDATA[<a href="javascript:history.back()">Send new code</a>]]></string>
+	<string name="_sys_form_login_input_caption_system_back"><![CDATA[Resend SMS code]]></string>
 	<string name="_sys_form_login_input_caption_system_delete_confirm"><![CDATA[Confirm Delete]]></string>
 	<string name="_sys_form_login_input_caption_system_delete_content"><![CDATA[Delete with Content]]></string>
 	<string name="_sys_form_login_input_caption_system_do_submit"><![CDATA[Sign up]]></string>
@@ -2292,7 +2294,7 @@ If it is not enabled then please consider implement this optimization, since it
 	<string name="_sys_form_login_input_caption_system_submit"><![CDATA[Submit]]></string>
 	<string name="_sys_form_login_input_caption_system_submit_text"><![CDATA[Submit Text]]></string>
 	<string name="_sys_form_login_input_code"><![CDATA[Code from SMS]]></string>
-	<string name="_sys_form_login_input_back"><![CDATA[<a href="javascript:history.back()">Send new code</a>]]></string>
+	<string name="_sys_form_login_input_back"><![CDATA[You didn't receive an SMS? <a href="/page/login-step2">Send SMS again</a>.]]></string>
 	<string name="_sys_form_login_input_checkcode"><![CDATA[Submit]]></string>
 	<string name="_sys_form_login_input_email"><![CDATA[Email]]></string>
 	<string name="_sys_form_login_input_password"><![CDATA[Password]]></string>

+ 4 - 2
modules/boonex/russian/data/langs/system/ru.xml

@@ -1373,6 +1373,7 @@
 	<string name="_adm_stg_cpt_option_sys_account_confirmation_type"><![CDATA[Аккаунт подтвержден когда]]></string>
     <string name="_adm_stg_cpt_option_sys_account_hide_unconfirmed_accounts"><![CDATA[Скрывать профили у неподтвержденных аккаунтов]]></string>
 	<string name="_adm_stg_cpt_option_sys_account_2fa_enable"><![CDATA[Включить двухфакторную аутентификацию]]></string>
+  <string name="_adm_stg_cpt_option_sys_account_2fa_lifetime"><![CDATA[Срок жизни 2FA кода, в секундах (0 - отправлять код при каждой авторизации)]]></string>
     <string name="_adm_stg_cpt_option_sys_account_autoapproval"><![CDATA[Автоматическая активация аккаунта после создания]]></string>
     <string name="_adm_stg_cpt_option_sys_account_auto_profile_creation"><![CDATA[Автоматическое создание профайла из аккаунта]]></string>
 	<string name="_adm_stg_cpt_option_sys_account_online_time"><![CDATA[Временные рамки статуса "онлайн" (минуты)]]></string>
@@ -2147,6 +2148,7 @@
 	<string name="_sys_form_account_input_email_error"><![CDATA[Введите правильный адрес электронной почты]]></string>
 	<string name="_sys_form_account_input_email_uniq_error"><![CDATA[Этот эл. адрес уже зарегистрирован. Пожалуйста, воспользуйтесь ссылкой <a href="{0}">Забыли пароль?</a>, чтобы восстановить доступ к своему аккаунту.]]></string>
 	<string name="_sys_form_account_input_email_uniq_error_loggedin"><![CDATA[Этот эл. адрес уже кем-то используется.]]></string>
+  <string name="_sys_form_account_input_phone_uniq_error_loggedin"><![CDATA[Этот номер телефона уже кем-то используется.]]></string>
 	<string name="_sys_form_account_input_name"><![CDATA[Имя пользователя]]></string>
 	<string name="_sys_form_account_input_name_error"><![CDATA[Это обязательное поле.]]></string>
 	<string name="_sys_form_account_input_password"><![CDATA[Создать пароль]]></string>
@@ -2254,7 +2256,7 @@
 	<string name="_sys_form_login_input_caption_system_captcha"><![CDATA[Капча]]></string>
 	<string name="_sys_form_login_input_caption_system_checkcode"><![CDATA[Выполнить]]></string>
 	<string name="_sys_form_login_input_caption_system_code"><![CDATA[Код из SMS]]></string>
-	<string name="_sys_form_login_input_caption_system_back"><![CDATA[<a href="javascript:history.back()">Отправить новый код</a>]]></string>
+	<string name="_sys_form_login_input_caption_system_back"><![CDATA[Отправить SMS ещё раз]]></string>
 	<string name="_sys_form_login_input_caption_system_delete_confirm"><![CDATA[Подтвердить удаление]]></string>
 	<string name="_sys_form_login_input_caption_system_delete_content"><![CDATA[Удалить с контентом]]></string>
 	<string name="_sys_form_login_input_caption_system_do_submit"><![CDATA[Присоединиться]]></string>
@@ -2275,7 +2277,7 @@
 	<string name="_sys_form_login_input_caption_system_submit_text"><![CDATA[Текст отправки]]></string>
 	<string name="_sys_form_login_input_checkcode"><![CDATA[Выполнить]]></string>
 	<string name="_sys_form_login_input_code"><![CDATA[Код из SMS]]></string>
-	<string name="_sys_form_login_input_back"><![CDATA[<a href="javascript:history.back()">Отправить новый код</a>]]></string>
+	<string name="_sys_form_login_input_back"><![CDATA[Вы не получили SMS? <a href="javascript:history.back()">Отправить SMS ещё раз</a>]]></string>
 	<string name="_sys_form_login_input_email"><![CDATA[Email]]></string>
 	<string name="_sys_form_login_input_password"><![CDATA[Пароль]]></string>
 	<string name="_sys_form_login_input_phone"><![CDATA[Телефон]]></string>

+ 13 - 0
template/scripts/BxBaseFormAccount.php

@@ -38,6 +38,19 @@ class BxFormAccountCheckerHelper extends BxDolFormCheckerHelper
 		
 		return $aInfo['password'] == $sPassCheck;
     }
+    
+    /**
+     * Check if phone is exists.
+     */
+    function checkPhoneExist ($s)
+    {
+        $s = trim($s);
+        if(!preg_match("/^\+[0-9\s]*$/", $s)) {
+            return _t('_sys_form_forgot_password_phone_error_format');
+        }
+
+        return BxDolAccountQuery::getInstance()->getIdByPhone($s) ? _t('_sys_form_account_input_phone_uniq_error_loggedin') : true;
+    }
 
     /**
      * Check if email is uniq.