コード例 #1
0
ファイル: registration.go プロジェクト: golanghr/goer
func (reg *Registration) processForm(w http.ResponseWriter, r *http.Request) {
	name := r.FormValue("name")
	surname := r.FormValue("surname")
	email := r.FormValue("email")

	if len(name) == 0 ||
		len(surname) == 0 ||
		len(email) == 0 ||
		!validateEmail(email) {
		http.Error(w, "Form submition not valid.", http.StatusBadRequest)
	}

	reg.Name = name
	reg.Surname = surname
	reg.Email = email
	reg.Created = time.Now()

	err := reg.Storer.Store(*reg)
	if err != nil {
		log.Printf("Error %s while storing registration %+v\n", err, reg)
		http.Error(w, "Registration storage failed.", http.StatusInternalServerError)
		return
	}

	p := make(map[string]interface{})
	p["success_msg"] = registrationSuccessful

	if len(reg.InfoFile) > 0 {
		infoTextFile, err := os.Open(reg.InfoFile)
		if err != nil {
			log.Fatal(err)
		}
		defer infoTextFile.Close()

		info, err := content.HTML(infoTextFile)
		if err != nil {
			log.Printf("Error in info text generation %s\n", err)
			http.Error(w, "Error in rendering.", http.StatusInternalServerError)
			return
		}
		p["info"] = template.HTML(info)
	}

	tpls["registration"].Execute(w, p)
}
コード例 #2
0
ファイル: registration.go プロジェクト: golanghr/goer
func (reg *Registration) displayForm(w http.ResponseWriter, r *http.Request) {
	p := make(map[string]interface{})

	if len(reg.InfoFile) > 0 {
		infoTextFile, err := os.Open(reg.InfoFile)
		if err != nil {
			log.Fatal(err)
		}
		defer infoTextFile.Close()

		info, err := content.HTML(infoTextFile)
		if err != nil {
			log.Printf("Error in info text generation %s\n", err)
			http.Error(w, "Error in rendering.", http.StatusInternalServerError)
			return
		}
		p["info"] = template.HTML(info)
	}

	tpls["registration"].Execute(w, p)
}