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">
<div class="d-flex flex-column gap-4">
<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"
name="username"
placeholder="Nom d'utilisateur"
@@ -33,14 +33,14 @@
<label for="username">Nom d'utilisateur</label>
</div>
<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"
name="password"
placeholder="Mot de passe"
required
type="password">
<label for="password">Mot de passe</label>
<div class="invalid-feedback">{{.Error}}</div>
<div class="invalid-feedback">{{.PageError.Message}}</div>
</div>
<button id="loginFormButton" class="btn btn-primary" disabled type="submit">
<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",
}
type PageError struct {
Message string `json:"message"`
IsError bool `json:"isError"`
}
func StaticFileServerWithContentType(fsys http.FileSystem) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
path := r.URL.Path
+6 -5
View File
@@ -11,15 +11,16 @@ import (
const LoginRoute = "/login"
type LoginPage struct {
IsError bool `json:"isError"`
Error string `json:"error"`
Username string `json:"username"`
PageError *PageError `json:"error"`
Username string `json:"username"`
}
func NewLoginPage(error string, username string) *LoginPage {
return &LoginPage{
IsError: strings.Compare(error, "") != 0,
Error: error,
PageError: &PageError{
IsError: strings.Compare(error, "") != 0,
Message: error,
},
Username: username,
}
}