mirror of
https://github.com/snowykami/neo-blog.git
synced 2025-09-05 16:56:22 +00:00
⚡️ feat: add main page layout with navigation and footer
feat: create random labels page feat: implement login page with OpenID Connect support feat: add Gravatar component for user avatars feat: create Navbar component with navigation menu chore: create Sidebar component placeholder feat: implement login form with OIDC and email/password options feat: add reusable button component feat: create card component for structured content display feat: implement input component for forms feat: create label component for form labels feat: add navigation menu component for site navigation chore: add configuration file for site metadata feat: implement device context for responsive design feat: add utility functions for class name management feat: define OIDC configuration model feat: define base response model for API responses feat: define user model for user data feat: implement i18n for internationalization support feat: add English and Chinese translations for login chore: create index for locale resources chore: add blog home view placeholder
This commit is contained in:
@ -2,6 +2,7 @@ package v1
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/cloudwego/hertz/pkg/app"
|
||||
"github.com/cloudwego/hertz/pkg/common/utils"
|
||||
"github.com/snowykami/neo-blog/internal/ctxutils"
|
||||
@ -82,8 +83,13 @@ func (u *UserController) OidcList(ctx context.Context, c *app.RequestContext) {
|
||||
|
||||
func (u *UserController) OidcLogin(ctx context.Context, c *app.RequestContext) {
|
||||
name := c.Param("name")
|
||||
code := c.Param("code")
|
||||
state := c.Param("state")
|
||||
code := c.Query("code")
|
||||
state := c.Query("state")
|
||||
redirectUri := c.Query("redirect_back") // 前端路由登录前的重定向地址
|
||||
if redirectUri == "" {
|
||||
redirectUri = "/"
|
||||
}
|
||||
fmt.Println("redirectBack:", redirectUri)
|
||||
oidcLoginReq := &dto.OidcLoginReq{
|
||||
Name: name,
|
||||
Code: code,
|
||||
@ -96,22 +102,14 @@ func (u *UserController) OidcLogin(ctx context.Context, c *app.RequestContext) {
|
||||
return
|
||||
}
|
||||
ctxutils.SetTokenAndRefreshTokenCookie(c, resp.Token, resp.RefreshToken)
|
||||
resps.Ok(c, resps.Success, map[string]any{
|
||||
"token": resp.Token,
|
||||
"user": resp.User,
|
||||
})
|
||||
resps.Redirect(c, redirectUri) // 重定向到前端路由
|
||||
}
|
||||
|
||||
func (u *UserController) GetUser(ctx context.Context, c *app.RequestContext) {
|
||||
userID := c.Param("id")
|
||||
if userID == "" {
|
||||
resps.BadRequest(c, resps.ErrParamInvalid)
|
||||
return
|
||||
}
|
||||
userIDInt, err := strconv.Atoi(userID)
|
||||
if err != nil || userIDInt <= 0 {
|
||||
resps.BadRequest(c, resps.ErrParamInvalid)
|
||||
return
|
||||
userIDInt = int(ctxutils.GetCurrentUserID(ctx))
|
||||
}
|
||||
|
||||
resp, err := u.service.GetUser(&dto.GetUserReq{UserID: uint(userIDInt)})
|
||||
@ -142,7 +140,7 @@ func (u *UserController) UpdateUser(ctx context.Context, c *app.RequestContext)
|
||||
updateUserReq.ID = uint(userIDInt)
|
||||
currentUser := ctxutils.GetCurrentUser(ctx)
|
||||
if currentUser == nil {
|
||||
resps.UnAuthorized(c, resps.ErrUnauthorized)
|
||||
resps.Unauthorized(c, resps.ErrUnauthorized)
|
||||
return
|
||||
}
|
||||
if currentUser.ID != updateUserReq.ID {
|
||||
|
Reference in New Issue
Block a user