更新若干
This commit is contained in:
1 parent
54c90072fb
commit
5682069553
59 files changed
+3813
-1617
No files matched your search
@@ -77,10 +77,13 @@ func SendIdentityEmailCode(purpose, email string) error {
|
||||
if !IsEmail(email) {
|
||||
return errors.New("请输入正确的邮箱地址")
|
||||
}
|
||||
if purpose != "reset" {
|
||||
if purpose != "reset" && purpose != "login" {
|
||||
return errors.New("参数错误")
|
||||
}
|
||||
if findIdentityByEmail(email) == nil {
|
||||
if purpose == "login" {
|
||||
return errors.New("该邮箱尚未注册,请先注册")
|
||||
}
|
||||
return errors.New("该邮箱尚未绑定账号")
|
||||
}
|
||||
|
||||
@@ -97,15 +100,21 @@ func SendIdentityEmailCode(purpose, email string) error {
|
||||
}
|
||||
|
||||
code := fmt.Sprintf("%06d", rand.Intn(1000000)) //nolint:gosec // 验证码场景可接受
|
||||
mailTitle := "找回密码验证码"
|
||||
mailHeading := "找回密码验证码"
|
||||
if purpose == "login" {
|
||||
mailTitle = "登录验证码"
|
||||
mailHeading = "登录验证码"
|
||||
}
|
||||
html := fmt.Sprintf(`
|
||||
<div style="font-family: Arial, sans-serif; padding: 22px; border: 1px solid #eee; border-radius: 6px; max-width: 520px;">
|
||||
<h3 style="color: #2563eb; margin: 0 0 16px;">找回密码验证码</h3>
|
||||
<h3 style="color: #2563eb; margin: 0 0 16px;">%s</h3>
|
||||
<p style="font-size: 15px; color: #333; margin: 0 0 6px;">您的验证码是:</p>
|
||||
<p style="font-size: 30px; font-weight: 700; letter-spacing: 6px; color: #2563eb; margin: 0 0 18px;">%s</p>
|
||||
<p style="font-size: 13px; color: #666; margin: 0;">验证码 5 分钟内有效。为保护账号安全,请勿转发给他人。</p>
|
||||
</div>
|
||||
`, code)
|
||||
if err := SendHTMLEmailSMTP(cfg, email, "找回密码验证码", html); err != nil {
|
||||
`, mailHeading, code)
|
||||
if err := SendHTMLEmailSMTP(cfg, email, mailTitle, html); err != nil {
|
||||
return errors.New("邮件发送失败,请稍后重试")
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user