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