reply with full user model in auth handlers

This commit is contained in:
Min RK
2015-03-23 16:29:30 -07:00
parent c467c64e01
commit 80997c8297
2 changed files with 3 additions and 7 deletions

View File

@@ -17,9 +17,7 @@ class TokenAPIHandler(APIHandler):
orm_token = orm.APIToken.find(self.db, token) orm_token = orm.APIToken.find(self.db, token)
if orm_token is None: if orm_token is None:
raise web.HTTPError(404) raise web.HTTPError(404)
self.write(json.dumps({ self.write(json.dumps(self.user_model(orm_token.user)))
'user' : orm_token.user.name,
}))
class CookieAPIHandler(APIHandler): class CookieAPIHandler(APIHandler):
@@ -33,9 +31,7 @@ class CookieAPIHandler(APIHandler):
user = self._user_for_cookie(cookie_name, cookie_value) user = self._user_for_cookie(cookie_name, cookie_value)
if user is None: if user is None:
raise web.HTTPError(404) raise web.HTTPError(404)
self.write(json.dumps({ self.write(json.dumps(self.user_model(user)))
'user' : user.name,
}))
default_handlers = [ default_handlers = [

View File

@@ -81,7 +81,7 @@ def test_auth_api(app):
r = api_request(app, 'authorizations/token', api_token) r = api_request(app, 'authorizations/token', api_token)
assert r.status_code == 200 assert r.status_code == 200
reply = r.json() reply = r.json()
assert reply['user'] == user.name assert reply['name'] == user.name
# check fail # check fail
r = api_request(app, 'authorizations/token', api_token, r = api_request(app, 'authorizations/token', api_token,