feat: apply user settings to effect

This commit is contained in:
engigu
2025-12-20 13:30:08 +08:00
parent 07d988cc7e
commit a4d73a6f89
17 changed files with 168 additions and 111 deletions
+8 -7
View File
@@ -4,21 +4,22 @@ import (
"crypto/sha256"
"encoding/hex"
"baihu/internal/constant"
"baihu/internal/database"
"baihu/internal/models"
)
type UserService struct{}
type UserService struct {
settingsService *SettingsService
}
func NewUserService() *UserService {
return &UserService{}
func NewUserService(settingsService *SettingsService) *UserService {
return &UserService{settingsService: settingsService}
}
func (us *UserService) hashPassword(password string) string {
salt := ""
if Config != nil {
salt = Config.Security.PasswordSalt
}
// 使用 JWT Secret 作为密码 salt
salt := us.settingsService.Get(constant.SectionSystem, constant.KeyJWTSecret)
hash := sha256.Sum256([]byte(password + salt))
return hex.EncodeToString(hash[:])
}