mirror of
https://github.com/gogs/gogs.git
synced 2025-12-24 01:00:00 +01:00
chore: rename internal/db to internal/database (#7665)
This commit is contained in:
@@ -19,7 +19,7 @@ import (
|
||||
|
||||
"gogs.io/gogs/internal/auth"
|
||||
"gogs.io/gogs/internal/conf"
|
||||
"gogs.io/gogs/internal/db"
|
||||
"gogs.io/gogs/internal/database"
|
||||
"gogs.io/gogs/internal/tool"
|
||||
)
|
||||
|
||||
@@ -109,7 +109,7 @@ func isAPIPath(url string) bool {
|
||||
// authenticatedUserID returns the ID of the authenticated user, along with a bool value
|
||||
// which indicates whether the user uses token authentication.
|
||||
func authenticatedUserID(c *macaron.Context, sess session.Store) (_ int64, isTokenAuth bool) {
|
||||
if !db.HasEngine {
|
||||
if !database.HasEngine {
|
||||
return 0, false
|
||||
}
|
||||
|
||||
@@ -132,14 +132,14 @@ func authenticatedUserID(c *macaron.Context, sess session.Store) (_ int64, isTok
|
||||
|
||||
// Let's see if token is valid.
|
||||
if len(tokenSHA) > 0 {
|
||||
t, err := db.AccessTokens.GetBySHA1(c.Req.Context(), tokenSHA)
|
||||
t, err := database.AccessTokens.GetBySHA1(c.Req.Context(), tokenSHA)
|
||||
if err != nil {
|
||||
if !db.IsErrAccessTokenNotExist(err) {
|
||||
if !database.IsErrAccessTokenNotExist(err) {
|
||||
log.Error("GetAccessTokenBySHA: %v", err)
|
||||
}
|
||||
return 0, false
|
||||
}
|
||||
if err = db.AccessTokens.Touch(c.Req.Context(), t.ID); err != nil {
|
||||
if err = database.AccessTokens.Touch(c.Req.Context(), t.ID); err != nil {
|
||||
log.Error("Failed to touch access token: %v", err)
|
||||
}
|
||||
return t.UserID, true
|
||||
@@ -151,9 +151,9 @@ func authenticatedUserID(c *macaron.Context, sess session.Store) (_ int64, isTok
|
||||
return 0, false
|
||||
}
|
||||
if id, ok := uid.(int64); ok {
|
||||
_, err := db.Users.GetByID(c.Req.Context(), id)
|
||||
_, err := database.Users.GetByID(c.Req.Context(), id)
|
||||
if err != nil {
|
||||
if !db.IsErrUserNotExist(err) {
|
||||
if !database.IsErrUserNotExist(err) {
|
||||
log.Error("Failed to get user by ID: %v", err)
|
||||
}
|
||||
return 0, false
|
||||
@@ -165,8 +165,8 @@ func authenticatedUserID(c *macaron.Context, sess session.Store) (_ int64, isTok
|
||||
|
||||
// authenticatedUser returns the user object of the authenticated user, along with two bool values
|
||||
// which indicate whether the user uses HTTP Basic Authentication or token authentication respectively.
|
||||
func authenticatedUser(ctx *macaron.Context, sess session.Store) (_ *db.User, isBasicAuth, isTokenAuth bool) {
|
||||
if !db.HasEngine {
|
||||
func authenticatedUser(ctx *macaron.Context, sess session.Store) (_ *database.User, isBasicAuth, isTokenAuth bool) {
|
||||
if !database.HasEngine {
|
||||
return nil, false, false
|
||||
}
|
||||
|
||||
@@ -176,20 +176,20 @@ 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 {
|
||||
user, err := db.Users.GetByUsername(ctx.Req.Context(), webAuthUser)
|
||||
user, err := database.Users.GetByUsername(ctx.Req.Context(), webAuthUser)
|
||||
if err != nil {
|
||||
if !db.IsErrUserNotExist(err) {
|
||||
if !database.IsErrUserNotExist(err) {
|
||||
log.Error("Failed to get user by name: %v", err)
|
||||
return nil, false, false
|
||||
}
|
||||
|
||||
// Check if enabled auto-registration.
|
||||
if conf.Auth.EnableReverseProxyAutoRegistration {
|
||||
user, err = db.Users.Create(
|
||||
user, err = database.Users.Create(
|
||||
ctx.Req.Context(),
|
||||
webAuthUser,
|
||||
gouuid.NewV4().String()+"@localhost",
|
||||
db.CreateUserOptions{
|
||||
database.CreateUserOptions{
|
||||
Activated: true,
|
||||
},
|
||||
)
|
||||
@@ -210,7 +210,7 @@ func authenticatedUser(ctx *macaron.Context, sess session.Store) (_ *db.User, is
|
||||
if len(auths) == 2 && auths[0] == "Basic" {
|
||||
uname, passwd, _ := tool.BasicAuthDecode(auths[1])
|
||||
|
||||
u, err := db.Users.Authenticate(ctx.Req.Context(), uname, passwd, -1)
|
||||
u, err := database.Users.Authenticate(ctx.Req.Context(), uname, passwd, -1)
|
||||
if err != nil {
|
||||
if !auth.IsErrBadCredentials(err) {
|
||||
log.Error("Failed to authenticate user: %v", err)
|
||||
@@ -224,7 +224,7 @@ func authenticatedUser(ctx *macaron.Context, sess session.Store) (_ *db.User, is
|
||||
return nil, false, false
|
||||
}
|
||||
|
||||
u, err := db.Users.GetByID(ctx.Req.Context(), uid)
|
||||
u, err := database.Users.GetByID(ctx.Req.Context(), uid)
|
||||
if err != nil {
|
||||
log.Error("GetUserByID: %v", err)
|
||||
return nil, false, false
|
||||
@@ -233,19 +233,19 @@ func authenticatedUser(ctx *macaron.Context, sess session.Store) (_ *db.User, is
|
||||
}
|
||||
|
||||
// AuthenticateByToken attempts to authenticate a user by the given access
|
||||
// token. It returns db.ErrAccessTokenNotExist when the access token does not
|
||||
// token. It returns database.ErrAccessTokenNotExist when the access token does not
|
||||
// exist.
|
||||
func AuthenticateByToken(ctx context.Context, token string) (*db.User, error) {
|
||||
t, err := db.AccessTokens.GetBySHA1(ctx, token)
|
||||
func AuthenticateByToken(ctx context.Context, token string) (*database.User, error) {
|
||||
t, err := database.AccessTokens.GetBySHA1(ctx, token)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "get access token by SHA1")
|
||||
}
|
||||
if err = db.AccessTokens.Touch(ctx, t.ID); err != nil {
|
||||
if err = database.AccessTokens.Touch(ctx, t.ID); err != nil {
|
||||
// NOTE: There is no need to fail the auth flow if we can't touch the token.
|
||||
log.Error("Failed to touch access token [id: %d]: %v", t.ID, err)
|
||||
}
|
||||
|
||||
user, err := db.Users.GetByID(ctx, t.UserID)
|
||||
user, err := database.Users.GetByID(ctx, t.UserID)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "get user by ID [user_id: %d]", t.UserID)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user