fix: check user status when validating token (#23)

This commit is contained in:
JustSong
2023-04-27 15:05:33 +08:00
parent 9272884381
commit 54b1e4adef
2 changed files with 23 additions and 0 deletions

View File

@@ -195,6 +195,19 @@ func IsAdmin(userId int) bool {
return user.Role >= common.RoleAdminUser
}
func IsUserEnabled(userId int) bool {
if userId == 0 {
return false
}
var user User
err := DB.Where("id = ?", userId).Select("status").Find(&user).Error
if err != nil {
common.SysError("No such user " + err.Error())
return false
}
return user.Status == common.UserStatusEnabled
}
func ValidateAccessToken(token string) (user *User) {
if token == "" {
return nil