Esempio n. 1
0
func (s *AuthSuite) testValidate(user t.TestUser, pause int, c *gc.C) error {
	<-time.NewTimer(timeout(pause)).C
	err := auth.Valid(s.d, user.Email, util.Key(user.LoginKey))
	if err != nil {
		return err
	}

	return nil
}
Esempio n. 2
0
func (s *AuthSuite) deleteTests(user t.TestUser, c *gc.C) error {
	err := auth.DeleteUser(s.d, user.Email)
	if err != nil {
		return err
	}

	err = auth.Valid(s.d, user.Email, util.Key(user.LoginKey))
	c.Assert(err, gc.ErrorMatches, fmt.Sprintf("user %q not logged in user not found", user.Email))
	return nil
}
Esempio n. 3
0
func handleValid(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")
		key := util.Key(r.Form.Get("key"))
		err = auth.Valid(d, email, key)
		if err != nil {
			WriteResponse(w, newApiError(err.Error(), err))
			log.Error("error authenticating user %q, key %q: %s", email, key, err.Error())
			return
		}

		log.Info("user %q validated", email)
		WriteResponse(w, &auth.User{
			Email: email,
		})
	}
}