func generateHandler(c appengine.Context, w http.ResponseWriter, r *http.Request) { u := gaeuser.Current(c) if u != nil && u.ID != "" { key := gonuts.UserKey(c, u) user := gonuts.User{} err := datastore.Get(c, key, &user) if err == nil { gonuts.PanicIfErr(user.GenerateToken()) _, err = datastore.Put(c, key, &user) } gonuts.LogError(c, err) } http.Redirect(w, r, "/-/me", http.StatusSeeOther) }
func myHandler(c appengine.Context, w http.ResponseWriter, r *http.Request) { d := make(ContentData) u := gaeuser.Current(c) if u == nil || u.ID == "" { url, err := gaeuser.LoginURL(c, "/-/me") gonuts.LogError(c, err) d["LoginURL"] = url d["OpenIDURL"] = "/-/me/openid" } else { user := new(gonuts.User) err := datastore.Get(c, gonuts.UserKey(c, u), user) if err == nil { url, err := gaeuser.LogoutURL(c, "/") gonuts.LogError(c, err) d["LogoutURL"] = url d["Identifier"] = user.Identifier() d["Token"] = user.Token d["GenerateURL"] = "/-/me/generate" d["Vendors"] = user.Vendors } else if err == datastore.ErrNoSuchEntity { user = &gonuts.User{Id: u.ID, Email: u.Email, FederatedIdentity: u.FederatedIdentity} url, err := gaeuser.LogoutURL(c, "/-/me") gonuts.LogError(c, err) d["LogoutURL"] = url d["Identifier"] = user.Identifier() d["RegisterURL"] = "/-/me/register" } else { panic(err) } } var content bytes.Buffer gonuts.PanicIfErr(Base.ExecuteTemplate(&content, "me.html", d)) bd := BaseData{ Tabtitle: "Me", Title: "Me", Content: template.HTML(content.String()), } gonuts.PanicIfErr(Base.Execute(w, &bd)) }