注册帐号时,如果尚未验证,再发一次验证信

This commit is contained in:
日下部 詩 2021-02-18 03:08:08 +08:00 committed by GitHub
parent 9c78515c72
commit 6c67b704e7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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{}