mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-21 17:24:10 +00:00
Reduce usage of db.DefaultContext
(#27073)
Part of #27065 This reduces the usage of `db.DefaultContext`. I think I've got enough files for the first PR. When this is merged, I will continue working on this. Considering how many files this PR affect, I hope it won't take to long to merge, so I don't end up in the merge conflict hell. --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
parent
0de09d3afc
commit
76659b1114
83 changed files with 339 additions and 324 deletions
|
@ -199,7 +199,7 @@ func SignInPost(ctx *context.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
u, source, err := auth_service.UserSignIn(form.UserName, form.Password)
|
||||
u, source, err := auth_service.UserSignIn(ctx, form.UserName, form.Password)
|
||||
if err != nil {
|
||||
if errors.Is(err, util.ErrNotExist) || errors.Is(err, util.ErrInvalidArgument) {
|
||||
ctx.RenderWithErr(ctx.Tr("form.username_password_incorrect"), tplSignIn, &form)
|
||||
|
@ -509,15 +509,15 @@ func createAndHandleCreatedUser(ctx *context.Context, tpl base.TplName, form any
|
|||
// createUserInContext creates a user and handles errors within a given context.
|
||||
// Optionally a template can be specified.
|
||||
func createUserInContext(ctx *context.Context, tpl base.TplName, form any, u *user_model.User, overwrites *user_model.CreateUserOverwriteOptions, gothUser *goth.User, allowLink bool) (ok bool) {
|
||||
if err := user_model.CreateUser(u, overwrites); err != nil {
|
||||
if err := user_model.CreateUser(ctx, u, overwrites); err != nil {
|
||||
if allowLink && (user_model.IsErrUserAlreadyExist(err) || user_model.IsErrEmailAlreadyUsed(err)) {
|
||||
if setting.OAuth2Client.AccountLinking == setting.OAuth2AccountLinkingAuto {
|
||||
var user *user_model.User
|
||||
user = &user_model.User{Name: u.Name}
|
||||
hasUser, err := user_model.GetUser(user)
|
||||
hasUser, err := user_model.GetUser(ctx, user)
|
||||
if !hasUser || err != nil {
|
||||
user = &user_model.User{Email: u.Email}
|
||||
hasUser, err = user_model.GetUser(user)
|
||||
hasUser, err = user_model.GetUser(ctx, user)
|
||||
if !hasUser || err != nil {
|
||||
ctx.ServerError("UserLinkAccount", err)
|
||||
return false
|
||||
|
@ -576,7 +576,7 @@ func createUserInContext(ctx *context.Context, tpl base.TplName, form any, u *us
|
|||
// sends a confirmation email if required.
|
||||
func handleUserCreated(ctx *context.Context, u *user_model.User, gothUser *goth.User) (ok bool) {
|
||||
// Auto-set admin for the only user.
|
||||
if user_model.CountUsers(nil) == 1 {
|
||||
if user_model.CountUsers(ctx, nil) == 1 {
|
||||
u.IsAdmin = true
|
||||
u.IsActive = true
|
||||
u.SetLastLogin()
|
||||
|
@ -652,7 +652,7 @@ func Activate(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
user := user_model.VerifyUserActiveCode(code)
|
||||
user := user_model.VerifyUserActiveCode(ctx, code)
|
||||
// if code is wrong
|
||||
if user == nil {
|
||||
ctx.Data["IsCodeInvalid"] = true
|
||||
|
@ -679,7 +679,7 @@ func ActivatePost(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
user := user_model.VerifyUserActiveCode(code)
|
||||
user := user_model.VerifyUserActiveCode(ctx, code)
|
||||
// if code is wrong
|
||||
if user == nil {
|
||||
ctx.Data["IsCodeInvalid"] = true
|
||||
|
@ -722,7 +722,7 @@ func handleAccountActivation(ctx *context.Context, user *user_model.User) {
|
|||
return
|
||||
}
|
||||
|
||||
if err := user_model.ActivateUserEmail(user.ID, user.Email, true); err != nil {
|
||||
if err := user_model.ActivateUserEmail(ctx, user.ID, user.Email, true); err != nil {
|
||||
log.Error("Unable to activate email for user: %-v with email: %s: %v", user, user.Email, err)
|
||||
ctx.ServerError("ActivateUserEmail", err)
|
||||
return
|
||||
|
@ -767,8 +767,8 @@ func ActivateEmail(ctx *context.Context) {
|
|||
emailStr := ctx.FormString("email")
|
||||
|
||||
// Verify code.
|
||||
if email := user_model.VerifyActiveEmailCode(code, emailStr); email != nil {
|
||||
if err := user_model.ActivateEmail(email); err != nil {
|
||||
if email := user_model.VerifyActiveEmailCode(ctx, code, emailStr); email != nil {
|
||||
if err := user_model.ActivateEmail(ctx, email); err != nil {
|
||||
ctx.ServerError("ActivateEmail", err)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue