mirror of
https://github.com/rjNemo/rentease.git
synced 2026-06-06 02:36:49 +00:00
redirect with htmx
format
This commit is contained in:
parent
cc621582f9
commit
24b7cf1251
6 changed files with 14 additions and 17 deletions
|
|
@ -6,7 +6,6 @@ import (
|
|||
|
||||
"github.com/labstack/echo-contrib/session"
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/labstack/gommon/log"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -22,7 +21,6 @@ func MakeAuthMiddleware() echo.MiddlewareFunc {
|
|||
}
|
||||
|
||||
s, err := readSession(c)
|
||||
log.Warnf("%=v", s)
|
||||
if s != "bar" || err != nil {
|
||||
return c.Redirect(http.StatusSeeOther, routeLogin)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ func handleLogin(as *auth.Service) echo.HandlerFunc {
|
|||
if err := sess.Save(c.Request(), c.Response()); err != nil {
|
||||
return err
|
||||
}
|
||||
return c.Redirect(http.StatusSeeOther, "/bookings")
|
||||
c.Response().Header().Add("HX-Redirect", "/bookings")
|
||||
return c.NoContent(200)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ templ BaseLayout() {
|
|||
<link rel="stylesheet" href="/static/css/pico.min.css"/>
|
||||
<script src="/static/js/htmx.js" defer></script>
|
||||
</head>
|
||||
<body hx-boost="true">
|
||||
<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>
|
||||
|
|
@ -23,7 +23,7 @@ templ BaseLayout() {
|
|||
<li><a href="/bookings/new" role="button">New Booking</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
<main class="container">
|
||||
<main class="container" style="flex: 1 0 auto;">
|
||||
{ children... }
|
||||
</main>
|
||||
<footer class="container-fluid">🏨 RentEase © 2024</footer>
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ func BaseLayout() templ.Component {
|
|||
templ_7745c5c3_Var1 = templ.NopComponent
|
||||
}
|
||||
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 {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,15 +6,13 @@ import (
|
|||
|
||||
templ Login() {
|
||||
@layout.BaseLayout() {
|
||||
<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>
|
||||
<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>
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ func Login() templ.Component {
|
|||
templ_7745c5c3_Buffer = templ.GetBuffer()
|
||||
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 {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue