From 6c67b704e7e13071b47a65c6b17b016beec9ab46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=97=A5=E4=B8=8B=E9=83=A8=20=E8=A9=A9?= Date: Thu, 18 Feb 2021 03:08:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B3=A8=E5=86=8C=E5=B8=90=E5=8F=B7=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E5=A6=82=E6=9E=9C=E5=B0=9A=E6=9C=AA=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=EF=BC=8C=E5=86=8D=E5=8F=91=E4=B8=80=E6=AC=A1=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E4=BF=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- service/user/register.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/service/user/register.go b/service/user/register.go index 04083ad..b8ca5ca 100644 --- a/service/user/register.go +++ b/service/user/register.go @@ -64,10 +64,16 @@ func (service *UserRegisterService) Register(c *gin.Context) serializer.Response user.Status = model.NotActivicated } user.GroupID = uint(defaultGroup) - + userNotActivated := false // 创建用户 if err := model.DB.Create(&user).Error; err != nil { - return serializer.DBErr("此邮箱已被使用", err) + //检查已存在使用者是否尚未激活 + expectedUser, err := model.GetUserByEmail(service.UserName) + if expectedUser.Status == model.NotActivicated { + userNotActivated = true + } else { + return serializer.DBErr("此邮箱已被使用", err) + } } // 发送激活邮件 @@ -100,8 +106,12 @@ func (service *UserRegisterService) Register(c *gin.Context) serializer.Response if err := email.Send(user.Email, title, body); err != nil { return serializer.Err(serializer.CodeInternalSetting, "无法发送激活邮件", err) } - - return serializer.Response{Code: 203} + if userNotActivated == true { + //原本在上面要抛出的DBErr,放来这边抛出 + return serializer.DBErr("用户未激活,已重新发送激活码", nil) + } else { + return serializer.Response{Code: 203} + } } return serializer.Response{}