session cookie destroy

This commit is contained in:
Zeni Kim 2024-10-27 10:27:54 -05:00
parent 8141a9eba0
commit 91455fc972
3 changed files with 26 additions and 2 deletions

1
.gitignore vendored
View file

@ -6,3 +6,4 @@ logs/*
tls/*
!tls/.gitkeep
.DS_Store
storage/sqlite/*

View file

@ -425,8 +425,28 @@ func SetNewPassword(c *core.Context) *core.Response {
}
func Signout(c *core.Context) *core.Response {
// check if template engine is enable
TemplateEnableStr := os.Getenv("TEMPLATE_ENABLE")
if TemplateEnableStr == "" {
TemplateEnableStr = "false"
}
TemplateEnable, _ := strconv.ParseBool(TemplateEnableStr)
token := ""
if TemplateEnable {
// get cookie
usercookie, err := c.GetCookie()
if err != nil {
}
token = usercookie.Token
} else {
tokenRaw := c.GetHeader("Authorization")
token := strings.TrimSpace(strings.Replace(tokenRaw, "Bearer", "", 1))
token = strings.TrimSpace(strings.Replace(tokenRaw, "Bearer", "", 1))
}
if token == "" {
return c.Response.SetStatusCode(http.StatusUnauthorized).Json(c.MapToJson(map[string]interface{}{
"message": "unauthorized",

View file

@ -36,6 +36,9 @@ func registerRoutes() {
controller.Get("/dashboard", controllers.WelcomeToDashboard, hooks.AuthCheck)
// templates demos
controller.Get("/signout", controllers.Signout)
controller.Get("/appsample", controllers.AppSample, hooks.AuthCheck)
controller.Post("/appsample", controllers.AppSample, hooks.AuthCheck)