support for auth backends that dont support user lookups
This commit is contained in:
parent
0b7d82529c
commit
709b852530
1 changed files with 21 additions and 13 deletions
|
@ -44,6 +44,7 @@ def signin(request):
|
||||||
data = json.loads(request.POST['data'])
|
data = json.loads(request.POST['data'])
|
||||||
if 'username' in data and 'password' in data:
|
if 'username' in data and 'password' in data:
|
||||||
data['username'] = data['username'].strip()
|
data['username'] = data['username'].strip()
|
||||||
|
if settings.AUTH_CHECK_USERNAME:
|
||||||
qs = User.objects.filter(username__iexact=data['username'])
|
qs = User.objects.filter(username__iexact=data['username'])
|
||||||
if qs.count() == 0:
|
if qs.count() == 0:
|
||||||
response = json_response({
|
response = json_response({
|
||||||
|
@ -51,8 +52,12 @@ def signin(request):
|
||||||
'username': 'Unknown Username'
|
'username': 'Unknown Username'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
username = None
|
||||||
else:
|
else:
|
||||||
username = qs[0].username
|
username = qs[0].username
|
||||||
|
else:
|
||||||
|
username = data['username']
|
||||||
|
if username:
|
||||||
user = authenticate(username=username, password=data['password'])
|
user = authenticate(username=username, password=data['password'])
|
||||||
if user is not None:
|
if user is not None:
|
||||||
if user.is_active:
|
if user.is_active:
|
||||||
|
@ -391,12 +396,15 @@ def findUser(request):
|
||||||
# keys = ['username', 'level']
|
# keys = ['username', 'level']
|
||||||
keys = ['username', 'level']
|
keys = ['username', 'level']
|
||||||
|
|
||||||
|
if settings.AUTH_CHECK_USERNAME:
|
||||||
if data['key'] == 'email':
|
if data['key'] == 'email':
|
||||||
response['data']['users'] = [models.user_json(u, keys)
|
response['data']['users'] = [models.user_json(u, keys)
|
||||||
for u in User.objects.filter(email__iexact=data['value'])]
|
for u in User.objects.filter(email__iexact=data['value'])]
|
||||||
else:
|
else:
|
||||||
response['data']['users'] = [models.user_json(u, keys)
|
response['data']['users'] = [models.user_json(u, keys)
|
||||||
for u in User.objects.filter(username__iexact=data['value'])]
|
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)
|
return render_to_json_response(response)
|
||||||
actions.register(findUser)
|
actions.register(findUser)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue