clean: made pageError struct type

This commit is contained in:
Florian Sylvain
2023-08-12 22:38:01 +02:00
parent e575062209
commit 5c61796313
3 changed files with 14 additions and 8 deletions
@@ -23,7 +23,7 @@
<form action="login" class="" method="POST"> <form action="login" class="" method="POST">
<div class="d-flex flex-column gap-4"> <div class="d-flex flex-column gap-4">
<div class="form-floating"> <div class="form-floating">
<input class="form-control {{ if .IsError }} is-invalid {{ end }}" <input class="form-control {{ if .PageError.IsError }} is-invalid {{ end }}"
id="username" id="username"
name="username" name="username"
placeholder="Nom d'utilisateur" placeholder="Nom d'utilisateur"
@@ -33,14 +33,14 @@
<label for="username">Nom d'utilisateur</label> <label for="username">Nom d'utilisateur</label>
</div> </div>
<div class="form-floating"> <div class="form-floating">
<input class="form-control {{ if .IsError }} is-invalid {{ end }}" <input class="form-control {{ if .PageError.IsError }} is-invalid {{ end }}"
id="password" id="password"
name="password" name="password"
placeholder="Mot de passe" placeholder="Mot de passe"
required required
type="password"> type="password">
<label for="password">Mot de passe</label> <label for="password">Mot de passe</label>
<div class="invalid-feedback">{{.Error}}</div> <div class="invalid-feedback">{{.PageError.Message}}</div>
</div> </div>
<button id="loginFormButton" class="btn btn-primary" disabled type="submit"> <button id="loginFormButton" class="btn btn-primary" disabled type="submit">
<span class="loginFormButtonLoading visually-hidden spinner-border spinner-border-sm" <span class="loginFormButtonLoading visually-hidden spinner-border spinner-border-sm"
+5
View File
@@ -21,6 +21,11 @@ var contentTypes = map[string]string{
".ico": "image/x-icon", ".ico": "image/x-icon",
} }
type PageError struct {
Message string `json:"message"`
IsError bool `json:"isError"`
}
func StaticFileServerWithContentType(fsys http.FileSystem) http.Handler { func StaticFileServerWithContentType(fsys http.FileSystem) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
path := r.URL.Path path := r.URL.Path
+4 -3
View File
@@ -11,15 +11,16 @@ import (
const LoginRoute = "/login" const LoginRoute = "/login"
type LoginPage struct { type LoginPage struct {
IsError bool `json:"isError"` PageError *PageError `json:"error"`
Error string `json:"error"`
Username string `json:"username"` Username string `json:"username"`
} }
func NewLoginPage(error string, username string) *LoginPage { func NewLoginPage(error string, username string) *LoginPage {
return &LoginPage{ return &LoginPage{
PageError: &PageError{
IsError: strings.Compare(error, "") != 0, IsError: strings.Compare(error, "") != 0,
Error: error, Message: error,
},
Username: username, Username: username,
} }
} }