feat: Closes #14 更新用户模型,确保用户名字段为非空;优化OIDC请求和用户信息处理逻辑;添加新的重写规则以支持HTTPS
All checks were successful
Push to Helm Chart Repository / build (push) Successful in 19s

This commit is contained in:
2025-09-14 13:54:23 +08:00
parent 78cc596544
commit a0b2c75839
6 changed files with 405 additions and 399 deletions

View File

@ -2,7 +2,6 @@ package v1
import ( import (
"context" "context"
"fmt"
"strconv" "strconv"
"github.com/cloudwego/hertz/pkg/app" "github.com/cloudwego/hertz/pkg/app"
@ -92,7 +91,6 @@ func (u *UserController) OidcLogin(ctx context.Context, c *app.RequestContext) {
if redirectUri == "" { if redirectUri == "" {
redirectUri = "/" redirectUri = "/"
} }
fmt.Println("redirectBack:", redirectUri)
oidcLoginReq := &dto.OidcLoginReq{ oidcLoginReq := &dto.OidcLoginReq{
Name: name, Name: name,
Code: code, Code: code,

View File

@ -7,7 +7,7 @@ import (
type User struct { type User struct {
gorm.Model gorm.Model
Username string `gorm:"uniqueIndex"` // 用户名,唯一 Username string `gorm:"uniqueIndex;not null"` // 用户名,唯一
Nickname string Nickname string
AvatarUrl string AvatarUrl string
Email string `gorm:"uniqueIndex"` Email string `gorm:"uniqueIndex"`

View File

@ -275,8 +275,9 @@ func (s *UserService) OidcLogin(req *dto.OidcLoginReq) (*dto.OidcLoginResp, erro
} }
return resp, nil return resp, nil
} else { } else {
// 第一次登录,创建新用户时才获取头像
user = &model.User{ user = &model.User{
Username: userInfo.Name, Username: userInfo.PreferredUsername,
Nickname: userInfo.Name, Nickname: userInfo.Name,
AvatarUrl: userInfo.Picture, AvatarUrl: userInfo.Picture,
Email: userInfo.Email, Email: userInfo.Email,

View File

@ -64,5 +64,6 @@ type UserInfo struct {
Name string `json:"name"` Name string `json:"name"`
Email string `json:"email"` Email string `json:"email"`
Picture string `json:"picture,omitempty"` Picture string `json:"picture,omitempty"`
PreferredUsername string `json:"preferred_username"`
Groups []string `json:"groups,omitempty"` // 可选字段OIDC提供的用户组信息 Groups []string `json:"groups,omitempty"` // 可选字段OIDC提供的用户组信息
} }

View File

@ -18,6 +18,12 @@ const nextConfig: NextConfig = {
port: '', port: '',
pathname: '/**', pathname: '/**',
}, },
{
protocol: 'https',
hostname: 'pass.liteyuki.org',
port: '',
pathname: '/**',
},
], ],
}, },
async rewrites() { async rewrites() {

View File

@ -166,7 +166,7 @@ export function CommentItem(
<div className="flex-1 pl-2 fade-in-up"> <div className="flex-1 pl-2 fade-in-up">
<div className="flex gap-2 md:gap-4 items-center"> <div className="flex gap-2 md:gap-4 items-center">
<div onClick={() => clickToUserProfile(commentState.user.username)} className="font-bold text-base text-slate-800 dark:text-slate-100 cursor-pointer fade-in-up"> <div onClick={() => clickToUserProfile(commentState.user.username)} className="font-bold text-base text-slate-800 dark:text-slate-100 cursor-pointer fade-in-up">
{commentState.user.nickname} {commentState.user.nickname || commentState.user.username}
</div> </div>
<span className="text-xs">{formatDateTime({ <span className="text-xs">{formatDateTime({
dateTimeString: commentState.createdAt, dateTimeString: commentState.createdAt,