From 838652503c5628430071c1bf50125778130e935b Mon Sep 17 00:00:00 2001 From: xmdhs Date: Thu, 5 Oct 2023 15:34:26 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A6=81=E7=94=A8=E7=94=A8=E6=88=B7=E7=99=BB?= =?UTF-8?q?=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- service/utils/auth.go | 8 ++++++++ service/yggdrasil/user.go | 11 ++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/service/utils/auth.go b/service/utils/auth.go index e1b3596..1f9e291 100644 --- a/service/utils/auth.go +++ b/service/utils/auth.go @@ -79,3 +79,11 @@ func Auth(ctx context.Context, t yggdrasil.ValidateToken, client *ent.Client, c } return claims, nil } + +func IsAdmin(state int) bool { + return state&1 == 1 +} + +func IsDisable(state int) bool { + return state&2 == 2 +} diff --git a/service/yggdrasil/user.go b/service/yggdrasil/user.go index 9a8a659..6c6f087 100644 --- a/service/yggdrasil/user.go +++ b/service/yggdrasil/user.go @@ -30,9 +30,10 @@ import ( ) var ( - ErrRate = errors.New("频率限制") - ErrPassWord = errors.New("错误的密码或邮箱") - ErrNotUser = errors.New("没有这个用户") + ErrRate = errors.New("频率限制") + ErrPassWord = errors.New("错误的密码或邮箱") + ErrNotUser = errors.New("没有这个用户") + ErrUserDisable = errors.New("用户被禁用") ) func (y *Yggdrasil) validatePass(cxt context.Context, email, pass string) (*ent.User, error) { @@ -60,6 +61,10 @@ func (y *Yggdrasil) Authenticate(cxt context.Context, auth yggdrasil.Authenticat return yggdrasil.Token{}, fmt.Errorf("Authenticate: %w", err) } + if sutils.IsDisable(u.State) { + return yggdrasil.Token{}, fmt.Errorf("Authenticate: %w", ErrUserDisable) + } + clientToken := auth.ClientToken if clientToken == "" { clientToken = strings.ReplaceAll(uuid.New().String(), "-", "")