updated handlers with the new view folder and testing how to validate jwt and cookies

This commit is contained in:
James Tombleson 2024-04-13 11:51:31 -07:00
parent 04acb45c76
commit f955be507a
2 changed files with 25 additions and 7 deletions

View File

@ -1,9 +1,10 @@
package handlers package handlers
import ( import (
"log"
"net/http" "net/http"
"templ-test/views"
"templ-test/views/auth" "templ-test/views/auth"
"templ-test/views/home"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
) )
@ -39,10 +40,17 @@ func (h *Handlers) AuthLoginPost(c echo.Context) error {
c.SetCookie(cookie) c.SetCookie(cookie)
// render // render
return Render(c, http.StatusOK, views.Home()) return Render(c, http.StatusOK, home.Home())
} }
func (h *Handlers) AuthShowCookies(c echo.Context) error { 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) cookies := GetCookieValues(c)
return Render(c, http.StatusOK, auth.ShowCookie(cookies)) return Render(c, http.StatusOK, auth.ShowCookie(cookies))
} }

View File

@ -2,15 +2,25 @@ package handlers
import ( import (
"net/http" "net/http"
"templ-test/views" "templ-test/views/home"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
) )
func (h *Handlers) HomeHandler(c echo.Context) error { 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 { func (h *Handlers) Settings(c echo.Context) error {
return Render(c, http.StatusOK, views.List()) 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())
//}