feat: 更新验证码逻辑,优化邮件验证功能,增加验证码冷却时间,改进用户体验Closes #17

This commit is contained in:
2025-09-24 09:33:09 +08:00
parent 291f52395b
commit e44637fb2a
19 changed files with 138 additions and 58 deletions

View File

@ -5,6 +5,7 @@ import (
"github.com/cloudwego/hertz/pkg/app"
"github.com/sirupsen/logrus"
"github.com/snowykami/neo-blog/pkg/constant"
"github.com/snowykami/neo-blog/pkg/resps"
"github.com/snowykami/neo-blog/pkg/utils"
)
@ -14,8 +15,8 @@ func UseCaptcha() app.HandlerFunc {
captchaConfig := utils.Captcha.GetCaptchaConfigFromEnv()
return func(ctx context.Context, c *app.RequestContext) {
CaptchaToken := string(c.GetHeader("X-Captcha-Token"))
if utils.IsDevMode && CaptchaToken == utils.Env.Get("CAPTCHA_DEV_PASSCODE", "dev_passcode") {
// 开发模式直接通过密钥
if utils.IsDevMode && CaptchaToken == utils.Env.Get(constant.EnvKeyPasscode, constant.DefaultCaptchaDevPasscode) {
// 开发模式直接通过密钥开启开发模式后Captcha可被绕过请注意安全
c.Next(ctx)
return
}

View File

@ -114,7 +114,13 @@ func (s *UserService) UserRegister(req *dto.UserRegisterReq) (*dto.UserRegisterR
func (s *UserService) RequestVerifyEmail(req *dto.VerifyEmailReq) (*dto.VerifyEmailResp, error) {
verifyCode := utils.RequestEmailVerify(req.Email)
template, err := static.RenderTemplate("email/verification-code.tmpl", map[string]interface{}{})
template, err := static.RenderTemplate("email/verification-code.tmpl", map[string]interface{}{
"Title": "NEO-BLOG",
"Email": req.Email,
"VerifyCode": verifyCode,
"Expire": 10,
"Details": "你正在验证电子邮件所有权",
})
if err != nil {
return nil, errs.ErrInternalServer
}