From 72420f2ede4c957ef12fe31aea5955ec04786327 Mon Sep 17 00:00:00 2001 From: coward Date: Wed, 4 Sep 2024 10:06:29 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=E4=BF=AE=E5=A4=8D=E5=8F=AF=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E5=88=9B=E5=BB=BA=E7=9B=B8=E5=90=8C=E8=B4=A6=E5=8F=B7?= =?UTF-8?q?=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- service/user.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/service/user.go b/service/user.go index 044ffee..0564f85 100644 --- a/service/user.go +++ b/service/user.go @@ -39,6 +39,11 @@ func (s user) CreateUser(user *model.User) (err error) { return s.Model(&model.User{}).Where("id = ?", user.Id).Updates(&updates).Error } + // 判断账号是否已经存在 + if _, err = s.GetUserByAccount(user.Account); err == nil { + return errors.New("账号已经存在,请勿重复创建!") + } + defaultPassword := utils.Password().GenerateHashPassword("admin123") if user.Password == "" { // 没有密码给一个默认密码 user.Password = defaultPassword