Exemplo n.º 1
0
func Index(w http.ResponseWriter, r *http.Request) *models.Error {
	if r.Method == "GET" {
		util.RenderView(w, "index", nil)
	} else if r.Method == "POST" {
		r.ParseForm()
		form := &models.Form{
			Name:    util.FetchAndClean(r, "name"),
			Email:   util.FetchAndClean(r, "email"),
			Phone:   util.FetchAndClean(r, "phone"),
			Message: util.FetchAndClean(r, "message"),
		}

		if form.Validate() {
			body := fmt.Sprintf(config.CONTACT_EMAIL, form.Name, form.Email, form.Phone, form.Message)

			if err := util.SendMail(body); err != nil {
				return &models.Error{
					Error:   err,
					Code:    500,
					Message: "Votre lettre pas pu être envoyé. Veuillez réessayer plus tard.",
					View:    "index",
				}
			} else {
				form.Thanks = config.THANK_YOU
			}
		}

		util.RenderView(w, "index", form)
	}
	return nil
}
Exemplo n.º 2
0
func (this Handle) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	if err := this(w, r); err != nil {
		// Log on AppEngine
		c := appengine.NewContext(r)
		log.Errorf(c, "%v", err.Error)

		// Check if UIError was disabled.
		if err.UIDisabled {
			// Log the error for development purposes.
			fmt.Printf("%v", err)
			http.Error(w, err.Message, err.Code)
			return
		}

		// Create UIError and pass to requested view.
		form := &Form{}
		form.NewUIError(err.Message)
		util.RenderView(w, err.View, form)
	}
}