Ejemplo n.º 1
0
// WebBooking sends an email to the recipients with a booking made from the website.
func (n *NLgids) WebBooking(w http.ResponseWriter, r *http.Request) (int, error) {
	tour, date := r.PostFormValue("tour"), r.PostFormValue("date")
	name, email := r.PostFormValue("name"), r.PostFormValue("email")
	phone, persons := r.PostFormValue("phone"), r.PostFormValue("persons")
	message := r.PostFormValue("message")

	if name == "" || email == "" {
		return http.StatusBadRequest, fmt.Errorf("nlgids: all empty")
	}
	if !strings.Contains(email, "@") {
		return http.StatusBadRequest, fmt.Errorf("nlgids: invalid email")
	}
	if persons != "" {
		if _, err := strconv.Atoi(persons); err != nil {
			return http.StatusBadRequest, err
		}
	}
	// Validate date and return error if not available.
	// use n.Config.Subject, n.Config.Secret

	tour = ntour.NameOrNonExists(tour, n.Config.Tours)

	booking := &webbooking.Booking{
		Tour:    tour,
		Date:    date,
		Name:    name,
		Email:   email,
		Phone:   phone,
		Persons: persons,
		Message: message,
	}
	log.Printf("[INFO] NLgids booking: %s:%s:%s:%s:%s:%s:%s", tour, date, name, email, phone, persons, message)

	return sendBookingMail(booking, n.Config.Recipients)
}
Ejemplo n.º 2
0
// WebInvoice sends an email to the recipients from a invoice form from the website.
func (n *NLgids) WebInvoice(w http.ResponseWriter, r *http.Request) (int, error) {
	tour, personsStr := r.PostFormValue("tour"), r.PostFormValue("persons")
	time, duration := r.PostFormValue("time"), r.PostFormValue("duration")
	costStr, date := r.PostFormValue("cost"), r.PostFormValue("date")
	name, fullname := r.PostFormValue("name"), r.PostFormValue("fullname")
	email := r.PostFormValue("email")
	where, how := r.PostFormValue("where"), r.PostFormValue("how")

	if tour == "" || personsStr == "" || time == "" || date == "" || name == "" ||
		fullname == "" || email == "" || duration == "" {
		return http.StatusBadRequest, fmt.Errorf("nlgids: all empty")
	}

	if !strings.Contains(email, "@") {
		return http.StatusBadRequest, fmt.Errorf("nlgids: invalid email")
	}
	cost, err := strconv.ParseFloat(costStr, 64)
	if err != nil {
		return http.StatusBadRequest, err
	}
	persons, err := strconv.Atoi(personsStr)
	if err != nil {
		return http.StatusBadRequest, err
	}

	// Get the real the name of the tour.
	tour = ntour.NameOrNonExists(tour, n.Config.Tours)

	log.Printf("[INFO] NLgids tour: %s:%s:%s:%s:%s:%f", tour, name, email, personsStr, date, cost)

	invoice := &webinvoice.Invoice{
		Tour:     tour,
		Persons:  persons,
		Time:     time,
		Duration: duration,
		Cost:     cost,
		Date:     date,
		Name:     name,
		FullName: fullname,
		Email:    email,
		Where:    where,
		How:      how,
	}

	tmpl := path.Join(n.Config.Template, webinvoice.Template)

	pdf, err := invoice.Create(n.Config.Template, tmpl)
	if err != nil {
		return http.StatusInternalServerError, err
	}
	if len(pdf) == 0 {
		return http.StatusInternalServerError, err
	}
	return sendInvoice(invoice, pdf, n.Config.Recipients)
}
Ejemplo n.º 3
0
func newInvoice() *webinvoice.Invoice {
	i := &webinvoice.Invoice{
		Tour:     "walks/koninklijke",
		Persons:  2,
		Time:     "11.00",
		Duration: "2.0",
		Cost:     50.0,
		Date:     "2015/12/10",
		Name:     "Christel",
		FullName: "Christel Achternaam",
		Email:    "*****@*****.**",
		Where:    "Green Park metro station",
		How:      "Ik sta buiten de de fontein om",
	}
	i.Tour = tour.NameOrNonExists(i.Tour, "/home/miek/html/nlgids.london/tours.json")
	return i
}