Ejemplo n.º 1
0
func CreateProfile(wr http.ResponseWriter, req *http.Request) {
	var (
		decoder *json.Decoder
		profile *data.Profile
		err     error
		encoder *json.Encoder
	)

	decoder = json.NewDecoder(req.Body)
	profile = data.NewProfile()
	encoder = json.NewEncoder(wr)

	if err = decoder.Decode(profile); err != nil {
		http.Error(wr, err.Error(), http.StatusBadRequest)
		return
	}

	if profile.Exists(profile.Email) {
		wr.WriteHeader(http.StatusConflict)
		encoder.Encode(NewErrorJSONExists())
		return
	}
	if _, err = profile.Save(); err != nil {
		log.Printf("error occurred saving profile %s ", err.Error())
		wr.WriteHeader(http.StatusInternalServerError)
		encoder.Encode(NewErrorJSONUnexpectedError(err.Error()))
		return
	}

	encoder.Encode(profile)
	//get handle to email channel and send email to user
	go service.SendMailTemplate(service.MAIL_TEMPLATE_INTEREST, service.NewMailSender(), service.MAIL_FROM, profile.Email)

}
Ejemplo n.º 2
0
func Test_Email_Send_Bad_Template(t *testing.T) {
	err := service.SendMailTemplate("notemplate", Test_Sender{}, "*****@*****.**", "*****@*****.**")
	if nil == err {
		t.Fatal("expected err during send but there was none ")
	}
}
Ejemplo n.º 3
0
func Test_Email_Send(t *testing.T) {
	err := service.SendMailTemplate(service.MAIL_TEMPLATE_INTEREST, Test_Sender{}, "*****@*****.**", "*****@*****.**")
	if nil != err {
		t.Fatal("did not expect err during send " + err.Error())
	}
}