From 635e81499fb6655a987604c0e05429eda2782a9d Mon Sep 17 00:00:00 2001 From: Andrew Williams Date: Thu, 10 Jun 2010 10:13:59 +0100 Subject: [PATCH] Switched basic out to "Login" and switched User to oauth, in prep for dreddit_oauth. --- api/handlers.py | 30 ++++++++++++++++++++++++++++-- api/urls.py | 4 +++- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/api/handlers.py b/api/handlers.py index 6dde68c..dfb3349 100644 --- a/api/handlers.py +++ b/api/handlers.py @@ -30,6 +30,32 @@ class UserHandler(BaseHandler): except ServiceAccount.DoesNotExist: return rc.NOT_HERE - d = { 'id': u.id, 'username': u.username, 'password': u.password, 'serviceaccounts': u.serviceaccount_set.all(), - 'eveapi': u.eveaccount_set.all(), 'email': u.email } + chars = [] + for a in u.eveaccount_set.all(): + chars.append(a.characters.all()) + + d = { 'id': u.id, 'username': u.username, 'email': u.email, + 'serviceaccounts': u.serviceaccount_set.all(), 'characters': chars, + 'groups': u.groups.all() } + return d + +class LoginHandler(BaseHandler): + allowed_methods = ('GET') + + def read(self, request, id=None): + if id: + try: + u = User.objects.get(id=id) + except (User.DoesNotExist, ValueError): + return rc.NOT_HERE + + if 'user' in request.GET: + try: + u = User.objects.get(username=request.GET['user']) + except User.DoesNotExist: + return rc.NOT_HERE + + d = { 'id': u.id, 'username': u.username, 'password': u.password, 'email': u.email, 'groups': u.groups.all() } + return d + diff --git a/api/urls.py b/api/urls.py index 36d57e8..5a650da 100644 --- a/api/urls.py +++ b/api/urls.py @@ -7,10 +7,12 @@ from api.handlers import * oauth = { 'authentication': OAuthAuthentication() } noauth = { 'authentication': NoAuthentication() } -user_resource = Resource(handler=UserHandler, **noauth) +user_resource = Resource(handler=UserHandler, **oauth) +login_resource = Resource(handler=LoginHandler, **noauth) urlpatterns = patterns('', url(r'^user/$', user_resource), + url(r'^login/$, login_resource), ) urlpatterns += patterns('piston.authentication',