Esempio n. 1
0
func LogoutHandler(w http.ResponseWriter, r *http.Request) error {
	db, err := util.OpenDb()
	if err != nil {
		return err
	}
	defer db.Close()

	// User authentication
	_, userId, _, err := util.CheckCookie(r, db) // return "" if not logged in
	if err != nil {
		return err
	}

	// Create gen.InvalidateCookie
	err, expiredCookie := util.DeleteCookie(db, userId, false)
	if err != nil {
		return err
	}
	http.SetCookie(w, &expiredCookie)

	http.Redirect(w, r, "https://5sur.com/", 303)
	return nil
}
Esempio n. 2
0
func LogoutHandler(w http.ResponseWriter, r *http.Request) error {
	db, err := util.OpenDb()
	if err != nil {
		return err
	}
	defer db.Close()

	// User authentication
	_, userId, err := util.CheckAppCookie(r, db) // return "" if not logged in
	if err != nil {
		return err
	}

	// Create gen.InvalidateCookie
	err, expiredCookie := util.DeleteCookie(db, userId, true)
	if err != nil {
		return err
	}
	http.SetCookie(w, &expiredCookie)
	w.WriteHeader(200)

	fmt.Fprint(w, "You logged out")
	return nil
}