feat: 品牌CMS配置化 + cookie_secure配置

- config.yaml 新增 server.cookie_secure 配置项
- site_settings 新增 site_name/site_tagline/contact_email 站点信息
- SiteInfo 结构体扩展,支持运行时从 DB 读取站点品牌信息
- cookie.go 使用 cfg.Server.CookieSecure 替代 Mode!=debug 判断
- SetSessionCookie/ClearSessionCookie 支持 siteSettings 运行时覆盖
- 模板替换硬编码 MetaLab → {{.SiteName}}(nav/header/footer/home/login/register/guidelines/admin,12+处)
- 管理后台站点设置页新增站点名称/标语/联系邮箱输入项
- 页脚版权年份改为动态 CurrentYear
- 注册成功消息 CMS 化(后端+前端)
This commit is contained in:
2026-06-21 23:12:18 +08:00
parent 7b5856e0ba
commit 0014bdb9ff
21 changed files with 106 additions and 35 deletions

View File

@ -78,7 +78,7 @@ func (ac *AuthController) Login(c *gin.Context) {
return
}
common.SetSessionCookie(c, sid, req.RememberMe, ac.cfg)
common.SetSessionCookie(c, sid, req.RememberMe, ac.cfg, ac.siteSettings)
common.OkWithMessage(c, user, "登录成功")
}
@ -108,6 +108,6 @@ func (ac *AuthController) ConfirmRestore(c *gin.Context) {
return
}
common.SetSessionCookie(c, sid, req.RememberMe, ac.cfg)
common.SetSessionCookie(c, sid, req.RememberMe, ac.cfg, ac.siteSettings)
common.OkWithMessage(c, user, "注销已撤销,欢迎回来")
}

View File

@ -69,9 +69,9 @@ func (ac *AuthController) Register(c *gin.Context) {
return
}
common.SetSessionCookie(c, sid, req.RememberMe, ac.cfg)
common.SetSessionCookie(c, sid, req.RememberMe, ac.cfg, ac.siteSettings)
common.OkWithMessage(c, user, "注册成功!欢迎加入 MetaLab")
common.OkWithMessage(c, user, "注册成功!欢迎加入 "+ac.siteSettings.SiteInfo().SiteName)
}
// Logout 退出登录:删除服务端 session + 清除 Cookie
@ -79,7 +79,7 @@ func (ac *AuthController) Logout(c *gin.Context) {
if sid, err := c.Cookie(common.SessionCookieName); err == nil && sid != "" {
_ = ac.sessionManager.Destroy(sid)
}
common.ClearSessionCookie(c, ac.cfg)
common.ClearSessionCookie(c, ac.cfg, ac.siteSettings)
common.OkMessage(c, "已退出登录")
}
@ -93,7 +93,7 @@ func (ac *AuthController) RefreshToken(c *gin.Context) {
s, err := ac.sessionManager.Validate(sid)
if err != nil || s == nil {
common.ClearSessionCookie(c, ac.cfg)
common.ClearSessionCookie(c, ac.cfg, ac.siteSettings)
common.Error(c, http.StatusUnauthorized, "登录凭证已失效,请重新登录")
return
}

View File

@ -3,6 +3,7 @@ package controller
import (
"html/template"
"net/http"
"strings"
"metazone.cc/mce/internal/common"
"metazone.cc/mce/internal/config"
@ -45,6 +46,12 @@ func (ac *AuthController) RegisterPage(c *gin.Context) {
}
guidelines = content
}
// 替换准则中的硬编码站点名和邮箱
siteInfo := ac.siteSettings.SiteInfo()
guidelines = template.HTML(strings.ReplaceAll(
strings.ReplaceAll(string(guidelines), "MetaLab", siteInfo.SiteName),
"metazone@foxmail.com", siteInfo.ContactEmail,
))
c.HTML(http.StatusOK, "auth/register.html", common.BuildPageData(c, gin.H{
"Title": "注册",
"ExtraCSS": "/static/css/auth.css",