feat(admin): 站点信息 + 注册开关可后台设置,模板动态渲染
新增 4 项可配置站点设置(DB持久化+内存缓存,即时生效): - site.brand 品牌名(页面标题/页脚/管理面板,默认 MetaLab) - site.framework 框架名(页脚标识,默认 MetaZone) - site.copyright_start 版权起始年(页脚,默认 2024) - registration.enabled 注册开关(关闭后禁止新用户注册,默认 true) 实现方式: - InjectSiteInfo 中间件:全局注入 Brand/Framework/CopyrightStart 到 gin.Context - BuildPageData 读取 context,所有 SSR 页面自动获取站点信息 - AuthService.Register 最先检查 IsRegistrationEnabled() - 管理后台新增「基本设置」+「注册设置」区块,文本输入手动保存 + Toggle 即时生效
This commit is contained in:
@ -18,11 +18,12 @@ type AuthService struct {
|
||||
userRepo userAuthStore
|
||||
tokenService tokenProvider
|
||||
cfg *config.Config
|
||||
siteSettings *config.SiteSettings
|
||||
}
|
||||
|
||||
// NewAuthService 构造函数
|
||||
func NewAuthService(userRepo userAuthStore, tokenSvc tokenProvider, cfg *config.Config) *AuthService {
|
||||
return &AuthService{userRepo: userRepo, tokenService: tokenSvc, cfg: cfg}
|
||||
func NewAuthService(userRepo userAuthStore, tokenSvc tokenProvider, cfg *config.Config, siteSettings *config.SiteSettings) *AuthService {
|
||||
return &AuthService{userRepo: userRepo, tokenService: tokenSvc, cfg: cfg, siteSettings: siteSettings}
|
||||
}
|
||||
|
||||
var pwLetter = regexp.MustCompile(`[a-zA-Z]`)
|
||||
@ -56,6 +57,11 @@ func validatePassword(pw string) error {
|
||||
// rememberMe=true: refresh Cookie 持久化(30天);false: session cookie(关浏览器即清除)
|
||||
// regIP: 注册 IP 地址
|
||||
func (s *AuthService) Register(req model.RegisterRequest, regIP string) (string, string, *model.User, error) {
|
||||
// 0. 检查注册开关
|
||||
if !s.siteSettings.IsRegistrationEnabled() {
|
||||
return "", "", nil, common.ErrRegistrationDisabled
|
||||
}
|
||||
|
||||
// 1. 密码强度
|
||||
if err := validatePassword(req.Password); err != nil {
|
||||
return "", "", nil, err
|
||||
|
||||
Reference in New Issue
Block a user