BxBaseServiceLogin.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 = array())
  23. {
  24. if(empty($aAuthTypes) || !is_array($aAuthTypes))
  25. $aAuthTypes = BxDolDb::getInstance()->fromCache('sys_objects_auths', 'getAll', 'SELECT * FROM `sys_objects_auths`');
  26. $bCompact = getParam('site_login_social_compact') == 'on';
  27. $aTmplButtons = array();
  28. foreach($aAuthTypes as $iKey => $aItems) {
  29. $sTitle = _t($aItems['Title']);
  30. $aTmplButtons[] = array(
  31. 'class' => $bCompact ? 'sys-auth-compact bx-def-margin-sec-left-auto' : '',
  32. 'href' => !empty($aItems['Link']) ? BX_DOL_URL_ROOT . $aItems['Link'] : 'javascript:void(0)',
  33. 'title_alt' => bx_html_attribute($sTitle),
  34. 'bx_if:show_onclick' => array(
  35. 'condition' => !empty($aItems['OnClick']),
  36. 'content' => array(
  37. 'onclick' => 'javascript:' . $aItems['OnClick']
  38. )
  39. ),
  40. 'bx_if:show_icon' => array(
  41. 'condition' => !empty($aItems['Icon']),
  42. 'content' => array(
  43. 'icon' => $aItems['Icon']
  44. )
  45. ),
  46. 'bx_if:show_title' => array(
  47. 'condition' => !$bCompact || empty($aItems['Icon']),
  48. 'content' => array(
  49. 'title' => $sTitle
  50. )
  51. )
  52. );
  53. }
  54. BxDolTemplate::getInstance()->addCss(array('auth.css'));
  55. return BxDolTemplate::getInstance()->parseHtmlByName('auth.html', array(
  56. 'bx_repeat:buttons' => $aTmplButtons
  57. ));
  58. }
  59. public function serviceLoginFormOnly ($sParams = '', $sForceRelocate = '')
  60. {
  61. if(strpos($sParams, 'no_join_text') === false)
  62. $sParams = ($sParams != '' ? ' ' : '') . 'no_join_text';
  63. return $this->serviceLoginForm($sParams, $sForceRelocate);
  64. }
  65. public function serviceLoginForm ($sParams = '', $sForceRelocate = '')
  66. {
  67. if(isLogged())
  68. return false;
  69. $oForm = BxDolForm::getObjectInstance('sys_login', 'sys_login');
  70. $sCustomHtmlBefore = '';
  71. $sCustomHtmlAfter = '';
  72. bx_alert('profile', 'show_login_form', 0, 0, array('oForm' => $oForm, 'sParams' => &$sParams, 'sCustomHtmlBefore' => &$sCustomHtmlBefore, 'sCustomHtmlAfter' => &$sCustomHtmlAfter, 'aAuthTypes' => &$aAuthTypes));
  73. if ($sForceRelocate && 0 === mb_stripos($sForceRelocate, BX_DOL_URL_ROOT))
  74. $oForm->aInputs['relocate']['value'] = $sForceRelocate;
  75. elseif ('homepage' == $sForceRelocate)
  76. $oForm->aInputs['relocate']['value'] = BX_DOL_URL_ROOT;
  77. $sFormCode = $oForm->getCode();
  78. $sJoinText = '';
  79. if (strpos($sParams, 'no_join_text') === false) {
  80. $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>';
  81. }
  82. BxDolTemplate::getInstance()->addJs(array('jquery.form.min.js'));
  83. $sAuth = $this->serviceMemberAuthCode();
  84. return $sCustomHtmlBefore . $sAuth . $sFormCode . $sCustomHtmlAfter . $sJoinText;
  85. }
  86. }
  87. /** @} */