code.gitea.io/gitea@v1.21.7/routers/web/user/setting/oauth2.go (about)

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