mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-10-14 23:00:27 +00:00
fix: prevent common user from specifying channel id (#12)
This commit is contained in:
@@ -175,3 +175,16 @@ func ResetUserPasswordByEmail(email string, password string) error {
|
||||
err = DB.Model(&User{}).Where("email = ?", email).Update("password", hashedPassword).Error
|
||||
return err
|
||||
}
|
||||
|
||||
func IsAdmin(userId int) bool {
|
||||
if userId == 0 {
|
||||
return false
|
||||
}
|
||||
var user User
|
||||
err := DB.Where("id = ?", userId).Select("role").Find(&user).Error
|
||||
if err != nil {
|
||||
common.SysError("No such user " + err.Error())
|
||||
return false
|
||||
}
|
||||
return user.Role >= common.RoleAdminUser
|
||||
}
|
||||
|
Reference in New Issue
Block a user