diff options
author | Jonas Franz <info@jonasfranz.software> | 2019-04-17 10:18:16 +0200 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2019-04-17 16:18:16 +0800 |
commit | 7a4c29c739fa9b08f901220ebcb2948daf491692 (patch) | |
tree | 73e44404a6c13061b832624582e230eedb801c3c /routers/user | |
parent | 34548369e1d78eb1141aecd4ab02acf59f2949ae (diff) | |
download | gitea-7a4c29c739fa9b08f901220ebcb2948daf491692.tar.gz gitea-7a4c29c739fa9b08f901220ebcb2948daf491692.zip |
OAuth2 Grant UI (#6625)
* Add oauth2 grants ui
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Add delete functionality
Add translations
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Fix unit tests
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Fix unit tests
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Refactor DeleteOAuth2Grant
Use results.Close()
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Refactor DeleteOAuth2Grant (again)
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Check if user ID is zero
Signed-off-by: Jonas Franz <info@jonasfranz.software>
* Check if grant ID is zero
Signed-off-by: Jonas Franz <info@jonasfranz.software>
Diffstat (limited to 'routers/user')
-rw-r--r-- | routers/user/setting/applications.go | 5 | ||||
-rw-r--r-- | routers/user/setting/oauth2.go | 19 |
2 files changed, 24 insertions, 0 deletions
diff --git a/routers/user/setting/applications.go b/routers/user/setting/applications.go index bc8633f72d..90e34d9e1a 100644 --- a/routers/user/setting/applications.go +++ b/routers/user/setting/applications.go @@ -81,5 +81,10 @@ func loadApplicationsData(ctx *context.Context) { ctx.ServerError("GetOAuth2ApplicationsByUserID", err) return } + ctx.Data["Grants"], err = models.GetOAuth2GrantsByUserID(ctx.User.ID) + if err != nil { + ctx.ServerError("GetOAuth2GrantsByUserID", err) + return + } } } diff --git a/routers/user/setting/oauth2.go b/routers/user/setting/oauth2.go index 1068b5db49..265e32642b 100644 --- a/routers/user/setting/oauth2.go +++ b/routers/user/setting/oauth2.go @@ -5,6 +5,8 @@ package setting import ( + "fmt" + "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/auth" "code.gitea.io/gitea/modules/base" @@ -138,3 +140,20 @@ func DeleteOAuth2Application(ctx *context.Context) { "redirect": setting.AppSubURL + "/user/settings/applications", }) } + +// RevokeOAuth2Grant revokes the grant with the given id +func RevokeOAuth2Grant(ctx *context.Context) { + if ctx.User.ID == 0 || ctx.QueryInt64("id") == 0 { + ctx.ServerError("RevokeOAuth2Grant", fmt.Errorf("user id or grant id is zero")) + return + } + if err := models.RevokeOAuth2Grant(ctx.QueryInt64("id"), ctx.User.ID); err != nil { + ctx.ServerError("RevokeOAuth2Grant", err) + return + } + + ctx.Flash.Success(ctx.Tr("settings.revoke_oauth2_grant_success")) + ctx.JSON(200, map[string]interface{}{ + "redirect": setting.AppSubURL + "/user/settings/applications", + }) +} |