Compare commits
5 Commits
6cfc53901e
...
fe4293b02f
Author | SHA1 | Date | |
---|---|---|---|
fe4293b02f | |||
a110f2de73 | |||
9dbd8e0e00 | |||
2086ff3547 | |||
cda43e8ae2 |
@ -41,7 +41,7 @@ func (h *Handlers) AuthLoginPost(c echo.Context) error {
|
|||||||
c.SetCookie(cookie)
|
c.SetCookie(cookie)
|
||||||
|
|
||||||
// render
|
// render
|
||||||
return Render(c, http.StatusOK, home.Home())
|
return Render(c, http.StatusOK, auth.LoginPost())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handlers) AuthShowCookies(c echo.Context) error {
|
func (h *Handlers) AuthShowCookies(c echo.Context) error {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package handlers
|
package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"templ-test/client"
|
"templ-test/client"
|
||||||
"templ-test/domain"
|
"templ-test/domain"
|
||||||
@ -43,7 +44,16 @@ func (h *Handlers) Register(group echo.Group) {
|
|||||||
func Render(ctx echo.Context, statusCode int, t templ.Component) error {
|
func Render(ctx echo.Context, statusCode int, t templ.Component) error {
|
||||||
ctx.Response().Writer.WriteHeader(statusCode)
|
ctx.Response().Writer.WriteHeader(statusCode)
|
||||||
ctx.Response().Header().Set(echo.HeaderContentType, echo.MIMETextHTML)
|
ctx.Response().Header().Set(echo.HeaderContentType, echo.MIMETextHTML)
|
||||||
return t.Render(ctx.Request().Context(), ctx.Response().Writer)
|
|
||||||
|
// take the request context and make it a var
|
||||||
|
request := ctx.Request().Context()
|
||||||
|
//Check to see if we the echo context has the cookie we are looking for, if so, create a new context based on what we had and add the value
|
||||||
|
darkMode, err := ctx.Cookie(domain.CookieSettingsDarkMode)
|
||||||
|
if err == nil {
|
||||||
|
request = context.WithValue(request, domain.CookieSettingsDarkMode, darkMode.Value)
|
||||||
|
}
|
||||||
|
|
||||||
|
return t.Render(request, ctx.Response().Writer)
|
||||||
}
|
}
|
||||||
|
|
||||||
type jwtToken struct {
|
type jwtToken struct {
|
||||||
@ -101,5 +111,10 @@ func GetCookieValues(ctx echo.Context) models.AllCookies {
|
|||||||
m.RefreshToken = refresh.Value
|
m.RefreshToken = refresh.Value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
darkMode, err := ctx.Cookie(domain.CookieSettingsDarkMode)
|
||||||
|
if err == nil {
|
||||||
|
m.DarkMode = darkMode.Value
|
||||||
|
}
|
||||||
|
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,3 @@ func (h *Handlers) SettingsPost(c echo.Context) error {
|
|||||||
|
|
||||||
return Render(c, http.StatusOK, home.SettingsUpdated())
|
return Render(c, http.StatusOK, home.SettingsUpdated())
|
||||||
}
|
}
|
||||||
|
|
||||||
//func (h *Handlers) ListHandler(c echo.Context) error {
|
|
||||||
// return Render(c, http.StatusOK, views.List())
|
|
||||||
//}
|
|
||||||
|
@ -4,6 +4,7 @@ type AllCookies struct {
|
|||||||
Username string
|
Username string
|
||||||
Token string
|
Token string
|
||||||
RefreshToken string
|
RefreshToken string
|
||||||
|
DarkMode string
|
||||||
}
|
}
|
||||||
|
|
||||||
type ShowCookie struct {
|
type ShowCookie struct {
|
||||||
|
@ -6,8 +6,11 @@ import "templ-test/views/layout"
|
|||||||
templ ShowCookie(m models.AllCookies) {
|
templ ShowCookie(m models.AllCookies) {
|
||||||
@layout.WithLayout("Cookie Explorer") {
|
@layout.WithLayout("Cookie Explorer") {
|
||||||
<h2>These are stored as cookies</h2>
|
<h2>These are stored as cookies</h2>
|
||||||
|
<h3>JWT Values</h3>
|
||||||
<p>Username: { m.Username }</p>
|
<p>Username: { m.Username }</p>
|
||||||
<p>JWT Token: { m.Token }</p>
|
<p>JWT Token: { m.Token }</p>
|
||||||
<p>RefreshToken: { m.RefreshToken }</p>
|
<p>RefreshToken: { m.RefreshToken }</p>
|
||||||
|
<h3>User Settings</h3>
|
||||||
|
<p>DarkMode: { m.DarkMode }</p>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
7
views/auth/loginPost.templ
Normal file
7
views/auth/loginPost.templ
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package auth
|
||||||
|
|
||||||
|
import "templ-test/views/components/bootstrap"
|
||||||
|
|
||||||
|
templ LoginPost() {
|
||||||
|
@bootstrap.BootstrapAlert("Login successful!", bootstrap.VariantSuccess)
|
||||||
|
}
|
@ -1,9 +1,5 @@
|
|||||||
package home
|
package home
|
||||||
|
|
||||||
import "templ-test/views/layout"
|
|
||||||
|
|
||||||
templ SettingsUpdated() {
|
templ SettingsUpdated() {
|
||||||
@layout.WithLayout("Settings Updated") {
|
|
||||||
<p>You are now free to move about the cabin. Thank you for saving with us!</p>
|
<p>You are now free to move about the cabin. Thank you for saving with us!</p>
|
||||||
}
|
}
|
||||||
}
|
|
@ -1,20 +1,8 @@
|
|||||||
package layout
|
package layout
|
||||||
|
|
||||||
templ WithLayout(pageName string) {
|
templ WithLayout(pageName string) {
|
||||||
<html>
|
<!doctype html>
|
||||||
@getHtmlHead()
|
<html lang="en" data-bs-theme={ useLightOrDarkTheme(ctx) }>
|
||||||
<body>
|
|
||||||
@bootstrapNavBar()
|
|
||||||
@getBodyHeader(pageName)
|
|
||||||
<div class="container-fluid">
|
|
||||||
{ children... }
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
}
|
|
||||||
|
|
||||||
templ Testing(pageName string) {
|
|
||||||
<html>
|
|
||||||
@getHtmlHead()
|
@getHtmlHead()
|
||||||
<body>
|
<body>
|
||||||
@bootstrapNavBar()
|
@bootstrapNavBar()
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package layout
|
package layout
|
||||||
|
|
||||||
templ bootstrapNavBar() {
|
templ bootstrapNavBar() {
|
||||||
<nav class="navbar navbar-expand-lg bg-body-tertiary" data-bs-theme={ useLightOrDarkTheme(ctx)}>
|
<nav class="navbar navbar-expand-lg bg-body-tertiary">
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<a class="navbar-brand" href="#">Navbar</a>
|
<a class="navbar-brand" href="#">Navbar</a>
|
||||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
|
||||||
|
@ -6,8 +6,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func useLightOrDarkTheme(ctx context.Context) string {
|
func useLightOrDarkTheme(ctx context.Context) string {
|
||||||
cookie := ctx.Value(domain.CookieSettingsDarkMode)
|
value := ctx.Value(domain.CookieSettingsDarkMode)
|
||||||
if cookie == "on" {
|
if value == "on" {
|
||||||
return "dark"
|
return "dark"
|
||||||
} else {
|
} else {
|
||||||
return "light"
|
return "light"
|
||||||
|
Loading…
Reference in New Issue
Block a user