backup/http.go

66 lines
1.3 KiB
Go
Raw Normal View History

2023-08-20 16:57:53 +02:00
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) {
}
}
2024-11-17 17:26:16 +01:00
func HttpAnySignIn(c *gin.Context) {
2023-08-20 16:57:53 +02:00
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,
})
}
2024-11-17 15:14:36 +01:00
}
func HttpGetRecover(c *gin.Context) {
2023-08-20 16:57:53 +02:00
}
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{})
}
}
2024-11-17 15:14:36 +01:00
func GetWebSessionUserID(c *gin.Context) uint64 {
2023-08-20 16:57:53 +02:00
return 0
}
func SetCSRFToken(c *gin.Context) {
}