BxBaseFormLogin.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. class BxFormLoginCheckerHelper extends BxDolFormCheckerHelper
  10. {
  11. /**
  12. * Check if key exists or wrong format
  13. */
  14. function checkPhoneExist($s)
  15. {
  16. $s = trim($s);
  17. if(!preg_match("/^\+[0-9\s]*$/", $s)) {
  18. return _t('_sys_form_login_input_phone_error_format');
  19. }
  20. $oSession = BxDolSession::getInstance();
  21. $oAccount = BxDolAccount::getInstance($oSession->getValue(BX_ACCOUNT_SESSION_KEY_FOR_2FA_LOGIN_ACCOUNT_ID));
  22. if ($oAccount) { // user is logged in
  23. $aAccountInfo = $oAccount->getInfo();
  24. if ($s == $aAccountInfo['phone']) // don't check phone for uniq, if it wasn't changed
  25. return true;
  26. }
  27. return BxDolAccountQuery::getInstance()->getIdByPhone($s) ? _t('_sys_form_login_input_phone_error_not_unique') : true;
  28. }
  29. function checkCodeExist($s)
  30. {
  31. $s = trim($s);
  32. if($s == '') {
  33. return _t('_sys_form_login_input_code_error_empty');
  34. }
  35. $oSession = BxDolSession::getInstance();
  36. return $oSession->getValue(BX_ACCOUNT_SESSION_KEY_FOR_PHONE_ACTIVATEION_CODE) != $s ? _t('_sys_form_login_input_code_error_invalid', bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=login-step2'))) : true;
  37. }
  38. }
  39. /**
  40. * Login Form.
  41. */
  42. class BxBaseFormLogin extends BxTemplFormView
  43. {
  44. protected $_iRole = BX_DOL_ROLE_MEMBER;
  45. public function __construct($aInfo, $oTemplate)
  46. {
  47. parent::__construct($aInfo, $oTemplate);
  48. $this->_aFieldsExcludeFromCheckForSpam = array("ID");
  49. $aNoRelocatePages = array('forgot-password', 'login', 'create-account', 'logout');
  50. if (isset($this->aInputs['ID']))
  51. $this->aInputs['ID']['skip_domain_check'] = true;
  52. if (isset($this->aInputs['relocate'])) {
  53. $sRelocate = bx_process_input(bx_get('relocate'));
  54. if (!$sRelocate && isset($_SERVER['HTTP_REFERER']) && 0 === mb_stripos($_SERVER['HTTP_REFERER'], BX_DOL_URL_ROOT)) {
  55. $sRelocate = $_SERVER['HTTP_REFERER'];
  56. foreach ($aNoRelocatePages as $s) {
  57. if (false !== mb_stripos($_SERVER['HTTP_REFERER'], $s)) {
  58. $sRelocate = BX_DOL_URL_ROOT . 'member.php';
  59. break;
  60. }
  61. }
  62. }
  63. $this->aInputs['relocate']['value'] = $sRelocate ? $sRelocate : BX_DOL_URL_ROOT . 'member.php';
  64. }
  65. }
  66. function isValid ()
  67. {
  68. if (!parent::isValid())
  69. return false;
  70. if (!isset($this->aInputs['ID']))
  71. return true;
  72. $sId = trim($this->getCleanValue('ID'));
  73. $sPassword = trim($this->getCleanValue('Password'));
  74. if ($sId != ''){
  75. $sErrorString = bx_check_password($sId, $sPassword, $this->getRole());
  76. $this->_setCustomError ($sErrorString);
  77. return $sErrorString ? false : true;
  78. }
  79. else {
  80. $this->_setCustomError (_t('_sys_txt_error_occured'));
  81. return false;
  82. }
  83. }
  84. protected function genCustomInputSubmitText ($aInput)
  85. {
  86. return '<div><a href="' . bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=forgot-password')) . '">' . _t("_sys_txt_forgot_pasword") . '</a></div>';
  87. }
  88. public function getRole()
  89. {
  90. return $this->_iRole;
  91. }
  92. public function setRole ($iRole)
  93. {
  94. $this->_iRole = $iRole == BX_DOL_ROLE_ADMIN ? BX_DOL_ROLE_ADMIN : BX_DOL_ROLE_MEMBER;
  95. }
  96. public function getRememberMe()
  97. {
  98. return isset($this->aInputs['rememberMe']) ? (bool)$this->getCleanValue('rememberMe') : bx_is_remember_me();
  99. }
  100. public function getLoginError ()
  101. {
  102. return isset($this->aInputs['ID']['error']) ? $this->aInputs['ID']['error'] : '';
  103. }
  104. protected function _setCustomError ($s)
  105. {
  106. $this->aInputs['ID']['error'] = $s;
  107. }
  108. }
  109. /** @} */