- 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 化(后端+前端)
37 lines
900 B
Go
37 lines
900 B
Go
package middleware
|
|
|
|
import (
|
|
"log"
|
|
"net/http"
|
|
|
|
"metazone.cc/mce/internal/common"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// AdminAuth 管理后台页面认证:失败时 302 跳首页而非返回 JSON
|
|
func (am *AuthMiddleware) AdminAuth() gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
sid, err := c.Cookie(common.SessionCookieName)
|
|
if err != nil || sid == "" {
|
|
common.ClearSessionCookie(c, am.cfg, am.siteSettings)
|
|
c.Redirect(http.StatusFound, "/")
|
|
c.Abort()
|
|
return
|
|
}
|
|
|
|
s, err := am.sessionManager.Validate(sid)
|
|
if err != nil || s == nil {
|
|
log.Printf("[AdminAuth] session invalid path=%s → 302", c.Request.URL.Path)
|
|
common.ClearSessionCookie(c, am.cfg, am.siteSettings)
|
|
c.Redirect(http.StatusFound, "/")
|
|
c.Abort()
|
|
return
|
|
}
|
|
|
|
log.Printf("[AdminAuth] OK uid=%d role=%s path=%s", s.UserID, s.Role, c.Request.URL.Path)
|
|
injectSessionContext(c, s)
|
|
c.Next()
|
|
}
|
|
}
|