summaryrefslogtreecommitdiffstats
path: root/routers/web/auth
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2022-03-22 23:22:54 +0800
committerGitHub <noreply@github.com>2022-03-22 16:22:54 +0100
commit7a550b3af20dad94cf468012a6b817b43b91c1ba (patch)
tree1b836eabf8e911f35d0446c0cdad053cb3572c79 /routers/web/auth
parent2b55422cd71b0b325f054646de5cebf39b72b502 (diff)
downloadgitea-7a550b3af20dad94cf468012a6b817b43b91c1ba.tar.gz
gitea-7a550b3af20dad94cf468012a6b817b43b91c1ba.zip
Use `ctx` instead of `db.DefaultContext` in some packages(routers/services/modules) (#19163)
* Remove `db.DefaultContext` usage in routers, use `ctx` directly * Use `ctx` directly if there is one, remove some `db.DefaultContext` in `services` * Use ctx instead of db.DefaultContext for `cmd` and some `modules` packages * fix incorrect context usage
Diffstat (limited to 'routers/web/auth')
-rw-r--r--routers/web/auth/auth.go10
-rw-r--r--routers/web/auth/oauth.go5
-rw-r--r--routers/web/auth/password.go5
3 files changed, 9 insertions, 11 deletions
diff --git a/routers/web/auth/auth.go b/routers/web/auth/auth.go
index 556fd26d01..ab538f0e5f 100644
--- a/routers/web/auth/auth.go
+++ b/routers/web/auth/auth.go
@@ -107,7 +107,7 @@ func resetLocale(ctx *context.Context, u *user_model.User) error {
// If the user does not have a locale set, we save the current one.
if len(u.Language) == 0 {
u.Language = ctx.Locale.Language()
- if err := user_model.UpdateUserCols(db.DefaultContext, u, "language"); err != nil {
+ if err := user_model.UpdateUserCols(ctx, u, "language"); err != nil {
return err
}
}
@@ -333,7 +333,7 @@ func handleSignInFull(ctx *context.Context, u *user_model.User, remember, obeyRe
// If the user does not have a locale set, we save the current one.
if len(u.Language) == 0 {
u.Language = ctx.Locale.Language()
- if err := user_model.UpdateUserCols(db.DefaultContext, u, "language"); err != nil {
+ if err := user_model.UpdateUserCols(ctx, u, "language"); err != nil {
ctx.ServerError("UpdateUserCols Language", fmt.Errorf("Error updating user language [user: %d, locale: %s]", u.ID, u.Language))
return setting.AppSubURL + "/"
}
@@ -350,7 +350,7 @@ func handleSignInFull(ctx *context.Context, u *user_model.User, remember, obeyRe
// Register last login
u.SetLastLogin()
- if err := user_model.UpdateUserCols(db.DefaultContext, u, "last_login_unix"); err != nil {
+ if err := user_model.UpdateUserCols(ctx, u, "last_login_unix"); err != nil {
ctx.ServerError("UpdateUserCols", err)
return setting.AppSubURL + "/"
}
@@ -606,7 +606,7 @@ func handleUserCreated(ctx *context.Context, u *user_model.User, gothUser *goth.
u.IsAdmin = true
u.IsActive = true
u.SetLastLogin()
- if err := user_model.UpdateUserCols(db.DefaultContext, u, "is_admin", "is_active", "last_login_unix"); err != nil {
+ if err := user_model.UpdateUserCols(ctx, u, "is_admin", "is_active", "last_login_unix"); err != nil {
ctx.ServerError("UpdateUser", err)
return
}
@@ -733,7 +733,7 @@ func handleAccountActivation(ctx *context.Context, user *user_model.User) {
ctx.ServerError("UpdateUser", err)
return
}
- if err := user_model.UpdateUserCols(db.DefaultContext, user, "is_active", "rands"); err != nil {
+ if err := user_model.UpdateUserCols(ctx, user, "is_active", "rands"); err != nil {
if user_model.IsErrUserNotExist(err) {
ctx.NotFound("UpdateUserCols", err)
} else {
diff --git a/routers/web/auth/oauth.go b/routers/web/auth/oauth.go
index 83b58d6cbf..847af52bdb 100644
--- a/routers/web/auth/oauth.go
+++ b/routers/web/auth/oauth.go
@@ -16,7 +16,6 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/auth"
- "code.gitea.io/gitea/models/db"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
@@ -1021,7 +1020,7 @@ func handleOAuth2SignIn(ctx *context.Context, source *auth.Source, u *user_model
cols = append(cols, "is_admin", "is_restricted")
}
- if err := user_model.UpdateUserCols(db.DefaultContext, u, cols...); err != nil {
+ if err := user_model.UpdateUserCols(ctx, u, cols...); err != nil {
ctx.ServerError("UpdateUserCols", err)
return
}
@@ -1048,7 +1047,7 @@ func handleOAuth2SignIn(ctx *context.Context, source *auth.Source, u *user_model
changed := setUserGroupClaims(source, u, &gothUser)
if changed {
- if err := user_model.UpdateUserCols(db.DefaultContext, u, "is_admin", "is_restricted"); err != nil {
+ if err := user_model.UpdateUserCols(ctx, u, "is_admin", "is_restricted"); err != nil {
ctx.ServerError("UpdateUserCols", err)
return
}
diff --git a/routers/web/auth/password.go b/routers/web/auth/password.go
index 8e309ebb1a..d7bf67cffb 100644
--- a/routers/web/auth/password.go
+++ b/routers/web/auth/password.go
@@ -9,7 +9,6 @@ import (
"net/http"
"code.gitea.io/gitea/models/auth"
- "code.gitea.io/gitea/models/db"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
@@ -232,7 +231,7 @@ func ResetPasswdPost(ctx *context.Context) {
return
}
u.MustChangePassword = false
- if err := user_model.UpdateUserCols(db.DefaultContext, u, "must_change_password", "passwd", "passwd_hash_algo", "rands", "salt"); err != nil {
+ if err := user_model.UpdateUserCols(ctx, u, "must_change_password", "passwd", "passwd_hash_algo", "rands", "salt"); err != nil {
ctx.ServerError("UpdateUser", err)
return
}
@@ -327,7 +326,7 @@ func MustChangePasswordPost(ctx *context.Context) {
u.MustChangePassword = false
- if err := user_model.UpdateUserCols(db.DefaultContext, u, "must_change_password", "passwd", "passwd_hash_algo", "salt"); err != nil {
+ if err := user_model.UpdateUserCols(ctx, u, "must_change_password", "passwd", "passwd_hash_algo", "salt"); err != nil {
ctx.ServerError("UpdateUser", err)
return
}