diff options
author | Joe Chen <jc@unknwon.io> | 2022-11-05 18:56:48 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-05 18:56:48 +0800 |
commit | b5d47b969258f3d644ad797b29901eb607f6b94f (patch) | |
tree | 790d2f06c0fc1dc0442c3869edf7fcd2dd6a8e42 /internal/context/auth.go | |
parent | fd798b4197dc53df872d20f5d10edb8d73c32386 (diff) |
refactor(db): migrate methods off `user.go` (#7230)
Diffstat (limited to 'internal/context/auth.go')
-rw-r--r-- | internal/context/auth.go | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/internal/context/auth.go b/internal/context/auth.go index 775a3dd8..73a362c6 100644 --- a/internal/context/auth.go +++ b/internal/context/auth.go @@ -175,7 +175,7 @@ func authenticatedUser(ctx *macaron.Context, sess session.Store) (_ *db.User, is if conf.Auth.EnableReverseProxyAuthentication { webAuthUser := ctx.Req.Header.Get(conf.Auth.ReverseProxyAuthenticationHeader) if len(webAuthUser) > 0 { - u, err := db.GetUserByName(webAuthUser) + user, err := db.GetUserByName(webAuthUser) if err != nil { if !db.IsErrUserNotExist(err) { log.Error("Failed to get user by name: %v", err) @@ -184,22 +184,21 @@ func authenticatedUser(ctx *macaron.Context, sess session.Store) (_ *db.User, is // Check if enabled auto-registration. if conf.Auth.EnableReverseProxyAutoRegistration { - u := &db.User{ - Name: webAuthUser, - Email: gouuid.NewV4().String() + "@localhost", - Password: webAuthUser, - IsActive: true, - } - if err = db.CreateUser(u); err != nil { - // FIXME: should I create a system notice? - log.Error("Failed to create user: %v", err) + user, err = db.Users.Create( + ctx.Req.Context(), + webAuthUser, + gouuid.NewV4().String()+"@localhost", + db.CreateUserOptions{ + Activated: true, + }, + ) + if err != nil { + log.Error("Failed to create user %q: %v", webAuthUser, err) return nil, false, false - } else { - return u, false, false } } } - return u, false, false + return user, false, false } } |