Esempio n. 1
0
func handleIndex(res http.ResponseWriter, req *http.Request) {
	if req.Method == "POST" {
		name := req.FormValue("name")
		year := req.FormValue("birthYear")

		ctx := appengine.NewContext(req)
		key := datastore.NewKey(ctx, "Person", name, 0, nil)

		person := &Person{
			Name:      name,
			BirthYear: year,
		}

		_, err := datastore.Put(ctx, key, person)
		if err != nil {
			http.Error(res, err.Error(), 500)
			return
		}
	}
	tpl, err := template.ParseFiles("home.html")
	if err != nil {
		log.Fatalln(err)
	}

	err = tpl.ExecuteTemplate(res, "home.html", nil)
	if err != nil {
		http.Error(res, err.Error(), 500)
	}
}
Esempio n. 2
0
func CreateUser(res http.ResponseWriter, req *http.Request, _ httprouter.Params) {
	ctx := appengine.NewContext(req)

	// Form validation skeleton
	//
	//	var PassVerify = req.FormValue("passWordVerify")
	//	var Password = req.FormValue("passWord")
	//
	//	if(PassVerify != Password){
	//
	//	}

	var password, _ = bcrypt.GenerateFromPassword([]byte(req.FormValue("passWord")), bcrypt.DefaultCost)
	user := User{
		FirstName: req.FormValue("firstName"),
		LastName:  req.FormValue("lastName"),
		UserName:  req.FormValue("userName"),
		Email:     req.FormValue("email"),
		Password:  string(password),
	}

	key := datastore.NewKey(ctx, "Users", user.UserName, 0, nil)
	key, err := datastore.Put(ctx, key, &user)
	if err != nil {
		http.Error(res, err.Error(), 500)
		return
	}

	var sd SessionData
	sd.LoggedIn = true

	tpl.ExecuteTemplate(res, "homePage.html", &sd)
}
Esempio n. 3
0
func mainFunc(res http.ResponseWriter, req *http.Request) {
	if req.Method == "POST" {
		addr := req.FormValue("email")
		name := req.FormValue("name")

		c := appengine.NewContext(req)
		key := datastore.NewKey(c, "Email", addr, 0, nil)

		person := &Email{
			Name:      name,
			EmailAddr: addr,
		}

		_, err := datastore.Put(c, key, person)
		if err != nil {
			http.Error(res, err.Error(), 500)
			return
		}
	}

	tpl, err := template.ParseFiles("main.html")
	if err != nil {
		log.Fatalln(err)
	}

	err = tpl.ExecuteTemplate(res, "main.html", nil)
	if err != nil {
		http.Error(res, err.Error(), 500)
	}
}