Added the ability to use "character" for authentication

This commit is contained in:
2011-12-19 01:28:12 +00:00
parent 38f1be7b35
commit 35da7e1402

View File

@@ -67,15 +67,25 @@ class LoginHandler(BaseHandler):
def read(self, request): def read(self, request):
u = None username = request.GET.get('user', None)
if request.GET.get('user', None): character = request.GET.get('character', None)
try: password = request.GET.get('pass', None)
u = User.objects.get(username=request.GET['user'])
except User.DoesNotExist:
return {'auth': 'missing', 'missing': 'Username'}
if u: if username:
if request.GET.get('pass', None) and u.is_active and request.GET['pass'] == u.get_profile().api_service_password: u = User.objects.filter(username=username)
elif character:
u = User.objects.filter(profile__primary_character__name__iexact=character)
else:
u = User.objects.none()
if not u.count():
return {'auth': 'failed', 'error': 'none'}
elif u.count() > 1:
return {'auth': 'failed', 'error': 'multiple'}
else:
u = u[0]
if u.is_active and password and password == u.get_profile().api_service_password:
pchar = u.get_profile().primary_character pchar = u.get_profile().primary_character
if pchar: if pchar:
pchardict = {'id': pchar.id, pchardict = {'id': pchar.id,
@@ -92,7 +102,7 @@ class LoginHandler(BaseHandler):
'email': u.email, 'groups': u.groups.all().values('id', 'name'), 'email': u.email, 'groups': u.groups.all().values('id', 'name'),
'staff': u.is_staff, 'superuser': u.is_superuser, 'primarycharacter': pchardict} 'staff': u.is_staff, 'superuser': u.is_superuser, 'primarycharacter': pchardict}
else: else:
return {'auth': 'failed'} return {'auth': 'failed', 'error': 'password'}
return {'auth': 'missing', 'missing': 'all'} return {'auth': 'missing', 'missing': 'all'}