aboutsummaryrefslogtreecommitdiffstats
path: root/services/auth/signin.go
diff options
context:
space:
mode:
authorJakobDev <jakobdev@gmx.de>2023-09-14 19:09:32 +0200
committerGitHub <noreply@github.com>2023-09-14 17:09:32 +0000
commit76659b1114153603050de810006e04a938e9dcb7 (patch)
treeed180213ca459bca51c44dbcc55fd3f9bc2d0460 /services/auth/signin.go
parent0de09d3afcb5394cbd97e4a1c5609eb8b2acb6cf (diff)
downloadgitea-76659b1114153603050de810006e04a938e9dcb7.tar.gz
gitea-76659b1114153603050de810006e04a938e9dcb7.zip
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>
Diffstat (limited to 'services/auth/signin.go')
-rw-r--r--services/auth/signin.go11
1 files changed, 6 insertions, 5 deletions
diff --git a/services/auth/signin.go b/services/auth/signin.go
index 1095b27fe2..6d515ac628 100644
--- a/services/auth/signin.go
+++ b/services/auth/signin.go
@@ -4,6 +4,7 @@
package auth
import (
+ "context"
"strings"
"code.gitea.io/gitea/models/auth"
@@ -20,14 +21,14 @@ import (
)
// UserSignIn validates user name and password.
-func UserSignIn(username, password string) (*user_model.User, *auth.Source, error) {
+func UserSignIn(ctx context.Context, username, password string) (*user_model.User, *auth.Source, error) {
var user *user_model.User
isEmail := false
if strings.Contains(username, "@") {
isEmail = true
emailAddress := user_model.EmailAddress{LowerEmail: strings.ToLower(strings.TrimSpace(username))}
// check same email
- has, err := db.GetEngine(db.DefaultContext).Get(&emailAddress)
+ has, err := db.GetEngine(ctx).Get(&emailAddress)
if err != nil {
return nil, nil, err
}
@@ -49,7 +50,7 @@ func UserSignIn(username, password string) (*user_model.User, *auth.Source, erro
}
if user != nil {
- hasUser, err := user_model.GetUser(user)
+ hasUser, err := user_model.GetUser(ctx, user)
if err != nil {
return nil, nil, err
}
@@ -69,7 +70,7 @@ func UserSignIn(username, password string) (*user_model.User, *auth.Source, erro
return nil, nil, smtp.ErrUnsupportedLoginType
}
- user, err := authenticator.Authenticate(user, user.LoginName, password)
+ user, err := authenticator.Authenticate(ctx, user, user.LoginName, password)
if err != nil {
return nil, nil, err
}
@@ -100,7 +101,7 @@ func UserSignIn(username, password string) (*user_model.User, *auth.Source, erro
continue
}
- authUser, err := authenticator.Authenticate(nil, username, password)
+ authUser, err := authenticator.Authenticate(ctx, nil, username, password)
if err == nil {
if !authUser.ProhibitLogin {