package main import ( "net/http" "github.com/gin-gonic/gin" ) func HttpAuth() gin.HandlerFunc { return func(c *gin.Context) { // Search signed-in userID userID := 0 if userID == 0 { // Return 404 and abort handlers chain. c.String(http.StatusNotFound, "404 page not found") c.AbortWithStatus(http.StatusNotFound) } } } func HttpNoAuth() gin.HandlerFunc { return func(c *gin.Context) { } } func HttpAnySignIn(c *gin.Context) { if GetWebSessionUserID(c) > 0 { c.Redirect(http.StatusTemporaryRedirect, "/p/home") } else { SetCSRFToken(c) warning, _ := c.Cookie("warning") c.SetCookie("warning", "", -1, "/", cfg.Admin.Addr, false, true) c.HTML(http.StatusOK, "page-signin.html", gin.H{ "Error": warning, }) } } func HttpGetRecover(c *gin.Context) { c.HTML(http.StatusOK, "page-recover.html", gin.H{}) } func HttpAnyIndex(c *gin.Context) { if GetWebSessionUserID(c) > 0 { c.Redirect(http.StatusTemporaryRedirect, "/p/home") } else { c.Redirect(http.StatusTemporaryRedirect, "/u/signin") } } func HttpAnyHome(c *gin.Context) { if GetWebSessionUserID(c) == 0 { c.Redirect(http.StatusTemporaryRedirect, "/u/signin") } else { SetCSRFToken(c) c.HTML(http.StatusOK, "page-home.html", gin.H{}) } } func GetWebSessionUserID(c *gin.Context) uint64 { return 0 } func SetCSRFToken(c *gin.Context) { }