BxOAuthFormAdd.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 OAuth2 OAuth2 server
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxOAuthFormAdd extends BxTemplFormView
  12. {
  13. public static $LENGTH_ID = 10;
  14. public static $LENGTH_SECRET = 32;
  15. protected $_sModule;
  16. protected $_oModule;
  17. function __construct($aCustomForm = array())
  18. {
  19. $this->_sModule = 'bx_oauth';
  20. $this->_oModule = BxDolModule::getInstance($this->_sModule);
  21. $aCustomForm = array_replace_recursive(array(
  22. 'form_attrs' => array(
  23. 'id' => 'bx-oauth-add',
  24. 'name' => 'bx-oauth-add',
  25. 'action' => BX_DOL_URL_ROOT . 'grid.php?' . bx_encode_url_params($_GET, array('ids', '_r')),
  26. 'method' => 'post',
  27. ),
  28. 'params' => array (
  29. 'db' => array(
  30. 'table' => 'bx_oauth_clients',
  31. 'key' => 'id',
  32. 'submit_name' => 'client_add',
  33. ),
  34. ),
  35. 'inputs' => array(
  36. 'title' => array(
  37. 'type' => 'text',
  38. 'name' => 'title',
  39. 'caption' => _t('_Title'),
  40. 'required' => true,
  41. 'checker' => array (
  42. 'func' => 'avail',
  43. 'error' => _t ('_sys_form_account_input_name_error'),
  44. ),
  45. 'db' => array (
  46. 'pass' => 'Xss',
  47. ),
  48. ),
  49. 'redirect_uri' => array(
  50. 'type' => 'text',
  51. 'name' => 'redirect_uri',
  52. 'caption' => _t('_bx_oauth_client_url'),
  53. 'required' => true,
  54. 'checker' => array (
  55. 'func' => 'preg',
  56. 'params' => array('/^https?:\/\//'),
  57. 'error' => _t ('_bx_oauth_form_valid_url'),
  58. ),
  59. 'db' => array (
  60. 'pass' => 'Xss',
  61. ),
  62. ),
  63. 'Submit' => array (
  64. 'type' => 'input_set',
  65. 0 => array (
  66. 'type' => 'submit',
  67. 'name' => 'client_add',
  68. 'value' => _t('_Submit'),
  69. ),
  70. 1 => array (
  71. 'type' => 'reset',
  72. 'name' => 'close',
  73. 'value' => _t('Close'),
  74. 'attrs' => array(
  75. 'onclick' => "$('.bx-popup-active').dolPopupHide()",
  76. 'class' => 'bx-def-margin-sec-left',
  77. ),
  78. ),
  79. ),
  80. ),
  81. ), $aCustomForm);
  82. parent::__construct ($aCustomForm);
  83. }
  84. function insert ($aValsToAdd = array(), $isIgnore = false)
  85. {
  86. $aValsToAdd['client_id'] = strtolower(genRndPwd(self::$LENGTH_ID, false));
  87. $aValsToAdd['client_secret'] = strtolower(genRndPwd(self::$LENGTH_SECRET, false));
  88. $aValsToAdd['scope'] = 'basic';
  89. $aValsToAdd['user_id'] = bx_get_logged_profile_id();
  90. return parent::insert($aValsToAdd, $isIgnore);
  91. }
  92. }
  93. /** @} */