1
0

BxBaseFormLogin.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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_DOL_URL_ROOT . 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. $aNoRelocatePages = array('forgot-password', 'login', 'create-account', 'logout');
  49. if (isset($this->aInputs['ID']))
  50. $this->aInputs['ID']['skip_domain_check'] = true;
  51. if (isset($this->aInputs['relocate'])) {
  52. $sRelocate = bx_process_input(bx_get('relocate'));
  53. if (!$sRelocate && isset($_SERVER['HTTP_REFERER']) && 0 === mb_stripos($_SERVER['HTTP_REFERER'], BX_DOL_URL_ROOT)) {
  54. $sRelocate = $_SERVER['HTTP_REFERER'];
  55. foreach ($aNoRelocatePages as $s) {
  56. if (false !== mb_stripos($_SERVER['HTTP_REFERER'], $s)) {
  57. $sRelocate = BX_DOL_URL_ROOT . 'member.php';
  58. break;
  59. }
  60. }
  61. }
  62. $this->aInputs['relocate']['value'] = $sRelocate ? $sRelocate : BX_DOL_URL_ROOT . 'member.php';
  63. }
  64. }
  65. function isValid ()
  66. {
  67. if (!parent::isValid())
  68. return false;
  69. $sId = trim($this->getCleanValue('ID'));
  70. $sPassword = trim($this->getCleanValue('Password'));
  71. if ($sId != ''){
  72. $sErrorString = bx_check_password($sId, $sPassword, $this->getRole());
  73. $this->_setCustomError ($sErrorString);
  74. return $sErrorString ? false : true;
  75. }
  76. else {
  77. $this->_setCustomError (_t('_sys_txt_error_occured'));
  78. return false;
  79. }
  80. }
  81. protected function genCustomInputSubmitText ($aInput)
  82. {
  83. return '<div><a href="' . BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=forgot-password') . '">' . _t("_sys_txt_forgot_pasword") . '</a></div>';
  84. }
  85. public function getRole()
  86. {
  87. return $this->_iRole;
  88. }
  89. public function setRole ($iRole)
  90. {
  91. $this->_iRole = $iRole == BX_DOL_ROLE_ADMIN ? BX_DOL_ROLE_ADMIN : BX_DOL_ROLE_MEMBER;
  92. }
  93. public function getLoginError ()
  94. {
  95. return isset($this->aInputs['ID']['error']) ? $this->aInputs['ID']['error'] : '';
  96. }
  97. protected function _setCustomError ($s)
  98. {
  99. $this->aInputs['ID']['error'] = $s;
  100. }
  101. }
  102. /** @} */