Documentation
¶
Index ¶
- Constants
- func Authorize(opt AuthorizeOption) func(*gin.Context)
- func BlockIfNotSuperAdmin(c *gin.Context, isPage bool) bool
- func CSRFMiddleware() gin.HandlerFunc
- func ClearSessionCookies(c *gin.Context)
- func CommonEnvironment(c *gin.Context, data map[string]interface{}) gin.H
- func CookieSecure(c *gin.Context) bool
- func GetPreferredTheme(c *gin.Context, path string) string
- func HashViewPassword(password string) string
- func PreferredTheme(c *gin.Context)
- func RecordPath(c *gin.Context)
- func RequireSuperAdmin() gin.HandlerFunc
- func SafeRedirectPath(c *gin.Context) string
- func SetCSRFCookie(c *gin.Context)
- func ShowErrorPage(c *gin.Context, i ErrInfo, isPage bool)
- func ValidateViewPassword(opt ValidateViewPasswordOption) gin.HandlerFunc
- type AuthorizeOption
- type ErrInfo
- type ValidateViewPasswordOption
Constants ¶
View Source
const ( CSRFCookieName = "nz-csrf" CSRFHeaderName = "X-CSRF-Token" )
Variables ¶
This section is empty.
Functions ¶
func Authorize ¶
func Authorize(opt AuthorizeOption) func(*gin.Context)
func BlockIfNotSuperAdmin ¶ added in v0.20.27
BlockIfNotSuperAdmin 拒绝未登录或非超级管理员,返回 true 表示已拒绝并已写入响应。
func CSRFMiddleware ¶ added in v0.20.26
func CSRFMiddleware() gin.HandlerFunc
CSRFMiddleware CSRF 防护中间件(Double-Submit Cookie 模式) 对基于 Cookie 的 POST/PUT/DELETE/PATCH 请求校验 X-CSRF-Token 头与 CSRF Cookie 是否一致且签名有效
func ClearSessionCookies ¶ added in v0.20.26
ClearSessionCookies 清除认证与 CSRF Cookie
func CookieSecure ¶ added in v0.20.26
CookieSecure 判断当前请求是否经 HTTPS 到达(直连 TLS 或反代 X-Forwarded-Proto)。 纯 HTTP 部署返回 false,不影响 Cookie 读写。
func HashViewPassword ¶ added in v0.20.27
HashViewPassword generates the value stored in the view-password cookie. The process-local salt intentionally invalidates existing cookies on restart.
func PreferredTheme ¶
func RecordPath ¶
func RequireSuperAdmin ¶ added in v0.20.27
func RequireSuperAdmin() gin.HandlerFunc
RequireSuperAdmin 中间件:仅允许超级管理员访问。
func SafeRedirectPath ¶ added in v0.20.25
SafeRedirectPath 从 Referer 解析同站相对路径用于跳转,失败则返回 "/"。
func SetCSRFCookie ¶ added in v0.20.26
SetCSRFCookie 在响应中设置 CSRF cookie(非 HttpOnly,JS 需读取)
func ValidateViewPassword ¶
func ValidateViewPassword(opt ValidateViewPasswordOption) gin.HandlerFunc
Types ¶
type AuthorizeOption ¶
Click to show internal directories.
Click to hide internal directories.