feat: 添加用户注册登录功能,实现数据和配置的用户隔离
- 新增 users 和 user_settings 表,repositories/analyses/review_notes 添加 user_id 列 - 实现基于邮箱+密码的注册登录,密码使用 bcrypt 哈希 - 使用 gin-contrib/sessions cookie-based session 管理 - 所有仓库、分析记录、review notes 按用户隔离 - 用户设置(LLM 配置、review 参数、缓存配置)独立存储 - 新增登录/注册页面,导航栏显示用户邮箱和退出按钮 - 前端 fetch 请求统一添加 credentials: 'same-origin' - 支持 SESSION_SECRET 环境变量配置会话密钥
This commit is contained in:
@@ -22,9 +22,9 @@ type PRDescription struct {
|
||||
|
||||
// GeneratePR generates a structured PR description from commit history and diff.
|
||||
// It streams progress via the callback and returns the parsed PR description.
|
||||
func GeneratePR(db *sql.DB, repoPath, base, head string, callback StreamCallback) (*PRDescription, error) {
|
||||
// Read LLM config
|
||||
config, err := GetLLMConfig(db)
|
||||
func GeneratePR(db *sql.DB, repoPath, base, head string, userID int64, callback StreamCallback) (*PRDescription, error) {
|
||||
// Read LLM config (per-user)
|
||||
config, err := GetLLMConfig(db, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
+3
-3
@@ -17,11 +17,11 @@ type LLMConfig struct {
|
||||
Model string
|
||||
}
|
||||
|
||||
// GetLLMConfig reads LLM settings from the database.
|
||||
func GetLLMConfig(db *sql.DB) (LLMConfig, error) {
|
||||
// GetLLMConfig reads LLM settings from the user_settings table for the given user.
|
||||
func GetLLMConfig(db *sql.DB, userID int64) (LLMConfig, error) {
|
||||
config := LLMConfig{}
|
||||
|
||||
rows, err := db.Query(`SELECT key, value FROM settings WHERE key IN ('llm.endpoint', 'llm.api_key', 'llm.model')`)
|
||||
rows, err := db.Query(`SELECT key, value FROM user_settings WHERE user_id = ? AND key IN ('llm.endpoint', 'llm.api_key', 'llm.model')`, userID)
|
||||
if err != nil {
|
||||
return config, fmt.Errorf("read settings: %w", err)
|
||||
}
|
||||
|
||||
+3
-3
@@ -58,9 +58,9 @@ func countDiffLines(patch string) int {
|
||||
// GenerateReview performs AI code review on diff files with Top-N strategy.
|
||||
// It streams events (file_start, suggestion, file_end, summary, done) via callback
|
||||
// and returns the complete ReviewResult for persistence.
|
||||
func GenerateReview(db *sql.DB, repoPath, base, head string, topN, concurrency int, callback StreamCallback) (*ReviewResult, error) {
|
||||
// Read LLM config
|
||||
config, err := GetLLMConfig(db)
|
||||
func GenerateReview(db *sql.DB, repoPath, base, head string, topN, concurrency int, userID int64, callback StreamCallback) (*ReviewResult, error) {
|
||||
// Read LLM config (per-user)
|
||||
config, err := GetLLMConfig(db, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user