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