forked from 0x2620/pandora
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,15 +44,20 @@ 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()
|
||||||
qs = User.objects.filter(username__iexact=data['username'])
|
if settings.AUTH_CHECK_USERNAME:
|
||||||
if qs.count() == 0:
|
qs = User.objects.filter(username__iexact=data['username'])
|
||||||
response = json_response({
|
if qs.count() == 0:
|
||||||
'errors': {
|
response = json_response({
|
||||||
'username': 'Unknown Username'
|
'errors': {
|
||||||
}
|
'username': 'Unknown Username'
|
||||||
})
|
}
|
||||||
|
})
|
||||||
|
username = None
|
||||||
|
else:
|
||||||
|
username = qs[0].username
|
||||||
else:
|
else:
|
||||||
username = qs[0].username
|
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 data['key'] == 'email':
|
if settings.AUTH_CHECK_USERNAME:
|
||||||
response['data']['users'] = [models.user_json(u, keys)
|
if data['key'] == 'email':
|
||||||
for u in User.objects.filter(email__iexact=data['value'])]
|
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:
|
else:
|
||||||
response['data']['users'] = [models.user_json(u, keys)
|
response['data']['users'] = [{'username': data['value'], 'level': 'member'}]
|
||||||
for u in User.objects.filter(username__iexact=data['value'])]
|
|
||||||
return render_to_json_response(response)
|
return render_to_json_response(response)
|
||||||
actions.register(findUser)
|
actions.register(findUser)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue