From f955be507a4ad748a60e2bddb487ce589775b5fd Mon Sep 17 00:00:00 2001 From: James Tombleson Date: Sat, 13 Apr 2024 11:51:31 -0700 Subject: [PATCH] updated handlers with the new view folder and testing how to validate jwt and cookies --- handlers/auth.go | 12 ++++++++++-- handlers/home.go | 20 +++++++++++++++----- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/handlers/auth.go b/handlers/auth.go index 29d4c73..5b152a2 100644 --- a/handlers/auth.go +++ b/handlers/auth.go @@ -1,9 +1,10 @@ package handlers import ( + "log" "net/http" - "templ-test/views" "templ-test/views/auth" + "templ-test/views/home" "github.com/labstack/echo/v4" ) @@ -39,10 +40,17 @@ func (h *Handlers) AuthLoginPost(c echo.Context) error { c.SetCookie(cookie) // render - return Render(c, http.StatusOK, views.Home()) + return Render(c, http.StatusOK, home.Home()) } func (h *Handlers) AuthShowCookies(c echo.Context) error { + claims, err := ValidateJwt(c, h.cfg.SharedApiSecret, h.cfg.ApiServerUri) + if err != nil { + return Render(c, http.StatusInternalServerError, home.Error(err)) + } + log.Println(claims) + cookies := GetCookieValues(c) + return Render(c, http.StatusOK, auth.ShowCookie(cookies)) } diff --git a/handlers/home.go b/handlers/home.go index aac02ef..d35c8df 100644 --- a/handlers/home.go +++ b/handlers/home.go @@ -2,15 +2,25 @@ package handlers import ( "net/http" - "templ-test/views" + "templ-test/views/home" "github.com/labstack/echo/v4" ) func (h *Handlers) HomeHandler(c echo.Context) error { - return Render(c, http.StatusOK, views.Home()) + return Render(c, http.StatusOK, home.Home()) } -func (h *Handlers) ListHandler(c echo.Context) error { - return Render(c, http.StatusOK, views.List()) -} \ No newline at end of file +func (h *Handlers) Settings(c echo.Context) error { + return Render(c, http.StatusOK, home.UserSettings()) +} + +func (h *Handlers) SettingsPost(c echo.Context) error { + // take in the updated values from he user and write the cookies... tbd + + return Render(c, http.StatusOK, home.UserSettings()) +} + +//func (h *Handlers) ListHandler(c echo.Context) error { +// return Render(c, http.StatusOK, views.List()) +//}