mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-17 19:59:29 +00:00
Added the ability to use "character" for authentication
This commit is contained in:
@@ -67,32 +67,42 @@ 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)
|
||||||
pchar = u.get_profile().primary_character
|
elif character:
|
||||||
if pchar:
|
u = User.objects.filter(profile__primary_character__name__iexact=character)
|
||||||
pchardict = {'id': pchar.id,
|
else:
|
||||||
'name': pchar.name,
|
u = User.objects.none()
|
||||||
'corporation': {'name': pchar.corporation.name, 'id': pchar.corporation.id, 'ticker': pchar.corporation.ticker },
|
|
||||||
}
|
if not u.count():
|
||||||
if pchar.corporation.alliance:
|
return {'auth': 'failed', 'error': 'none'}
|
||||||
pchardict['alliance'] = {'id': pchar.corporation.alliance.id, 'name': pchar.corporation.alliance.name, 'ticker': pchar.corporation.alliance.ticker }
|
elif u.count() > 1:
|
||||||
else:
|
return {'auth': 'failed', 'error': 'multiple'}
|
||||||
pchardict['alliance'] = None
|
else:
|
||||||
|
u = u[0]
|
||||||
|
|
||||||
|
if u.is_active and password and password == u.get_profile().api_service_password:
|
||||||
|
pchar = u.get_profile().primary_character
|
||||||
|
if pchar:
|
||||||
|
pchardict = {'id': pchar.id,
|
||||||
|
'name': pchar.name,
|
||||||
|
'corporation': {'name': pchar.corporation.name, 'id': pchar.corporation.id, 'ticker': pchar.corporation.ticker },
|
||||||
|
}
|
||||||
|
if pchar.corporation.alliance:
|
||||||
|
pchardict['alliance'] = {'id': pchar.corporation.alliance.id, 'name': pchar.corporation.alliance.name, 'ticker': pchar.corporation.alliance.ticker }
|
||||||
else:
|
else:
|
||||||
pchardict = None
|
pchardict['alliance'] = None
|
||||||
return {'auth': 'ok', 'id': u.id, 'username': u.username,
|
|
||||||
'email': u.email, 'groups': u.groups.all().values('id', 'name'),
|
|
||||||
'staff': u.is_staff, 'superuser': u.is_superuser, 'primarycharacter': pchardict}
|
|
||||||
else:
|
else:
|
||||||
return {'auth': 'failed'}
|
pchardict = None
|
||||||
|
return {'auth': 'ok', 'id': u.id, 'username': u.username,
|
||||||
|
'email': u.email, 'groups': u.groups.all().values('id', 'name'),
|
||||||
|
'staff': u.is_staff, 'superuser': u.is_superuser, 'primarycharacter': pchardict}
|
||||||
|
else:
|
||||||
|
return {'auth': 'failed', 'error': 'password'}
|
||||||
|
|
||||||
return {'auth': 'missing', 'missing': 'all'}
|
return {'auth': 'missing', 'missing': 'all'}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user