func handleCreate(d db.DB) htr.Handle { return func(w http.ResponseWriter, r *http.Request, ps htr.Params) { err := r.ParseForm() if err != nil { WriteResponse(w, newApiError(err.Error(), err)) log.Error("bad request: %#v", r) return } email := r.Form.Get("email") pwhash := r.Form.Get("pwhash") // Check whether the user exists // If it does, fail // If it doesn't, create it err = auth.CreateUser(d, email, pwhash) if err != nil { WriteResponse(w, newApiError(err.Error(), err)) log.Error("error authenticating user %q, pwhash %q: %s", email, pwhash, err.Error()) return } log.Info("user %q created", email) WriteResponse(w, &auth.User{ Email: email, }) } }
func (s *AuthSuite) createTests(user t.TestUser, c *gc.C) error { err := auth.CreateUser(s.d, user.Email, user.Pwhash) if err != nil { return err } userBytes, err := db.GetByKey(s.d, auth.Users, []byte(user.Email)) if err != nil { return err } c.Assert(len(userBytes), gc.Not(gc.Equals), 0) var tmpUser auth.User err = json.Unmarshal(userBytes, &tmpUser) if err != nil { return err } c.Check(tmpUser.Email, gc.Equals, user.Email) return nil }
func (s *AuthSuite) createUsers(c *gc.C) { for _, u := range s.users { err := auth.CreateUser(s.d, u.Email, u.Pwhash) c.Assert(err, gc.IsNil) } }