mirror of
https://github.com/snowykami/neo-blog.git
synced 2025-09-26 02:56:22 +00:00
All checks were successful
Push to Helm Chart Repository / build (push) Successful in 13s
- Removed the old reset password form component and replaced it with a new implementation. - Updated routing paths for login, registration, and reset password to be under a common auth path. - Added new login and registration pages with corresponding forms. - Introduced a common auth header component for consistent branding across auth pages. - Implemented a current logged-in user display component. - Enhanced the register form to include email verification and captcha. - Updated translations for new and modified components. - Refactored the navigation bar to include user avatar dropdown and improved menu structure.
33 lines
921 B
Go
33 lines
921 B
Go
package middleware
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
|
|
"github.com/cloudwego/hertz/pkg/app"
|
|
"github.com/snowykami/neo-blog/pkg/constant"
|
|
"github.com/snowykami/neo-blog/pkg/resps"
|
|
"github.com/snowykami/neo-blog/pkg/utils"
|
|
)
|
|
|
|
// UseEmailVerify 中间件函数,用于邮箱验证,使用前先调用请求发送邮件验证码函数
|
|
func UseEmailVerify() app.HandlerFunc {
|
|
return func(ctx context.Context, c *app.RequestContext) {
|
|
email := strings.TrimSpace(string(c.GetHeader(constant.HeaderKeyEmail)))
|
|
verifyCode := strings.TrimSpace(string(c.GetHeader(constant.HeaderKeyVerifyCode)))
|
|
if !utils.Env.GetAsBool(constant.EnvKeyEnableEmailVerify, true) {
|
|
c.Next(ctx)
|
|
}
|
|
if email == "" || verifyCode == "" {
|
|
resps.BadRequest(c, "缺失email和verifyCode")
|
|
return
|
|
}
|
|
ok := utils.VerifyEmailCode(email, verifyCode)
|
|
if !ok {
|
|
resps.Unauthorized(c, "验证码错误")
|
|
return
|
|
}
|
|
c.Next(ctx)
|
|
}
|
|
}
|