From 91455fc972e9bd1837739ebf5b6cb9918392ab9b Mon Sep 17 00:00:00 2001 From: Zeni Kim Date: Sun, 27 Oct 2024 10:27:54 -0500 Subject: [PATCH] session cookie destroy --- .gitignore | 1 + controllers/authentication.go | 24 ++++++++++++++++++++++-- routes.go | 3 +++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 8d4682e..84146d5 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ logs/* tls/* !tls/.gitkeep .DS_Store +storage/sqlite/* diff --git a/controllers/authentication.go b/controllers/authentication.go index 25c7b31..9e7e940 100644 --- a/controllers/authentication.go +++ b/controllers/authentication.go @@ -425,8 +425,28 @@ func SetNewPassword(c *core.Context) *core.Response { } func Signout(c *core.Context) *core.Response { - tokenRaw := c.GetHeader("Authorization") - token := strings.TrimSpace(strings.Replace(tokenRaw, "Bearer", "", 1)) + + // 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)) + } + if token == "" { return c.Response.SetStatusCode(http.StatusUnauthorized).Json(c.MapToJson(map[string]interface{}{ "message": "unauthorized", diff --git a/routes.go b/routes.go index 610fbcb..00f1906 100644 --- a/routes.go +++ b/routes.go @@ -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)