diff --git a/pandora/user/views.py b/pandora/user/views.py index 4fc40ed8..0fd30ac9 100644 --- a/pandora/user/views.py +++ b/pandora/user/views.py @@ -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)