master
Evan Chen 2021-12-17 01:56:21 +08:00
parent d68e8aa6b1
commit e761516c02
3 changed files with 5 additions and 5 deletions

View File

@ -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))

View File

@ -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)
}

View File

@ -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")
}