BxBaseServiceLogin.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. * System service for login form functionality.
  11. */
  12. class BxBaseServiceLogin extends BxDol
  13. {
  14. public function __construct()
  15. {
  16. parent::__construct();
  17. }
  18. public function serviceTest ($n = 1)
  19. {
  20. return $n*2;
  21. }
  22. public function serviceMemberAuthCode($aAuthTypes)
  23. {
  24. $aTmplButtons = array();
  25. foreach($aAuthTypes as $iKey => $aItems) {
  26. $sTitle = _t($aItems['Title']);
  27. $aTmplButtons[] = array(
  28. 'href' => !empty($aItems['Link']) ? BX_DOL_URL_ROOT . $aItems['Link'] : 'javascript:void(0)',
  29. 'bx_if:show_onclick' => array(
  30. 'condition' => !empty($aItems['OnClick']),
  31. 'content' => array(
  32. 'onclick' => 'javascript:' . $aItems['OnClick']
  33. )
  34. ),
  35. 'bx_if:show_icon' => array(
  36. 'condition' => !empty($aItems['Icon']),
  37. 'content' => array(
  38. 'icon' => $aItems['Icon']
  39. )
  40. ),
  41. 'title' => !empty($sTitleKey) ? _t($sTitleKey, $sTitle) : $sTitle
  42. );
  43. }
  44. BxDolTemplate::getInstance()->addCss(array('auth.css'));
  45. return BxDolTemplate::getInstance()->parseHtmlByName('auth.html', array(
  46. 'bx_repeat:buttons' => $aTmplButtons
  47. ));
  48. }
  49. public function serviceLoginFormOnly ($sParams = '', $sForceRelocate = '')
  50. {
  51. if(strpos($sParams, 'no_join_text') === false)
  52. $sParams = ($sParams != '' ? ' ' : '') . 'no_join_text';
  53. return $this->serviceLoginForm($sParams, $sForceRelocate);
  54. }
  55. public function serviceLoginForm ($sParams = '', $sForceRelocate = '')
  56. {
  57. if (isLogged()) {
  58. return false;
  59. }
  60. // get all auth types
  61. $aAuthTypes = BxDolDb::getInstance()->fromCache('sys_objects_auths', 'getAll', 'SELECT * FROM `sys_objects_auths`');
  62. $oForm = BxDolForm::getObjectInstance('sys_login', 'sys_login');
  63. $sCustomHtmlBefore = '';
  64. $sCustomHtmlAfter = '';
  65. bx_alert('profile', 'show_login_form', 0, 0, array('oForm' => $oForm, 'sParams' => &$sParams, 'sCustomHtmlBefore' => &$sCustomHtmlBefore, 'sCustomHtmlAfter' => &$sCustomHtmlAfter, 'aAuthTypes' => &$aAuthTypes));
  66. if ($sForceRelocate && 0 === mb_stripos($sForceRelocate, BX_DOL_URL_ROOT))
  67. $oForm->aInputs['relocate']['value'] = $sForceRelocate;
  68. elseif ('homepage' == $sForceRelocate)
  69. $oForm->aInputs['relocate']['value'] = BX_DOL_URL_ROOT;
  70. $sFormCode = $oForm->getCode();
  71. $sJoinText = '';
  72. if (strpos($sParams, 'no_join_text') === false) {
  73. $sJoinText = '<hr class="bx-def-hr bx-def-margin-sec-topbottom" /><div>' . _t('_sys_txt_login_description', BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=create-account')) . '</div>';
  74. }
  75. BxDolTemplate::getInstance()->addJs(array('jquery.form.min.js'));
  76. $sAuth = $this->serviceMemberAuthCode($aAuthTypes);
  77. return $sCustomHtmlBefore . $sAuth . $sFormCode . $sCustomHtmlAfter . $sJoinText;
  78. }
  79. }
  80. /** @} */