diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2022-01-02 21:12:35 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-02 21:12:35 +0800 |
commit | de8e3948a5e38f7eaf82d3c0cfd10e995bf68e92 (patch) | |
tree | bbcb011d264e0d614d49c734856b446360c5a4a3 /routers/api | |
parent | e61b390d545919244141b699b28e3fbc42adc66f (diff) | |
download | gitea-de8e3948a5e38f7eaf82d3c0cfd10e995bf68e92.tar.gz gitea-de8e3948a5e38f7eaf82d3c0cfd10e995bf68e92.zip |
Refactor auth package (#17962)
Diffstat (limited to 'routers/api')
-rw-r--r-- | routers/api/v1/admin/user.go | 16 | ||||
-rw-r--r-- | routers/api/v1/user/app.go | 18 |
2 files changed, 17 insertions, 17 deletions
diff --git a/routers/api/v1/admin/user.go b/routers/api/v1/admin/user.go index 5d2bbdea2f..e95ab33d77 100644 --- a/routers/api/v1/admin/user.go +++ b/routers/api/v1/admin/user.go @@ -13,8 +13,8 @@ import ( "code.gitea.io/gitea/models" asymkey_model "code.gitea.io/gitea/models/asymkey" + "code.gitea.io/gitea/models/auth" "code.gitea.io/gitea/models/db" - "code.gitea.io/gitea/models/login" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/convert" @@ -30,17 +30,17 @@ import ( user_service "code.gitea.io/gitea/services/user" ) -func parseLoginSource(ctx *context.APIContext, u *user_model.User, sourceID int64, loginName string) { +func parseAuthSource(ctx *context.APIContext, u *user_model.User, sourceID int64, loginName string) { if sourceID == 0 { return } - source, err := login.GetSourceByID(sourceID) + source, err := auth.GetSourceByID(sourceID) if err != nil { - if login.IsErrSourceNotExist(err) { + if auth.IsErrSourceNotExist(err) { ctx.Error(http.StatusUnprocessableEntity, "", err) } else { - ctx.Error(http.StatusInternalServerError, "login.GetSourceByID", err) + ctx.Error(http.StatusInternalServerError, "auth.GetSourceByID", err) } return } @@ -82,13 +82,13 @@ func CreateUser(ctx *context.APIContext) { Passwd: form.Password, MustChangePassword: true, IsActive: true, - LoginType: login.Plain, + LoginType: auth.Plain, } if form.MustChangePassword != nil { u.MustChangePassword = *form.MustChangePassword } - parseLoginSource(ctx, u, form.SourceID, form.LoginName) + parseAuthSource(ctx, u, form.SourceID, form.LoginName) if ctx.Written() { return } @@ -168,7 +168,7 @@ func EditUser(ctx *context.APIContext) { return } - parseLoginSource(ctx, u, form.SourceID, form.LoginName) + parseAuthSource(ctx, u, form.SourceID, form.LoginName) if ctx.Written() { return } diff --git a/routers/api/v1/user/app.go b/routers/api/v1/user/app.go index bf45bf4dd5..94cfab45bd 100644 --- a/routers/api/v1/user/app.go +++ b/routers/api/v1/user/app.go @@ -12,7 +12,7 @@ import ( "strconv" "code.gitea.io/gitea/models" - "code.gitea.io/gitea/models/login" + "code.gitea.io/gitea/models/auth" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/convert" api "code.gitea.io/gitea/modules/structs" @@ -213,7 +213,7 @@ func CreateOauth2Application(ctx *context.APIContext) { data := web.GetForm(ctx).(*api.CreateOAuth2ApplicationOptions) - app, err := login.CreateOAuth2Application(login.CreateOAuth2ApplicationOptions{ + app, err := auth.CreateOAuth2Application(auth.CreateOAuth2ApplicationOptions{ Name: data.Name, UserID: ctx.User.ID, RedirectURIs: data.RedirectURIs, @@ -252,7 +252,7 @@ func ListOauth2Applications(ctx *context.APIContext) { // "200": // "$ref": "#/responses/OAuth2ApplicationList" - apps, total, err := login.ListOAuth2Applications(ctx.User.ID, utils.GetListOptions(ctx)) + apps, total, err := auth.ListOAuth2Applications(ctx.User.ID, utils.GetListOptions(ctx)) if err != nil { ctx.Error(http.StatusInternalServerError, "ListOAuth2Applications", err) return @@ -288,8 +288,8 @@ func DeleteOauth2Application(ctx *context.APIContext) { // "404": // "$ref": "#/responses/notFound" appID := ctx.ParamsInt64(":id") - if err := login.DeleteOAuth2Application(appID, ctx.User.ID); err != nil { - if login.IsErrOAuthApplicationNotFound(err) { + if err := auth.DeleteOAuth2Application(appID, ctx.User.ID); err != nil { + if auth.IsErrOAuthApplicationNotFound(err) { ctx.NotFound() } else { ctx.Error(http.StatusInternalServerError, "DeleteOauth2ApplicationByID", err) @@ -320,9 +320,9 @@ func GetOauth2Application(ctx *context.APIContext) { // "404": // "$ref": "#/responses/notFound" appID := ctx.ParamsInt64(":id") - app, err := login.GetOAuth2ApplicationByID(appID) + app, err := auth.GetOAuth2ApplicationByID(appID) if err != nil { - if login.IsErrOauthClientIDInvalid(err) || login.IsErrOAuthApplicationNotFound(err) { + if auth.IsErrOauthClientIDInvalid(err) || auth.IsErrOAuthApplicationNotFound(err) { ctx.NotFound() } else { ctx.Error(http.StatusInternalServerError, "GetOauth2ApplicationByID", err) @@ -363,14 +363,14 @@ func UpdateOauth2Application(ctx *context.APIContext) { data := web.GetForm(ctx).(*api.CreateOAuth2ApplicationOptions) - app, err := login.UpdateOAuth2Application(login.UpdateOAuth2ApplicationOptions{ + app, err := auth.UpdateOAuth2Application(auth.UpdateOAuth2ApplicationOptions{ Name: data.Name, UserID: ctx.User.ID, ID: appID, RedirectURIs: data.RedirectURIs, }) if err != nil { - if login.IsErrOauthClientIDInvalid(err) || login.IsErrOAuthApplicationNotFound(err) { + if auth.IsErrOauthClientIDInvalid(err) || auth.IsErrOAuthApplicationNotFound(err) { ctx.NotFound() } else { ctx.Error(http.StatusInternalServerError, "UpdateOauth2ApplicationByID", err) |