mirror of
https://github.com/snowykami/neo-blog.git
synced 2025-09-26 19:16:24 +00:00
feat: 更新验证码逻辑,优化邮件验证功能,增加验证码冷却时间,改进用户体验Closes #17
This commit is contained in:
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user