Writing auth middleware
This commit is contained in:
@ -474,9 +474,11 @@ func (m *Repository) PostShowLogin(w http.ResponseWriter, r *http.Request) {
|
||||
password := r.Form.Get("password")
|
||||
form := forms.New(r.PostForm)
|
||||
form.Required("email", "password")
|
||||
form.IsEmail("email")
|
||||
if !form.Valid() {
|
||||
// TODO
|
||||
http.Redirect(w, r, "/user/login", http.StatusSeeOther)
|
||||
render.Template(w, r, "login.page.tmpl", &models.TemplateData{
|
||||
Form: form,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -24,3 +24,7 @@ func ServerError(w http.ResponseWriter, err error) {
|
||||
app.ErrorLog.Println(trace)
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
func IsAuthenticated(r *http.Request) bool {
|
||||
return app.Session.Exists(r.Context(), "user_id")
|
||||
}
|
||||
|
Reference in New Issue
Block a user