Login page using templ

This commit is contained in:
Ruidy 2024-05-19 21:29:23 +02:00
parent 0924417a81
commit 37c5c9428e
No known key found for this signature in database
GPG key ID: E00F51288CB857CC
5 changed files with 14 additions and 29 deletions

View file

@ -9,6 +9,7 @@ import (
"github.com/markbates/goth/gothic"
"github.com/rjNemo/rentease/internal/auth"
"github.com/rjNemo/rentease/internal/view"
)
var indexTemplate = `{{range $key,$value:=.Providers}}
@ -71,8 +72,6 @@ func handleProvider() echo.HandlerFunc {
func handleLoginPage(as *auth.Service) echo.HandlerFunc {
return func(c echo.Context) error {
t, _ := template.New("foo").Parse(indexTemplate)
return t.Execute(c.Response(), as.GetProviderIndex())
//return renderTempl(c, http.StatusOK, view.Login(as.GetProviderIndex()))
return renderTempl(c, http.StatusOK, view.Login(as.GetProviderIndex()))
}
}

View file

@ -48,7 +48,7 @@ templ PublicLayout() {
<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="false">
<nav class="container-fluid">
<ul>
<li>

View file

@ -72,7 +72,7 @@ func PublicLayout() templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" | Locations de vacances au Gosier en Guadeloupe</title><meta charset=\"UTF-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"><meta name=\"description\" content=\"Locations de vacances au Gosier en Guadeloupe\"><link rel=\"icon\" href=\"/static/icons/favicon.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=\"/\"><img src=\"/static/img/logo.png\" alt=\"logo de villafleurie\" width=\"50px\"></a></li></ul><ul><li><details class=\"dropdown\"><summary>Logements</summary><ul dir=\"rtl\">")
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" | Locations de vacances au Gosier en Guadeloupe</title><meta charset=\"UTF-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"><meta name=\"description\" content=\"Locations de vacances au Gosier en Guadeloupe\"><link rel=\"icon\" href=\"/static/icons/favicon.png\"><link rel=\"stylesheet\" href=\"/static/css/pico.min.css\"><script src=\"/static/js/htmx.js\" defer></script></head><body hx-boost=\"false\"><nav class=\"container-fluid\"><ul><li><a href=\"/\"><img src=\"/static/img/logo.png\" alt=\"logo de villafleurie\" width=\"50px\"></a></li></ul><ul><li><details class=\"dropdown\"><summary>Logements</summary><ul dir=\"rtl\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}

View file

@ -1,33 +1,17 @@
package view
import (
"github.com/rjNemo/rentease/internal/auth"
"github.com/rjNemo/rentease/internal/view/layout"
)
templ Login() {
@layout.BaseLayout() {
// inject the providers into the template even if we don't use it
templ Login(providers *auth.ProviderIndex) {
@layout.PublicLayout() {
<main class="container">
<section>
<h1>Login</h1>
<form method="POST">
<input
type="email"
name="email"
placeholder="john@email.com"
aria-label="email"
autocomplete="email"
required
/>
<input
type="password"
name="password"
placeholder="p4Ssw0rD"
aria-label="password"
autocomplete="password"
required
/>
<button type="submit">Log in</button>
</form>
<a href="/auth?provider=google">Log in with Google</a>
</section>
</main>
}

View file

@ -11,10 +11,12 @@ import "io"
import "bytes"
import (
"github.com/rjNemo/rentease/internal/auth"
"github.com/rjNemo/rentease/internal/view/layout"
)
func Login() templ.Component {
// inject the providers into the template even if we don't use it
func Login(providers *auth.ProviderIndex) templ.Component {
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) {
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)
if !templ_7745c5c3_IsBuffer {
@ -33,7 +35,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>Login</h1><form method=\"POST\"><input type=\"email\" name=\"email\" placeholder=\"john@email.com\" aria-label=\"email\" autocomplete=\"email\" 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("<main class=\"container\"><section><h1>Login</h1><a href=\"/auth?provider=google\">Log in with Google</a></section></main>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@ -42,7 +44,7 @@ func Login() templ.Component {
}
return templ_7745c5c3_Err
})
templ_7745c5c3_Err = layout.BaseLayout().Render(templ.WithChildren(ctx, templ_7745c5c3_Var2), templ_7745c5c3_Buffer)
templ_7745c5c3_Err = layout.PublicLayout().Render(templ.WithChildren(ctx, templ_7745c5c3_Var2), templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}