Exemple #1
0
func (h *homeController) login(w http.ResponseWriter, req *http.Request) {
	responseWriter := util.GetResponseWriter(w, req)
	defer responseWriter.Close()

	w.Header().Add("Content Type", "text/html")

	if req.Method == "POST" {
		email := req.FormValue("email")
		password := req.FormValue("password")

		member, err := models.GetMember(email, password)

		if err == nil {
			session, err := models.CreateSession(member)
			log.Printf("create session err: %v", err)
			if err == nil {
				var cookie http.Cookie
				cookie.Name = "sessionId"
				cookie.Value = session.SessionId()
				responseWriter.Header().Add("Set-Cookie", cookie.String())
			}
		} else {
			log.Print("User not found!")
		}
	}

	vm := viewmodels.GetLogin()

	h.loginTemplate.Execute(responseWriter, vm)
}
func (s *standLocatorController) get(w http.ResponseWriter, req *http.Request) {
	responseWriter := util.GetResponseWriter(w, req)
	defer responseWriter.Close()

	vm := viewmodels.GetStandLocator()
	responseWriter.Header().Add("Content Type", "text/html")

	s.template.Execute(responseWriter, vm)
}
Exemple #3
0
func (h *homeController) get(w http.ResponseWriter, req *http.Request) {
	vm := viewmodels.GetHome()

	w.Header().Add("Content Type", "text/html")

	responseWriter := util.GetResponseWriter(w, req)
	defer responseWriter.Close()

	h.template.Execute(responseWriter, vm)
}
func (s *standLocatorController) apiSearch(w http.ResponseWriter, req *http.Request) {
	responseWriter := util.GetResponseWriter(w, req)
	defer responseWriter.Close()

	vm := viewmodels.GetStandLocations()
	responseWriter.Header().Add("Content Type", "application/json")
	data, err := json.Marshal(vm)
	if err == nil {
		responseWriter.Write(data)
	} else {
		responseWriter.WriteHeader(http.StatusNotFound)
	}
}
Exemple #5
0
func (p *productController) get(w http.ResponseWriter, req *http.Request) {
	vars := mux.Vars(req)

	id, err := strconv.Atoi(vars["id"])
	if err == nil {
		vm := viewmodels.GetProduct(id)

		w.Header().Add("Content Type", "text/html")
		gzw := util.GetResponseWriter(w, req)
		defer gzw.Close()

		p.template.Execute(gzw, vm)
	} else {
		w.WriteHeader(http.StatusNotFound)
		w.Write([]byte(http.StatusText(http.StatusNotFound)))
	}
}
Exemple #6
0
func (c *categoriesController) get(w http.ResponseWriter, req *http.Request) {
	categories := models.GetCategories()

	categoriesVM := []viewmodels.Category{}
	for _, category := range categories {
		categoriesVM = append(categoriesVM, converters.ConvertCategoryToViewModel(category))
	}

	vm := viewmodels.GetCategories()
	vm.Categories = categoriesVM

	w.Header().Add("Content Type", "text/html")

	responseWriter := util.GetResponseWriter(w, req)
	defer responseWriter.Close()

	c.template.Execute(responseWriter, vm)
}
Exemple #7
0
func (p *profileController) handle(w http.ResponseWriter, req *http.Request) {
	gzrw := util.GetResponseWriter(w, req)
	defer gzrw.Close()

	vm := viewmodels.GetProfile()

	if req.Method == "POST" {
		vm.User.Email = req.FormValue("email")
		vm.User.FirstName = req.FormValue("firstName")
		vm.User.LastName = req.FormValue("lastName")
		vm.User.Stand.Address = req.FormValue("standAddress")
		vm.User.Stand.City = req.FormValue("standCity")
		vm.User.Stand.State = req.FormValue("standState")
		vm.User.Stand.Zip = req.FormValue("standZip")
	}

	gzrw.Header().Add("Content Type", "text/html")
	p.template.Execute(gzrw, vm)
}