responsive forms
Marco Andronaco andronacomarco@gmail.com
Sun, 13 Oct 2024 00:14:11 +0200
8 files changed,
45 insertions(+),
42 deletions(-)
M
src/app/handlers.go
→
src/app/handlers.go
@@ -16,20 +16,20 @@ xt.ExecuteTemplate(w, "example.tmpl", map[string]interface{}{"User": user})
} func getRegisterHandler(w http.ResponseWriter, r *http.Request) { - xt.ExecuteTemplate(w, "register.tmpl", nil) + xt.ExecuteTemplate(w, "auth-register.tmpl", nil) } func getLoginHandler(w http.ResponseWriter, r *http.Request) { _, err := readSessionCookie(r) if err != nil { - xt.ExecuteTemplate(w, "login.tmpl", nil) + xt.ExecuteTemplate(w, "auth-login.tmpl", nil) return } http.Redirect(w, r, "/", http.StatusFound) } func getResetPasswordHandler(w http.ResponseWriter, r *http.Request) { - xt.ExecuteTemplate(w, "reset_password.tmpl", nil) + xt.ExecuteTemplate(w, "auth-reset_password.tmpl", nil) } func postRegisterHandler(w http.ResponseWriter, r *http.Request) {@@ -132,7 +132,7 @@ http.Error(w, "Token is invalid or expired.", http.StatusUnauthorized)
return } - xt.ExecuteTemplate(w, "new_password.tmpl", nil) + xt.ExecuteTemplate(w, "auth-new_password.tmpl", nil) } func postResetPasswordConfirmHandler(w http.ResponseWriter, r *http.Request) {
M
static/style.css
→
static/style.css
@@ -1,19 +1,13 @@
-form { - width: 400px; -} - label { - display: flex; - flex-direction: row; - justify-content: flex-end; + display: grid; + grid-template-columns: auto auto; + align-items: center; + justify-items: start; + align-content: center; + justify-content: space-between; + max-width: 350px; } label > input { - flex: 0 0 200px; - margin-left: 20px; + max-width: 250px; } - -input[type=checkbox] { - flex: unset; -} -
A
templates/auth.tmpl
@@ -0,0 +1,9 @@
+{{ extends "base.tmpl" }} + +{{define "content" -}} +<center> +{{block "auth" .}} + <h1>Auth template</h1> +{{end}} +</center> +{{end}}
M
templates/base.tmpl
→
templates/base.tmpl
@@ -11,7 +11,7 @@ </head>
<body> {{block "content" .}} - <h1>Base template</h1> + <h1>Base template</h1> {{end}} </body>
M
templates/login.tmpl
→
templates/auth-login.tmpl
@@ -1,24 +1,24 @@
-{{ extends "base.tmpl" }} +{{ extends "auth.tmpl" }} {{define "title" -}}Login{{end}} -{{define "content" -}} +{{define "auth" -}} <h1>Login</h1> <form method="post" action="/login"> <label> <span>Username:</span> - <input type="text" name="username" autocomplete="off" placeholder="Username" required> + <input type="text" name="username" autocomplete="off" placeholder="Username" required /> </label> <label> <span>Password:</span> - <input type="password" name="password" placeholder="Password" required> + <input type="password" name="password" placeholder="Password" required /> </label> <label> <span>Remember me:</span> - <input type="checkbox" name="remember"> + <input type="checkbox" name="remember" /> </label> - <input type="submit" value="Login"> + <input type="submit" value="Login" /> </form> - <a href="/register">Sign up</a> + <a href="/register">Sign up</a><br /> <a href="/reset-password">Reset password</a> {{end}}
M
templates/new_password.tmpl
→
templates/auth-new_password.tmpl
@@ -1,14 +1,14 @@
-{{ extends "base.tmpl" }} +{{ extends "auth.tmpl" }} {{define "title" -}}Reset password{{end}} -{{define "content" -}} +{{define "auth" -}} <h1>Reset password</h1> <form method="post"> <label> <span>New password:</span> - <input type="password" name="password" placeholder="Max 56 chars, ASCII only" required> + <input type="password" name="password" placeholder="Max 56 chars, ASCII only" required /> </label> - <input type="submit" value="Reset password"> + <input type="submit" value="Reset password" /> </form> {{end}}
M
templates/register.tmpl
→
templates/auth-register.tmpl
@@ -1,25 +1,25 @@
-{{ extends "base.tmpl" }} +{{ extends "auth.tmpl" }} {{define "title" -}}Sign up{{end}} -{{define "content" -}} +{{define "auth" -}} <h1>Sign up</h1> <form method="post" action="/register"> <label> <span>Username:</span> - <input type="text" name="username" placeholder="^[a-z0-9._-]+$" required> + <input type="text" name="username" placeholder="[a-z0-9._-]" required /> </label> <label> <span>Email:</span> - <input type="email" name="email" placeholder="Email" required> + <input type="email" name="email" placeholder="Email" required /> </label> <label> <span>Password:</span> - <input type="password" name="password" placeholder="Max 56 chars, ASCII only" required> + <input type="password" name="password" placeholder="Max 56 chars, ASCII only" required /> </label> - <input type="submit" value="Sign up"> + <input type="submit" value="Sign up" /> </form> -<a href="/login">Login</a> +<a href="/login">Login</a><br /> <a href="/reset-password">Reset password</a> </form> {{end}}
M
templates/reset_password.tmpl
→
templates/auth-reset_password.tmpl
@@ -1,16 +1,16 @@
-{{ extends "base.tmpl" }} +{{ extends "auth.tmpl" }} {{define "title" -}}Reset password{{end}} -{{define "content" -}} +{{define "auth" -}} <h1>Reset password</h1> <form method="post" action="/reset-password"> <label> <span>Email:</span> - <input type="email" name="email" placeholder="Email" required> + <input type="email" name="email" placeholder="Email" required /> </label> - <input type="submit" value="Reset password"> + <input type="submit" value="Reset password" /> </form> +<a href="/login">Login</a><br /> <a href="/register">Sign up</a> -<a href="/login">Login</a> {{end}}