func (repo *Repository) PostLogin(w http.ResponseWriter, r *http.Request) {
	_ = repo.App.Session.RenewToken(r.Context()) // to prevent session fixation attack

	err := r.ParseForm()
	if err != nil {
		repo.App.Session.Put(r.Context(), "error", "can't parse form")
		r.Method = "GET"
		http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
		return
	}

	form := forms.New(r.PostForm)
	form.Required("email", "password")
	form.IsEmail("email")
	if !form.Valid() {
		render.Template(w, r, "login.page.html", &models.TemplateData{
			Form: form,
		})
		return 
	}
	email := r.Form.Get("email")
	password := r.Form.Get("password")

	id, _, err := repo.DB.Authenticate(email, password)
	if err != nil {
		repo.App.Session.Put(r.Context(), "error", "invalid login credentials")
		r.Method = "GET"
		http.Redirect(w, r, "/user/login", http.StatusSeeOther)
		return
	}

	repo.App.Session.Put(r.Context(), "user_id", id)
	repo.App.Session.Put(r.Context(), "flash", "Logged in successfully")
	r.Method = "GET"
	http.Redirect(w, r, "/", http.StatusSeeOther)
}
// PostLogin handles logging the user in 
PostLogin handles logging the user in
// PostLogin handles logging the user in
func (repo *Repository) PostLogin(w http.ResponseWriter, r *http.Request) {
	_ = repo.App.Session.RenewToken(r.Context()) 
	err := r.ParseForm()
	if err != nil {
		repo.App.Session.Put(r.Context(), "error", "can't parse form")
		r.Method = "GET"
		http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
		return
	}
	form := forms.New(r.PostForm)
	form.Required("email", "password")
	form.IsEmail("email")
	if !form.Valid() {
		render.Template(w, r, "login.page.html", &models.TemplateData{
			Form: form,
		})
		return 
	}
	email := r.Form.Get("email")
	password := r.Form.Get("password")
	id, _, err := repo.DB.Authenticate(email, password)
	if err != nil {
		repo.App.Session.Put(r.Context(), "error", "invalid login credentials")
		r.Method = "GET"
		http.Redirect(w, r, "/user/login", http.StatusSeeOther)
		return
	}
	repo.App.Session.Put(r.Context(), "user_id", id)
	repo.App.Session.Put(r.Context(), "flash", "Logged in successfully")
	r.Method = "GET"
	http.Redirect(w, r, "/", http.StatusSeeOther)
}
func ( repo * Repository ) PostLogin ( w http . ResponseWriter , r * http . Request ) { _ = repo . App . Session . RenewToken ( r . Context ( ) ) err := r . ParseForm ( ) if err != nil { repo . App . Session . Put ( r . Context ( ) , " " , " " ) r . Method = " " http . Redirect ( w , r , " " , http . StatusTemporaryRedirect ) return } form := forms . New ( r . PostForm ) form . Required ( " " , " " ) form . IsEmail ( " " ) if ! form . Valid ( ) { render . Template ( w , r , " " , & models . TemplateData { Form : form , } ) return } email := r . Form . Get ( " " ) password := r . Form . Get ( " " ) id , _ , err := repo . DB . Authenticate ( email , password ) if err != nil { repo . App . Session . Put ( r . Context ( ) , " " , " " ) r . Method = " " http . Redirect ( w , r , " " , http . StatusSeeOther ) return } repo . App . Session . Put ( r . Context ( ) , " " , id ) repo . App . Session . Put ( r . Context ( ) , " " , " " ) r . Method = " " http . Redirect ( w , r , " " , http . StatusSeeOther ) }
PostLogin handles logging the user in
PostLogin handles logging the user in
// to prevent session fixation attack