diff --git a/auth/api_auth.go b/auth/api_auth.go index a8bf8ec..f80c973 100644 --- a/auth/api_auth.go +++ b/auth/api_auth.go @@ -80,7 +80,7 @@ func ApiLogout(c *gin.Context) { } func ApiMe(c *gin.Context) { - usr, err := GetUser(c, DB) + usr, err := GetUser(c) if err != nil { ClearToken(c) panic(errors.NewError(http.StatusUnauthorized, err)) diff --git a/auth/api_user.go b/auth/api_user.go index 1ba8e82..4deadd9 100644 --- a/auth/api_user.go +++ b/auth/api_user.go @@ -36,7 +36,7 @@ func ApiUserNew(c *gin.Context) { Username: data.Name, Password: string(pwd), } - err = NewUser(usr, DB) + err = NewUser(usr) if err != nil { panic(err) } diff --git a/auth/helper.go b/auth/helper.go index 9e07e06..41539c0 100644 --- a/auth/helper.go +++ b/auth/helper.go @@ -144,13 +144,13 @@ and user_id = ?`, } } -func GetUser(c *gin.Context, db *gorm.DB) (*User, error) { +func GetUser(c *gin.Context) (*User, error) { claim, err := GetContextClaims(c) if err != nil { return nil, err } usr := &User{} - err = db.Preload("Groups").Preload("Profile").Where("id = ?", claim.Uid).First(usr).Error + err = DB.Preload("Groups").Preload("Profile").Where("id = ?", claim.Uid).First(usr).Error if err != nil { return nil, err } @@ -158,7 +158,7 @@ func GetUser(c *gin.Context, db *gorm.DB) (*User, error) { } // NewUser the password is still not hashed -func NewUser(usr *User, db *gorm.DB) error { +func NewUser(usr *User) error { if usr.Username == "" || usr.Password == "" { return ErrorBadRequestTmpl.New("auth.User") }