feat: 注册准则阅读控制 + Footer 合规信息
准则阅读(三层控制): - registration.show_guidelines — 弹窗/复选框模式 - registration.force_guidelines — 是否强制倒计时+滚动 - registration.guidelines_timer — 倒计时秒数 Footer 合规(8 字段,空值不显示,链接纯手写): - site.operator_name / site.icp_number / site.icp_license - site.police_number / site.wenwangwen / site.algorithm_filing - site.privacy_url / site.terms_url - 新增 safeHTML 模板函数输出不转义 HTML
This commit is contained in:
@ -175,5 +175,32 @@ func injectSiteInfo(c *gin.Context, data gin.H) {
|
||||
if copyrightStart, exists := c.Get("site_copyright_start"); exists {
|
||||
data["CopyrightStart"] = copyrightStart
|
||||
}
|
||||
if operatorName, exists := c.Get("site_operator_name"); exists {
|
||||
data["OperatorName"] = operatorName
|
||||
}
|
||||
if icpNumber, exists := c.Get("site_icp_number"); exists {
|
||||
data["ICPNumber"] = icpNumber
|
||||
}
|
||||
if icpLicense, exists := c.Get("site_icp_license"); exists {
|
||||
data["ICPLicense"] = icpLicense
|
||||
}
|
||||
if policeNumber, exists := c.Get("site_police_number"); exists {
|
||||
data["PoliceNumber"] = policeNumber
|
||||
}
|
||||
if wenwangwen, exists := c.Get("site_wenwangwen"); exists {
|
||||
data["WenWangWen"] = wenwangwen
|
||||
}
|
||||
if algorithmFiling, exists := c.Get("site_algorithm_filing"); exists {
|
||||
data["AlgorithmFiling"] = algorithmFiling
|
||||
}
|
||||
if privacyURL, exists := c.Get("site_privacy_url"); exists {
|
||||
data["PrivacyURL"] = privacyURL
|
||||
}
|
||||
if termsURL, exists := c.Get("site_terms_url"); exists {
|
||||
data["TermsURL"] = termsURL
|
||||
}
|
||||
if guidelinesTimer, exists := c.Get("registration_guidelines_timer"); exists {
|
||||
data["GuidelinesTimer"] = guidelinesTimer
|
||||
}
|
||||
data["CurrentYear"] = time.Now().Year()
|
||||
}
|
||||
|
||||
@ -117,16 +117,32 @@ type SiteInfoDefaults struct {
|
||||
ContactEmail string // 联系/申诉邮箱,默认 "metazone@foxmail.com"
|
||||
Framework string // 附加标识,默认 "Framework: MetaGenesis"
|
||||
CopyrightStart string // 版权起始年份,默认 "2024"
|
||||
OperatorName string // 运营主体
|
||||
ICPNumber string // ICP 备案(HTML,含链接)
|
||||
ICPLicense string // ICP 经营许可证(HTML)
|
||||
PoliceNumber string // 公安备案(HTML)
|
||||
WenWangWen string // 文网文(HTML)
|
||||
AlgorithmFiling string // 算法备案(HTML)
|
||||
PrivacyURL string // 隐私政策(HTML)
|
||||
TermsURL string // 服务条款(HTML)
|
||||
}
|
||||
|
||||
// SiteInfo 获取站点展示信息(优先 DB 设置,fallback 默认值)
|
||||
func (s *SiteSettings) SiteInfo() SiteInfoDefaults {
|
||||
return SiteInfoDefaults{
|
||||
SiteName: s.Get("site.name", "MetaLab"),
|
||||
SiteTagline: s.Get("site.tagline", "下一代开发者社区"),
|
||||
ContactEmail: s.Get("site.contact_email", "metazone@foxmail.com"),
|
||||
Framework: s.Get("site.framework", "Framework: MetaGenesis"),
|
||||
CopyrightStart: s.Get("site.copyright_start", "2024"),
|
||||
SiteName: s.Get("site.name", "MetaLab"),
|
||||
SiteTagline: s.Get("site.tagline", "下一代开发者社区"),
|
||||
ContactEmail: s.Get("site.contact_email", "metazone@foxmail.com"),
|
||||
Framework: s.Get("site.framework", "Framework: MetaGenesis"),
|
||||
CopyrightStart: s.Get("site.copyright_start", "2024"),
|
||||
OperatorName: s.Get("site.operator_name", ""),
|
||||
ICPNumber: s.Get("site.icp_number", ""),
|
||||
ICPLicense: s.Get("site.icp_license", ""),
|
||||
PoliceNumber: s.Get("site.police_number", ""),
|
||||
WenWangWen: s.Get("site.wenwangwen", ""),
|
||||
AlgorithmFiling: s.Get("site.algorithm_filing", ""),
|
||||
PrivacyURL: s.Get("site.privacy_url", ""),
|
||||
TermsURL: s.Get("site.terms_url", ""),
|
||||
}
|
||||
}
|
||||
|
||||
@ -140,6 +156,26 @@ func (s *SiteSettings) IsRegistrationEnabled() bool {
|
||||
return s.GetBool("registration.enabled", true)
|
||||
}
|
||||
|
||||
// ShowGuidelinesModal 注册时是否弹窗显示社区准则
|
||||
func (s *SiteSettings) ShowGuidelinesModal() bool {
|
||||
return s.GetBool("registration.show_guidelines", true)
|
||||
}
|
||||
|
||||
// ForceGuidelines 是否强制阅读准则(需要倒计时+滚动到底部)
|
||||
func (s *SiteSettings) ForceGuidelines() bool {
|
||||
return s.GetBool("registration.force_guidelines", true)
|
||||
}
|
||||
|
||||
// GuidelinesTimer 强制阅读倒计时秒数
|
||||
func (s *SiteSettings) GuidelinesTimer() int {
|
||||
val := s.Get("registration.guidelines_timer", "60")
|
||||
n, err := strconv.Atoi(val)
|
||||
if err != nil || n < 1 {
|
||||
return 60
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
// IsMaintenanceEnabled 是否处于维护模式(维护期间仅站长可登录和访问)
|
||||
func (s *SiteSettings) IsMaintenanceEnabled() bool {
|
||||
return s.GetBool("maintenance.enabled", false)
|
||||
|
||||
@ -57,6 +57,9 @@ func (ac *AuthController) RegisterPage(c *gin.Context) {
|
||||
"ExtraCSS": "/static/css/auth.css",
|
||||
"Guidelines": guidelines,
|
||||
"RegistrationEnabled": ac.authService.IsRegistrationEnabled(),
|
||||
"ShowGuidelinesModal": ac.siteSettings.ShowGuidelinesModal(),
|
||||
"ForceGuidelines": ac.siteSettings.ForceGuidelines(),
|
||||
"GuidelinesTimer": ac.siteSettings.GuidelinesTimer(),
|
||||
}))
|
||||
}
|
||||
|
||||
|
||||
@ -16,7 +16,16 @@ func InjectSiteInfo(siteSettings *config.SiteSettings) gin.HandlerFunc {
|
||||
c.Set("site_contact_email", info.ContactEmail)
|
||||
c.Set("site_framework", info.Framework)
|
||||
c.Set("site_copyright_start", info.CopyrightStart)
|
||||
c.Set("site_operator_name", info.OperatorName)
|
||||
c.Set("site_icp_number", info.ICPNumber)
|
||||
c.Set("site_icp_license", info.ICPLicense)
|
||||
c.Set("site_police_number", info.PoliceNumber)
|
||||
c.Set("site_wenwangwen", info.WenWangWen)
|
||||
c.Set("site_algorithm_filing", info.AlgorithmFiling)
|
||||
c.Set("site_privacy_url", info.PrivacyURL)
|
||||
c.Set("site_terms_url", info.TermsURL)
|
||||
c.Set("is_maintenance", siteSettings.IsMaintenanceEnabled())
|
||||
c.Set("registration_guidelines_timer", siteSettings.GuidelinesTimer())
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
|
||||
@ -26,6 +26,7 @@ func LoadTemplates(roots ...TemplateRoot) (*template.Template, error) {
|
||||
"formatCount": formatCount,
|
||||
"str": str,
|
||||
"assetV": common.AssetV,
|
||||
"safeHTML": func(s string) template.HTML { return template.HTML(s) },
|
||||
"substr": func(s string, start, length int) string {
|
||||
runes := []rune(s)
|
||||
if start >= len(runes) {
|
||||
|
||||
Reference in New Issue
Block a user