注册帐号时,如果尚未验证,再发一次验证信
This commit is contained in:
parent
9c78515c72
commit
6c67b704e7
1 changed files with 14 additions and 4 deletions
|
@ -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{}
|
||||
|
|
Loading…
Add table
Reference in a new issue