Commit f994cbd6 authored by Jean-samuel TETTEKPOE's avatar Jean-samuel TETTEKPOE
Browse files

Fix login

parent 9932cdf9
Pipeline #9130 failed with stage
in 38 seconds
......@@ -37,5 +37,3 @@ class ObtainJSONWebTokenWrapper(ObtainJSONWebToken):
LoginAttempt.objects.create(user=user, success=success, ip=ip, sent_username=sent_username)
return response
obtain_jwt_token = ObtainJSONWebTokenWrapper.as_view()
......@@ -15,8 +15,8 @@ class BackendTests(APITestCase):
def test_login(self):
data = {'username': 'test', 'password': 'test'}
response = self.client.post('/api-token-auth/', data, format='json')
data = '{"username": "test", "password": "test"}'
response = self.client.post('/api-token-auth/', data, content_type='application/json')
self.assertEqual(response.status_code, 200)
......@@ -28,14 +28,14 @@ class BackendTests(APITestCase):
self.assertEqual(response.data['username'], "test")
def test_login_wrong_password(self):
data = {'username': 'test', 'password': 'sdgez'}
response = self.client.post('/api-token-auth/', data, format='json')
data = '{"username": "test", "password": "sdgez"}'
response = self.client.post('/api-token-auth/', data, content_type='application/json')
self.assertEqual(response.status_code, 400)
def test_login_wrong_user(self):
data = {'username': 'not_admin', 'password': 'test'}
response = self.client.post('/api-token-auth/', data, format='json')
data = '{"username": "not_admin", "password": "test"}'
response = self.client.post('/api-token-auth/', data, content_type='application/json')
self.assertEqual(response.status_code, 400)
......
......@@ -52,7 +52,7 @@ ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = (
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
......@@ -70,8 +70,8 @@ INSTALLED_APPS = (
'bars_transactions',
'bars_news',
'bars_bugtracker',
'bars_menus',
)
'bars_menus'
]
MIDDLEWARE = [
......@@ -122,13 +122,13 @@ REST_FRAMEWORK = {
'DEFAULT_MODEL_SERIALIZER_CLASS':
'rest_framework.serializers.HyperlinkedModelSerializer',
'DEFAULT_PERMISSION_CLASSES': [
'DEFAULT_PERMISSION_CLASSES': (
# 'bars_core.perms.RootBarPermissionsOrAnonReadOnly',
# 'rest_framework.permissions.AllowAny',
# 'bars_core.perms.PerBarPermissionsOrAnonReadOnly',
'rest_framework.permissions.DjangoObjectPermissions',
# 'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly',
],
),
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
'rest_framework.authentication.SessionAuthentication', # TODO: remove
......@@ -140,10 +140,11 @@ REST_FRAMEWORK = {
)
}
AUTHENTICATION_BACKENDS = (
AUTHENTICATION_BACKENDS = [
'bars_core.auth.AuthenticationBackend',
'bars_core.perms.PermissionBackend',
)
'django.contrib.auth.backends.ModelBackend'
]
import datetime
JWT_AUTH = {
......
......@@ -4,9 +4,9 @@ DEBUG = True
TEMPLATE_DEBUG = True
INSTALLED_APPS = INSTALLED_APPS + (
'debug_toolbar',
)
INSTALLED_APPS = INSTALLED_APPS + [
'debug_toolbar'
]
DATABASES = {
'default': {
......@@ -31,6 +31,8 @@ TEMPLATES = [
},
]
MIDDLEWARE += ['debug_toolbar.middleware.DebugToolbarMiddleware']
# DATABASES = {
# 'default': {
......
......@@ -4,9 +4,9 @@ DEBUG = True
TEMPLATE_DEBUG = True
INSTALLED_APPS = INSTALLED_APPS + (
'debug_toolbar',
)
INSTALLED_APPS = INSTALLED_APPS + [
'debug_toolbar'
]
DATABASES = {
'default': {
......
......@@ -14,7 +14,7 @@ from bars_core.models.user import UserViewSet, ResetPasswordView
from bars_core.models.role import RoleViewSet
from bars_core.models.account import AccountViewSet
from bars_core.models.loginattempt import LoginAttemptViewSet
from bars_core.auth import obtain_jwt_token
from bars_core.auth import ObtainJSONWebTokenWrapper
from bars_items.models.sellitem import SellItemViewSet
from bars_items.models.stockitem import StockItemViewSet
......@@ -60,7 +60,7 @@ urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
# url(r'^api-token-auth/', 'rest_framework_jwt.views.obtain_jwt_token'),
url(r'^api-token-auth/', obtain_jwt_token),
url(r'^api-token-auth/', ObtainJSONWebTokenWrapper.as_view()),
url(r'^reset-password/$', ResetPasswordView.as_view()),
url(r'^docs/', schema_view),
url(r'^', include(router.urls)),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment