support for auth backends that dont support user lookups

This commit is contained in:
j 2013-09-24 12:29:13 +00:00
parent 0b7d82529c
commit 709b852530

View file

@ -44,6 +44,7 @@ def signin(request):
data = json.loads(request.POST['data'])
if 'username' in data and 'password' in data:
data['username'] = data['username'].strip()
if settings.AUTH_CHECK_USERNAME:
qs = User.objects.filter(username__iexact=data['username'])
if qs.count() == 0:
response = json_response({
@ -51,8 +52,12 @@ def signin(request):
'username': 'Unknown Username'
}
})
username = None
else:
username = qs[0].username
else:
username = data['username']
if username:
user = authenticate(username=username, password=data['password'])
if user is not None:
if user.is_active:
@ -391,12 +396,15 @@ def findUser(request):
# keys = ['username', 'level']
keys = ['username', 'level']
if settings.AUTH_CHECK_USERNAME:
if data['key'] == 'email':
response['data']['users'] = [models.user_json(u, keys)
for u in User.objects.filter(email__iexact=data['value'])]
else:
response['data']['users'] = [models.user_json(u, keys)
for u in User.objects.filter(username__iexact=data['value'])]
else:
response['data']['users'] = [{'username': data['value'], 'level': 'member'}]
return render_to_json_response(response)
actions.register(findUser)