| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <?php defined('BX_DOL') or die('hack attempt');
- /**
- * Copyright (c) UNA, Inc - https://una.io
- * MIT License - https://opensource.org/licenses/MIT
- *
- * @defgroup UnaBaseView UNA Base Representation Classes
- * @{
- */
- class BxFormLoginCheckerHelper extends BxDolFormCheckerHelper
- {
- /**
- * Check if key exists or wrong format
- */
- function checkPhoneExist($s)
- {
- $s = trim($s);
- if(!preg_match("/^\+[0-9\s]*$/", $s)) {
- return _t('_sys_form_login_input_phone_error_format');
- }
- $oSession = BxDolSession::getInstance();
- $oAccount = BxDolAccount::getInstance($oSession->getValue(BX_ACCOUNT_SESSION_KEY_FOR_2FA_LOGIN_ACCOUNT_ID));
- if ($oAccount) { // user is logged in
- $aAccountInfo = $oAccount->getInfo();
- if ($s == $aAccountInfo['phone']) // don't check phone for uniq, if it wasn't changed
- return true;
- }
-
- return BxDolAccountQuery::getInstance()->getIdByPhone($s) ? _t('_sys_form_login_input_phone_error_not_unique') : true;
- }
- function checkCodeExist($s)
- {
- $s = trim($s);
- if($s == '') {
- return _t('_sys_form_login_input_code_error_empty');
- }
-
- $oSession = BxDolSession::getInstance();
- return $oSession->getValue(BX_ACCOUNT_SESSION_KEY_FOR_PHONE_ACTIVATEION_CODE) != $s ? _t('_sys_form_login_input_code_error_invalid', BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=login-step2')) : true;
- }
- }
- /**
- * Login Form.
- */
- class BxBaseFormLogin extends BxTemplFormView
- {
- protected $_iRole = BX_DOL_ROLE_MEMBER;
- public function __construct($aInfo, $oTemplate)
- {
- parent::__construct($aInfo, $oTemplate);
- $aNoRelocatePages = array('forgot-password', 'login', 'create-account', 'logout');
- if (isset($this->aInputs['ID']))
- $this->aInputs['ID']['skip_domain_check'] = true;
- $sRelocate = bx_process_input(bx_get('relocate'));
- if (!$sRelocate && isset($_SERVER['HTTP_REFERER']) && 0 === mb_stripos($_SERVER['HTTP_REFERER'], BX_DOL_URL_ROOT)) {
- $sRelocate = $_SERVER['HTTP_REFERER'];
-
- foreach ($aNoRelocatePages as $s) {
- if (false !== mb_stripos($_SERVER['HTTP_REFERER'], $s)) {
- $sRelocate = BX_DOL_URL_ROOT . 'member.php';
- break;
- }
- }
- }
-
- $this->aInputs['relocate']['value'] = $sRelocate ? $sRelocate : BX_DOL_URL_ROOT . 'member.php';
- }
- function isValid ()
- {
- if (!parent::isValid())
- return false;
-
- $sId = trim($this->getCleanValue('ID'));
- $sPassword = $this->getCleanValue('Password');
- if ($sId != ''){
- $sErrorString = bx_check_password($sId, $sPassword, $this->getRole());
- $this->_setCustomError ($sErrorString);
- return $sErrorString ? false : true;
- }
- else {
- $this->_setCustomError (_t('_sys_txt_error_occured'));
- return false;
- }
- }
- protected function genCustomInputSubmitText ($aInput)
- {
- return '<div><a href="' . BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=forgot-password') . '">' . _t("_sys_txt_forgot_pasword") . '</a></div>';
- }
- public function getRole()
- {
- return $this->_iRole;
- }
- public function setRole ($iRole)
- {
- $this->_iRole = $iRole == BX_DOL_ROLE_ADMIN ? BX_DOL_ROLE_ADMIN : BX_DOL_ROLE_MEMBER;
- }
- public function getLoginError ()
- {
- return isset($this->aInputs['ID']['error']) ? $this->aInputs['ID']['error'] : '';
- }
- protected function _setCustomError ($s)
- {
- $this->aInputs['ID']['error'] = $s;
- }
- }
- /** @} */
|