Exemple #1
0
func (s *AuthSuite) logoutTests(user t.TestUser, key util.Key, login bool, c *gc.C) error {
	if login {
		key, err := auth.LoginUser(s.d, user.Email, user.Pwhash)
		c.Assert(err, gc.IsNil)
		user = t.TestUser{
			Email:    user.Email,
			Pwhash:   user.Pwhash,
			LoginKey: string(key),
		}
	}

	if key != util.Key("") {
		user.LoginKey = string(key)
	}

	err := auth.LogoutUser(s.d, user.Email, util.Key(user.LoginKey))
	if err != nil {
		return err
	}

	err = auth.LogoutUser(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
}
Exemple #2
0
func handleLogout(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("bad request: "+err.Error(), err))
			log.Error("bad request: %#v", r)
			return
		}
		email := r.Form.Get("email")
		key := util.Key(r.Form.Get("key"))
		err = auth.LogoutUser(d, email, key)
		if err != nil {
			WriteResponse(w, newApiError(err.Error(), err))
			log.Error("user %q logout for key %q failed: %s", email, key, err.Error())
			return
		}
		WriteResponse(w, &auth.User{
			Email: email,
		})
	}
}