gitea源码

oauth2.go 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package setting
  4. import (
  5. "code.gitea.io/gitea/modules/setting"
  6. "code.gitea.io/gitea/modules/templates"
  7. "code.gitea.io/gitea/services/context"
  8. )
  9. const (
  10. tplSettingsOAuthApplicationEdit templates.TplName = "user/settings/applications_oauth2_edit"
  11. )
  12. func newOAuth2CommonHandlers(userID int64) *OAuth2CommonHandlers {
  13. return &OAuth2CommonHandlers{
  14. OwnerID: userID,
  15. BasePathList: setting.AppSubURL + "/user/settings/applications",
  16. BasePathEditPrefix: setting.AppSubURL + "/user/settings/applications/oauth2",
  17. TplAppEdit: tplSettingsOAuthApplicationEdit,
  18. }
  19. }
  20. // OAuthApplicationsPost response for adding a oauth2 application
  21. func OAuthApplicationsPost(ctx *context.Context) {
  22. ctx.Data["Title"] = ctx.Tr("settings")
  23. ctx.Data["PageIsSettingsApplications"] = true
  24. oa := newOAuth2CommonHandlers(ctx.Doer.ID)
  25. oa.AddApp(ctx)
  26. }
  27. // OAuthApplicationsEdit response for editing oauth2 application
  28. func OAuthApplicationsEdit(ctx *context.Context) {
  29. ctx.Data["Title"] = ctx.Tr("settings")
  30. ctx.Data["PageIsSettingsApplications"] = true
  31. oa := newOAuth2CommonHandlers(ctx.Doer.ID)
  32. oa.EditSave(ctx)
  33. }
  34. // OAuthApplicationsRegenerateSecret handles the post request for regenerating the secret
  35. func OAuthApplicationsRegenerateSecret(ctx *context.Context) {
  36. ctx.Data["Title"] = ctx.Tr("settings")
  37. ctx.Data["PageIsSettingsApplications"] = true
  38. oa := newOAuth2CommonHandlers(ctx.Doer.ID)
  39. oa.RegenerateSecret(ctx)
  40. }
  41. // OAuth2ApplicationShow displays the given application
  42. func OAuth2ApplicationShow(ctx *context.Context) {
  43. oa := newOAuth2CommonHandlers(ctx.Doer.ID)
  44. oa.EditShow(ctx)
  45. }
  46. // DeleteOAuth2Application deletes the given oauth2 application
  47. func DeleteOAuth2Application(ctx *context.Context) {
  48. oa := newOAuth2CommonHandlers(ctx.Doer.ID)
  49. oa.DeleteApp(ctx)
  50. }
  51. // RevokeOAuth2Grant revokes the grant with the given id
  52. func RevokeOAuth2Grant(ctx *context.Context) {
  53. oa := newOAuth2CommonHandlers(ctx.Doer.ID)
  54. oa.RevokeGrant(ctx)
  55. }