示例#1
0
文件: server.go 项目: hamax/avy
// Serves the AngularJS application
func root(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)

	// Get user and account
	u := user.Current(c)
	acc, err := model.GetAccount(c, u)
	if err != nil {
		common.ServeError(c, w, err)
		return
	}

	templates.ExecuteTemplate(w, "index", IndexData{u, acc, domain, port})
}
示例#2
0
文件: modules.go 项目: hamax/avy
// Create a new module
func newModule(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	u := user.Current(c)

	acc, err := model.GetAccount(c, u)
	if err != nil {
		common.ServeError(c, w, err)
		return
	}
	if acc == nil {
		common.Serve401(w)
		return
	}

	// Parse form data
	devname := r.PostFormValue("devname")
	name := r.PostFormValue("name")

	// Set user developer name
	if acc.Devname == "" {
		if devname == "" {
			common.Serve404(w) // TODO: maybe 400 instead
			return
		}
		acc.Devname = devname
		err := model.SaveAccount(c, u, acc)
		if err != nil {
			common.ServeError(c, w, err)
			return
		}
	} else {
		devname = acc.Devname
	}

	e := model.Module{devname, name, time.Now(), nil}
	_, err = datastore.Put(c, datastore.NewKey(c, "module", name, 0, model.GetAccountKey(c, u)), &e)
	if err != nil {
		common.ServeError(c, w, err)
		return
	}

	common.WriteJson(c, w, map[string]string{"Devname": devname, "Name": name})
}