github.html 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <form action="/_api/admin/security/passport-github" method="post" class="form-horizontal passportStrategy" id="githubSetting" role="form"
  2. {% if isRestartingServerNeeded %}style="opacity: 0.4;"{% endif %}>
  3. <legend class="alert-anchor">{{ t("security_setting.OAuth.GitHub.name") }} {{ t("security_setting.configuration") }}</legend>
  4. {% set nameForIsGitHubEnabled = "settingForm[security:passport-github:isEnabled]" %}
  5. {% set isGitHubEnabled = settingForm['security:passport-github:isEnabled'] %}
  6. {% set siteUrl = settingForm['app:siteUrl'] || '[INVALID]' %}
  7. {% set callbackUrl = siteUrl + '/passport/github/callback' %}
  8. <div class="form-group">
  9. <label for="{{nameForIsGitHubEnabled}}" class="col-xs-3 control-label">{{ t("security_setting.OAuth.GitHub.name") }}</label>
  10. <div class="col-xs-6">
  11. <div class="btn-group btn-toggle" data-toggle="buttons">
  12. <label class="btn btn-default btn-rounded btn-outline {% if isGitHubEnabled %}active{% endif %}" data-active-class="primary">
  13. <input name="{{nameForIsGitHubEnabled}}" value="true" type="radio"
  14. {% if true === isGitHubEnabled %}checked{% endif %}> ON
  15. </label>
  16. <label class="btn btn-default btn-rounded btn-outline {% if !isGitHubEnabled %}active{% endif %}" data-active-class="default">
  17. <input name="{{nameForIsGitHubEnabled}}" value="false" type="radio"
  18. {% if !isGitHubEnabled %}checked{% endif %}> OFF
  19. </label>
  20. </div>
  21. </div>
  22. </div>
  23. <fieldset id="passport-github-hide-when-disabled" {%if !isGitHubEnabled %}style="display: none;"{% endif %}>
  24. <div class="form-group">
  25. <label for="settingForm[security:passport-github:clientId]" class="col-xs-3 control-label">{{ t("security_setting.clientID") }}</label>
  26. <div class="col-xs-6">
  27. <input class="form-control" type="text" name="settingForm[security:passport-github:clientId]" value="{{ settingForm['security:passport-github:clientId'] || '' }}">
  28. <p class="help-block">
  29. <small>
  30. {{ t("security_setting.Use env var if empty", "OAUTH_GITHUB_CLIENT_SECRET") }}
  31. </small>
  32. </p>
  33. </div>
  34. </div>
  35. <div class="form-group">
  36. <label for="settingForm[security:passport-github:clientSecret]" class="col-xs-3 control-label">{{ t("security_setting.client_secret") }}</label>
  37. <div class="col-xs-6">
  38. <input class="form-control" type="text" name="settingForm[security:passport-github:clientSecret]" value="{{ settingForm['security:passport-github:clientSecret'] || '' }}">
  39. <p class="help-block">
  40. <small>
  41. {{ t("security_setting.Use env var if empty", "OAUTH_GITHUB_CLIENT_SECRET") }}
  42. </small>
  43. </p>
  44. </div>
  45. </div>
  46. <div class="form-group">
  47. <label class="col-xs-3 control-label">{{ t("security_setting.callback_URL") }}</label>
  48. <div class="col-xs-6">
  49. <input class="form-control" type="text" value="{{ callbackUrl }}" readonly>
  50. <p class="help-block small">{{ t("security_setting.desc_of_callback_URL", 'OAuth') }}</p>
  51. {% if !settingForm['app:siteUrl'] %}
  52. <div class="alert alert-danger">
  53. <i class="icon-exclamation"></i> {{ t("security_setting.alert_siteUrl_is_not_set", '<a href="/admin/app">' + t('App settings') + '<i class="icon-login"></i></a>') }}
  54. </div>
  55. {% endif %}
  56. </div>
  57. </div>
  58. <div class="form-group">
  59. <div class="col-xs-6 col-xs-offset-3">
  60. <div class="checkbox checkbox-info">
  61. <input type="checkbox" id="bindByUserName-GitHub" name="settingForm[security:passport-github:isSameUsernameTreatedAsIdenticalUser]" value="1"
  62. {% if settingForm['security:passport-github:isSameUsernameTreatedAsIdenticalUser'] %}checked{% endif %} />
  63. <label for="bindByUserName-GitHub">
  64. {{ t("security_setting.Treat username matching as identical", "username") }}
  65. </label>
  66. <p class="help-block">
  67. <small>
  68. {{ t("security_setting.Treat username matching as identical_warn", "username") }}
  69. </small>
  70. </p>
  71. </div>
  72. </div>
  73. </div>
  74. </fieldset>
  75. <div class="form-group" id="btn-update">
  76. <div class="col-xs-offset-3 col-xs-6">
  77. <input type="hidden" name="_csrf" value="{{ csrf() }}">
  78. <button type="submit" class="btn btn-primary">{{ t('Update') }}</button>
  79. </div>
  80. </div>
  81. </form>
  82. {# Help Section #}
  83. <hr>
  84. <div style="min-height: 300px;">
  85. <h4>
  86. <i class="icon-question" aria-hidden="true"></i>
  87. <a href="#collapseHelpForGithubOauth" data-toggle="collapse">{{ t("security_setting.OAuth.how_to.github") }}</a>
  88. </h4>
  89. <ol id="collapseHelpForGithubOauth" class="collapse">
  90. <li>{{ t("security_setting.OAuth.GitHub.register_1", "https://github.com/settings/developers", "GitHub Developer Settings") }}</li>
  91. <li>{{ t("security_setting.OAuth.GitHub.register_2", callbackUrl) }}</li>
  92. <li>{{ t("security_setting.OAuth.GitHub.register_3") }}</li>
  93. </ol>
  94. </div>
  95. <script>
  96. $('input[name="settingForm[security:passport-github:isEnabled]"]').change(function() {
  97. const isEnabled = ($(this).val() === "true");
  98. if (isEnabled) {
  99. $('#passport-github-hide-when-disabled').show(400);
  100. }
  101. else {
  102. $('#passport-github-hide-when-disabled').hide(400);
  103. }
  104. });
  105. </script>