Example #1
0
func EmailPrefHandler(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
	}

	if userId == 0 {
		return util.NewError(nil, "Se requiere ingreso a la cuenta", 401)
	}

	prefs, err := util.ReturnEmailPref(db, userId)
	if err != nil {
		return err
	}

	err = templates.ExecuteTemplate(w, "emailPref.html", prefs)
	if err != nil {
		return util.NewError(err, "No se cargó la página", 500)
	}
	return nil
}
Example #2
0
// Return true if you want an email, false otherwise
func emailPref(db *sql.DB, user int, category string) (bool, error) {
	prefs, err := util.ReturnEmailPref(db, user)
	if err != nil {
		return false, err
	}

	switch category {
	case "pending":
		return prefs.Pending, nil
	case "dropped":
		return prefs.Dropped, nil
	case "message":
		return prefs.Message, nil
	case "accepted":
		return prefs.Accepted, nil
	case "removed":
		return prefs.Removed, nil
	case "deleted":
		return prefs.Deleted, nil
	}

	return false, nil
}