BxBaseFormLogin.php 3.8 KB

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