注册帐号时,如果尚未验证,再发一次验证信
This commit is contained in:
parent
9c78515c72
commit
6c67b704e7
1 changed files with 14 additions and 4 deletions
|
@ -64,11 +64,17 @@ func (service *UserRegisterService) Register(c *gin.Context) serializer.Response
|
||||||
user.Status = model.NotActivicated
|
user.Status = model.NotActivicated
|
||||||
}
|
}
|
||||||
user.GroupID = uint(defaultGroup)
|
user.GroupID = uint(defaultGroup)
|
||||||
|
userNotActivated := false
|
||||||
// 创建用户
|
// 创建用户
|
||||||
if err := model.DB.Create(&user).Error; err != nil {
|
if err := model.DB.Create(&user).Error; err != nil {
|
||||||
|
//检查已存在使用者是否尚未激活
|
||||||
|
expectedUser, err := model.GetUserByEmail(service.UserName)
|
||||||
|
if expectedUser.Status == model.NotActivicated {
|
||||||
|
userNotActivated = true
|
||||||
|
} else {
|
||||||
return serializer.DBErr("此邮箱已被使用", err)
|
return serializer.DBErr("此邮箱已被使用", err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 发送激活邮件
|
// 发送激活邮件
|
||||||
if isEmailRequired {
|
if isEmailRequired {
|
||||||
|
@ -100,9 +106,13 @@ func (service *UserRegisterService) Register(c *gin.Context) serializer.Response
|
||||||
if err := email.Send(user.Email, title, body); err != nil {
|
if err := email.Send(user.Email, title, body); err != nil {
|
||||||
return serializer.Err(serializer.CodeInternalSetting, "无法发送激活邮件", err)
|
return serializer.Err(serializer.CodeInternalSetting, "无法发送激活邮件", err)
|
||||||
}
|
}
|
||||||
|
if userNotActivated == true {
|
||||||
|
//原本在上面要抛出的DBErr,放来这边抛出
|
||||||
|
return serializer.DBErr("用户未激活,已重新发送激活码", nil)
|
||||||
|
} else {
|
||||||
return serializer.Response{Code: 203}
|
return serializer.Response{Code: 203}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return serializer.Response{}
|
return serializer.Response{}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue