feat: add captcha support for user login and enhance user profile page

- Refactored userLogin function to include captcha handling.
- Introduced getCaptchaConfig API to fetch captcha configuration.
- Added Captcha component to handle different captcha providers (hCaptcha, reCaptcha, Turnstile).
- Updated LoginForm component to integrate captcha verification.
- Created UserProfile component to display user information with avatar.
- Implemented getUserByUsername API to fetch user details by username.
- Removed deprecated LoginRequest interface from user model.
- Enhanced navbar and layout with animation effects.
- Removed unused user page component and added dynamic user profile routing.
- Updated localization files to include captcha-related messages.
- Improved Gravatar component for better avatar handling.
This commit is contained in:
2025-09-10 21:15:36 +08:00
parent a7da023b1e
commit 4781d81869
28 changed files with 1048 additions and 701 deletions

View File

@ -10,8 +10,10 @@ import (
"github.com/snowykami/neo-blog/internal/ctxutils"
"github.com/snowykami/neo-blog/internal/dto"
"github.com/snowykami/neo-blog/internal/service"
"github.com/snowykami/neo-blog/pkg/constant"
"github.com/snowykami/neo-blog/pkg/errs"
"github.com/snowykami/neo-blog/pkg/resps"
utils2 "github.com/snowykami/neo-blog/pkg/utils"
)
type UserController struct {
@ -125,6 +127,22 @@ func (u *UserController) GetUser(ctx context.Context, c *app.RequestContext) {
return
}
resps.Ok(c, resps.Success, resp.User)
}
func (u *UserController) GetUserByUsername(ctx context.Context, c *app.RequestContext) {
username := c.Param("username")
if username == "" {
resps.BadRequest(c, resps.ErrParamInvalid)
return
}
resp, err := u.service.GetUserByUsername(&dto.GetUserByUsernameReq{Username: username})
if err != nil {
serviceErr := errs.AsServiceError(err)
resps.Custom(c, serviceErr.Code, serviceErr.Message, nil)
return
}
resps.Ok(c, resps.Success, resp.User)
}
func (u *UserController) UpdateUser(ctx context.Context, c *app.RequestContext) {
@ -184,3 +202,11 @@ func (u *UserController) ChangePassword(ctx context.Context, c *app.RequestConte
func (u *UserController) ChangeEmail(ctx context.Context, c *app.RequestContext) {
// TODO: 实现修改邮箱功能
}
func (u *UserController) GetCaptchaConfig(ctx context.Context, c *app.RequestContext) {
resps.Ok(c, "ok", utils.H{
"provider": utils2.Env.Get(constant.EnvKeyCaptchaProvider),
"site_key": utils2.Env.Get(constant.EnvKeyCaptchaSiteKey),
"url": utils2.Env.Get(constant.EnvKeyCaptchaUrl),
})
}