BxBaseFormLogin.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup TridentCore Trident Core
  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. $sRelocate = bx_process_input(bx_get('relocate'));
  20. if (!$sRelocate && isset($_SERVER['HTTP_REFERER']) && 0 === mb_stripos($_SERVER['HTTP_REFERER'], BX_DOL_URL_ROOT)) {
  21. $sRelocate = $_SERVER['HTTP_REFERER'];
  22. foreach ($aNoRelocatePages as $s) {
  23. if (false !== mb_stripos($_SERVER['HTTP_REFERER'], $s)) {
  24. $sRelocate = BX_DOL_URL_ROOT . 'member.php';
  25. break;
  26. }
  27. }
  28. }
  29. $this->aInputs['relocate']['value'] = $sRelocate ? $sRelocate : BX_DOL_URL_ROOT . 'member.php';
  30. }
  31. function isValid ()
  32. {
  33. if (!parent::isValid ())
  34. return false;
  35. $sId = trim($this->getCleanValue('ID'));
  36. $sPassword = $this->getCleanValue('Password');
  37. $sErrorString = bx_check_password($sId, $sPassword, $this->getRole());
  38. $this->_setCustomError ($sErrorString);
  39. return $sErrorString ? false : true;
  40. }
  41. protected function genCustomInputSubmitText ($aInput)
  42. {
  43. return '<div class="bx-def-font-align-center">
  44. <a href="' . BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=forgot-password') . '">' . _t("_sys_txt_forgot_pasword") . '</a>
  45. </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. /** @} */