redirect with htmx

format
This commit is contained in:
Ruidy 2024-05-25 18:21:36 +02:00
parent cc621582f9
commit 24b7cf1251
No known key found for this signature in database
GPG key ID: E00F51288CB857CC
6 changed files with 14 additions and 17 deletions

View file

@ -6,7 +6,6 @@ import (
"github.com/labstack/echo-contrib/session" "github.com/labstack/echo-contrib/session"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
"github.com/labstack/gommon/log"
) )
const ( const (
@ -22,7 +21,6 @@ func MakeAuthMiddleware() echo.MiddlewareFunc {
} }
s, err := readSession(c) s, err := readSession(c)
log.Warnf("%=v", s)
if s != "bar" || err != nil { if s != "bar" || err != nil {
return c.Redirect(http.StatusSeeOther, routeLogin) return c.Redirect(http.StatusSeeOther, routeLogin)
} }

View file

@ -41,6 +41,7 @@ func handleLogin(as *auth.Service) echo.HandlerFunc {
if err := sess.Save(c.Request(), c.Response()); err != nil { if err := sess.Save(c.Request(), c.Response()); err != nil {
return err return err
} }
return c.Redirect(http.StatusSeeOther, "/bookings") c.Response().Header().Add("HX-Redirect", "/bookings")
return c.NoContent(200)
} }
} }

View file

@ -12,7 +12,7 @@ templ BaseLayout() {
<link rel="stylesheet" href="/static/css/pico.min.css"/> <link rel="stylesheet" href="/static/css/pico.min.css"/>
<script src="/static/js/htmx.js" defer></script> <script src="/static/js/htmx.js" defer></script>
</head> </head>
<body hx-boost="true"> <body hx-boost="true" style="display: flex; flex-direction: column; height: 100%;">
<nav class="container-fluid"> <nav class="container-fluid">
<ul> <ul>
<li><a href="/"><b>🏨 RentEase </b> </a></li> <li><a href="/"><b>🏨 RentEase </b> </a></li>
@ -23,7 +23,7 @@ templ BaseLayout() {
<li><a href="/bookings/new" role="button">New Booking</a></li> <li><a href="/bookings/new" role="button">New Booking</a></li>
</ul> </ul>
</nav> </nav>
<main class="container"> <main class="container" style="flex: 1 0 auto;">
{ children... } { children... }
</main> </main>
<footer class="container-fluid">🏨 RentEase &copy 2024</footer> <footer class="container-fluid">🏨 RentEase &copy 2024</footer>

View file

@ -23,7 +23,7 @@ func BaseLayout() templ.Component {
templ_7745c5c3_Var1 = templ.NopComponent templ_7745c5c3_Var1 = templ.NopComponent
} }
ctx = templ.ClearChildren(ctx) ctx = templ.ClearChildren(ctx)
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<!doctype html><html lang=\"en\"><head><title>RentEase | Your Property Management System</title><meta charset=\"UTF-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"><meta name=\"description\" content=\"AI assistant to help you improve your management\"><link rel=\"icon\" href=\"/static/icons/favicon-main.png\"><link rel=\"stylesheet\" href=\"/static/css/pico.min.css\"><script src=\"/static/js/htmx.js\" defer></script></head><body hx-boost=\"true\"><nav class=\"container-fluid\"><ul><li><a href=\"/\"><b>🏨 RentEase </b></a></li></ul><ul><li><a href=\"/bookings\">Bookings</a></li><li><a href=\"/reports\">Reports</a></li><li><a href=\"/bookings/new\" role=\"button\">New Booking</a></li></ul></nav><main class=\"container\">") _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<!doctype html><html lang=\"en\"><head><title>RentEase | Your Property Management System</title><meta charset=\"UTF-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"><meta name=\"description\" content=\"AI assistant to help you improve your management\"><link rel=\"icon\" href=\"/static/icons/favicon-main.png\"><link rel=\"stylesheet\" href=\"/static/css/pico.min.css\"><script src=\"/static/js/htmx.js\" defer></script></head><body hx-boost=\"true\" style=\"display: flex; flex-direction: column; height: 100%;\"><nav class=\"container-fluid\"><ul><li><a href=\"/\"><b>🏨 RentEase </b></a></li></ul><ul><li><a href=\"/bookings\">Bookings</a></li><li><a href=\"/reports\">Reports</a></li><li><a href=\"/bookings/new\" role=\"button\">New Booking</a></li></ul></nav><main class=\"container\" style=\"flex: 1 0 auto;\">")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }

View file

@ -6,15 +6,13 @@ import (
templ Login() { templ Login() {
@layout.BaseLayout() { @layout.BaseLayout() {
<main class="container"> <section>
<section> <h1>Welcome</h1>
<h1>Welcome</h1> <form hx-post="/">
<form method="POST"> <input type="email" name="email" placeholder="john@email.com" aria-label="email" autocomplete="email" autofocus required=""/>
<input type="email" name="email" placeholder="john@email.com" aria-label="email" autocomplete="email" autofocus required=""/> <input type="password" name="password" placeholder="p4Ssw0rD" aria-label="password" autocomplete="password" required=""/>
<input type="password" name="password" placeholder="p4Ssw0rD" aria-label="password" autocomplete="password" required=""/> <button type="submit">Log in</button>
<button type="submit">Log in</button> </form>
</form> </section>
</section>
</main>
} }
} }

View file

@ -33,7 +33,7 @@ func Login() templ.Component {
templ_7745c5c3_Buffer = templ.GetBuffer() templ_7745c5c3_Buffer = templ.GetBuffer()
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) defer templ.ReleaseBuffer(templ_7745c5c3_Buffer)
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<main class=\"container\"><section><h1>Welcome</h1><form method=\"POST\"><input type=\"email\" name=\"email\" placeholder=\"john@email.com\" aria-label=\"email\" autocomplete=\"email\" autofocus required=\"\"> <input type=\"password\" name=\"password\" placeholder=\"p4Ssw0rD\" aria-label=\"password\" autocomplete=\"password\" required=\"\"> <button type=\"submit\">Log in</button></form></section></main>") _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<section><h1>Welcome</h1><form hx-post=\"/\"><input type=\"email\" name=\"email\" placeholder=\"john@email.com\" aria-label=\"email\" autocomplete=\"email\" autofocus required=\"\"> <input type=\"password\" name=\"password\" placeholder=\"p4Ssw0rD\" aria-label=\"password\" autocomplete=\"password\" required=\"\"> <button type=\"submit\">Log in</button></form></section>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }