fix: handle template render errors
This commit is contained in:
@@ -11,8 +11,6 @@ type Handler struct {
|
|||||||
authService *Service
|
authService *Service
|
||||||
}
|
}
|
||||||
|
|
||||||
const rateLimitFormError = "Too many attempts in a short time. Please wait a minute and try again."
|
|
||||||
|
|
||||||
func NewHandler(authService *Service) *Handler {
|
func NewHandler(authService *Service) *Handler {
|
||||||
return &Handler{authService: authService}
|
return &Handler{authService: authService}
|
||||||
}
|
}
|
||||||
@@ -29,11 +27,13 @@ func (h *Handler) HandleLoginPage(w http.ResponseWriter, r *http.Request) {
|
|||||||
// HandleLogin validates credentials and creates a session on success
|
// HandleLogin validates credentials and creates a session on success
|
||||||
func (h *Handler) HandleLogin(w http.ResponseWriter, r *http.Request) {
|
func (h *Handler) HandleLogin(w http.ResponseWriter, r *http.Request) {
|
||||||
if err := r.ParseForm(); err != nil {
|
if err := r.ParseForm(); err != nil {
|
||||||
templates.GetRenderer().ExecuteTemplate(r.Context(), w, "login.gohtml", map[string]any{
|
if err := templates.GetRenderer().ExecuteTemplate(r.Context(), w, "login.gohtml", map[string]any{
|
||||||
"Error": "Something went wrong. Please try again.",
|
"Error": "Something went wrong. Please try again.",
|
||||||
"Username": "",
|
"Username": "",
|
||||||
"CurrentPath": r.URL.Path,
|
"CurrentPath": r.URL.Path,
|
||||||
})
|
}); err != nil {
|
||||||
|
log.Printf("render error: %v", err)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,21 +41,25 @@ func (h *Handler) HandleLogin(w http.ResponseWriter, r *http.Request) {
|
|||||||
password := r.FormValue("password")
|
password := r.FormValue("password")
|
||||||
|
|
||||||
if username == "" || password == "" {
|
if username == "" || password == "" {
|
||||||
templates.GetRenderer().ExecuteTemplate(r.Context(), w, "login.gohtml", map[string]any{
|
if err := templates.GetRenderer().ExecuteTemplate(r.Context(), w, "login.gohtml", map[string]any{
|
||||||
"Error": "The email or password is wrong.",
|
"Error": "The email or password is wrong.",
|
||||||
"Username": username,
|
"Username": username,
|
||||||
"CurrentPath": r.URL.Path,
|
"CurrentPath": r.URL.Path,
|
||||||
})
|
}); err != nil {
|
||||||
|
log.Printf("render error: %v", err)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
session, err := h.authService.Login(r.Context(), username, password)
|
session, err := h.authService.Login(r.Context(), username, password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
templates.GetRenderer().ExecuteTemplate(r.Context(), w, "login.gohtml", map[string]any{
|
if err := templates.GetRenderer().ExecuteTemplate(r.Context(), w, "login.gohtml", map[string]any{
|
||||||
"Error": "The email or password is wrong.",
|
"Error": "The email or password is wrong.",
|
||||||
"Username": username,
|
"Username": username,
|
||||||
"CurrentPath": r.URL.Path,
|
"CurrentPath": r.URL.Path,
|
||||||
})
|
}); err != nil {
|
||||||
|
log.Printf("render error: %v", err)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user