BxBaseFormLogin.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. /**
  10. * Login Form.
  11. */
  12. class BxBaseFormLogin extends BxTemplFormView
  13. {
  14. protected $_iRole = BX_DOL_ROLE_MEMBER;
  15. public function __construct($aInfo, $oTemplate)
  16. {
  17. parent::__construct($aInfo, $oTemplate);
  18. $aNoRelocatePages = array('forgot-password', 'login', 'create-account', 'logout');
  19. if (isset($this->aInputs['ID']))
  20. $this->aInputs['ID']['skip_domain_check'] = true;
  21. $sRelocate = bx_process_input(bx_get('relocate'));
  22. if (!$sRelocate && isset($_SERVER['HTTP_REFERER']) && 0 === mb_stripos($_SERVER['HTTP_REFERER'], BX_DOL_URL_ROOT)) {
  23. $sRelocate = $_SERVER['HTTP_REFERER'];
  24. foreach ($aNoRelocatePages as $s) {
  25. if (false !== mb_stripos($_SERVER['HTTP_REFERER'], $s)) {
  26. $sRelocate = BX_DOL_URL_ROOT . 'member.php';
  27. break;
  28. }
  29. }
  30. }
  31. $this->aInputs['relocate']['value'] = $sRelocate ? $sRelocate : BX_DOL_URL_ROOT . 'member.php';
  32. }
  33. function isValid ()
  34. {
  35. if (!parent::isValid ())
  36. return false;
  37. $sId = trim($this->getCleanValue('ID'));
  38. $sPassword = $this->getCleanValue('Password');
  39. $sErrorString = bx_check_password($sId, $sPassword, $this->getRole());
  40. $this->_setCustomError ($sErrorString);
  41. return $sErrorString ? false : true;
  42. }
  43. protected function genCustomInputSubmitText ($aInput)
  44. {
  45. return '<div><a href="' . BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=forgot-password') . '">' . _t("_sys_txt_forgot_pasword") . '</a></div>';
  46. }
  47. public function getRole()
  48. {
  49. return $this->_iRole;
  50. }
  51. public function setRole ($iRole)
  52. {
  53. $this->_iRole = $iRole == BX_DOL_ROLE_ADMIN ? BX_DOL_ROLE_ADMIN : BX_DOL_ROLE_MEMBER;
  54. }
  55. public function getLoginError ()
  56. {
  57. return isset($this->aInputs['ID']['error']) ? $this->aInputs['ID']['error'] : '';
  58. }
  59. protected function _setCustomError ($s)
  60. {
  61. $this->aInputs['ID']['error'] = $s;
  62. }
  63. }
  64. /** @} */