Skip to content

Commit

Permalink
Logged
Browse files Browse the repository at this point in the history
  • Loading branch information
Pomog committed Dec 24, 2023
1 parent 088e79e commit c5b2598
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions internal/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,5 +455,32 @@ func (m *Repository) ShowLogin(w http.ResponseWriter, r *http.Request) {
}

func (m *Repository) PostShowLogin(w http.ResponseWriter, r *http.Request) {
log.Println("PostShowLogin - works")
}
// updates the session data
_ = m.App.Session.RenewToken(r.Context())

err := r.ParseForm()
if err != nil {
log.Println(err)
}

form := forms.New(r.PostForm)
form.Required("email", "password")
if !form.Valid() {
log.Println("not valid form")
}

email := r.Form.Get("email")
password := r.Form.Get("password")

id, _, err := m.DB.Autenticate(email, password)
if err != nil {
m.App.Session.Put (r.Context(), "error","Invalid Login")
http.Redirect(w,r, "/user-login", http.StatusSeeOther)
return
}

m.App.Session.Put(r.Context(), "user_id", id)
m.App.Session.Put (r.Context(), "flash","Logged in successfully")
http.Redirect(w,r, "/user-login", http.StatusSeeOther)

}

0 comments on commit c5b2598

Please sign in to comment.