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

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

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

	err = user.LogoutUser(s.d, u.Email, util.Key(u.LoginKey))
	c.Assert(err, gc.ErrorMatches, fmt.Sprintf("could not get login for email %q not valid", u.Email))
	return nil
}
Example #2
0
func handleUserLogout(d db.DB) htr.Handle {
	return func(w http.ResponseWriter, r *http.Request, ps htr.Params) {
		if err := r.ParseForm(); err != nil {
			WriteResponse(w, newApiError("bad request: "+err.Error(), err))
			log.Printf("bad request: %#v", r)
			return
		}

		email := r.Form.Get("email")
		key := util.Key(r.Form.Get("key"))

		if err := user.LogoutUser(d, email, key); err != nil {
			WriteResponse(w, newApiError(err.Error(), err))
			log.Printf("user %q logout for key %q failed: %s", email, key, err.Error())
			return
		}

		WriteResponse(w, &user.User{
			Email: email,
		})
	}
}