summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2020-04-30 19:50:47 +0200
committerGitHub <noreply@github.com>2020-04-30 18:50:47 +0100
commitab69b9b1a60a83cf2b5d6c021da0cb35540df10f (patch)
tree446be5bfe00d6e1da91f848b3ca9710fb1786645 /routers
parentc25969e694245ec72c609d3be676b64361e05335 (diff)
downloadgitea-ab69b9b1a60a83cf2b5d6c021da0cb35540df10f.tar.gz
gitea-ab69b9b1a60a83cf2b5d6c021da0cb35540df10f.zip
Refactor UpdateOAuth2Application (#11034)
Following on from #11008 refactor UpdateOAuth2Application
Diffstat (limited to 'routers')
-rw-r--r--routers/api/v1/user/app.go10
-rw-r--r--routers/user/setting/oauth2.go8
2 files changed, 4 insertions, 14 deletions
diff --git a/routers/api/v1/user/app.go b/routers/api/v1/user/app.go
index f29572ef62..f426721c82 100644
--- a/routers/api/v1/user/app.go
+++ b/routers/api/v1/user/app.go
@@ -301,18 +301,13 @@ func UpdateOauth2Application(ctx *context.APIContext, data api.CreateOAuth2Appli
// "$ref": "#/responses/OAuth2Application"
appID := ctx.ParamsInt64(":id")
- err := models.UpdateOAuth2Application(models.UpdateOAuth2ApplicationOptions{
+ app, err := models.UpdateOAuth2Application(models.UpdateOAuth2ApplicationOptions{
Name: data.Name,
UserID: ctx.User.ID,
ID: appID,
RedirectURIs: data.RedirectURIs,
})
if err != nil {
- ctx.Error(http.StatusBadRequest, "", "error updating oauth2 application")
- return
- }
- app, err := models.GetOAuth2ApplicationByID(appID)
- if err != nil {
if models.IsErrOauthClientIDInvalid(err) || models.IsErrOAuthApplicationNotFound(err) {
ctx.NotFound()
} else {
@@ -320,12 +315,11 @@ func UpdateOauth2Application(ctx *context.APIContext, data api.CreateOAuth2Appli
}
return
}
- secret, err := app.GenerateClientSecret()
+ app.ClientSecret, err = app.GenerateClientSecret()
if err != nil {
ctx.Error(http.StatusBadRequest, "", "error updating application secret")
return
}
- app.ClientSecret = secret
ctx.JSON(http.StatusOK, convert.ToOAuth2Application(app))
}
diff --git a/routers/user/setting/oauth2.go b/routers/user/setting/oauth2.go
index 265e32642b..f42c1123e1 100644
--- a/routers/user/setting/oauth2.go
+++ b/routers/user/setting/oauth2.go
@@ -62,7 +62,8 @@ func OAuthApplicationsEdit(ctx *context.Context, form auth.EditOAuth2Application
return
}
// TODO validate redirect URI
- if err := models.UpdateOAuth2Application(models.UpdateOAuth2ApplicationOptions{
+ var err error
+ if ctx.Data["App"], err = models.UpdateOAuth2Application(models.UpdateOAuth2ApplicationOptions{
ID: ctx.ParamsInt64("id"),
Name: form.Name,
RedirectURIs: []string{form.RedirectURI},
@@ -71,11 +72,6 @@ func OAuthApplicationsEdit(ctx *context.Context, form auth.EditOAuth2Application
ctx.ServerError("UpdateOAuth2Application", err)
return
}
- var err error
- if ctx.Data["App"], err = models.GetOAuth2ApplicationByID(ctx.ParamsInt64("id")); err != nil {
- ctx.ServerError("GetOAuth2ApplicationByID", err)
- return
- }
ctx.Flash.Success(ctx.Tr("settings.update_oauth2_application_success"))
ctx.HTML(200, tplSettingsOAuthApplications)
}