diff --git a/backend/api/filters.py b/backend/api/filters.py index 8f10cfb..8b8be32 100644 --- a/backend/api/filters.py +++ b/backend/api/filters.py @@ -159,12 +159,12 @@ def filter_queryset(self, queryset): if user.is_organizer: status_filter = self.data.get("draft") and self.filter_draft or \ - self.data.get("active") and self.filter_active or \ - self.data.get("completed") and self.filter_completed or \ - self.data.get("archive") and self.filter_archive + self.data.get("active") and self.filter_active or \ + self.data.get("completed") and self.filter_completed or \ + self.data.get("archive") and self.filter_archive elif user.is_volunteer: status_filter = self.data.get("active") and self.filter_active or \ - self.data.get("completed") and self.filter_completed + self.data.get("completed") and self.filter_completed if status_filter: queryset = status_filter(queryset) diff --git a/backend/backend/settings.py b/backend/backend/settings.py index 7c02425..c27438d 100644 --- a/backend/backend/settings.py +++ b/backend/backend/settings.py @@ -28,8 +28,6 @@ 'http://*.127.0.0.1', ] -# Application definition - INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', @@ -42,7 +40,6 @@ 'djoser', 'rest_framework', 'rest_framework.authtoken', - # 'rest_framework_swagger', # убираем 'drf_yasg', 'taggit', 'gmailapi_backend', @@ -199,6 +196,7 @@ 'SEND_CONFIRMATION_EMAIL': True, 'SERIALIZERS': { 'current_user': 'api.serializers.CurrentUserSerializer', + 'token_create': 'core.auth.serialisers.CustomTokenCreateSerializer', }, } diff --git a/backend/core/auth/__init__.py b/backend/core/auth/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/core/auth/serialisers.py b/backend/core/auth/serialisers.py new file mode 100644 index 0000000..25e3e7c --- /dev/null +++ b/backend/core/auth/serialisers.py @@ -0,0 +1,47 @@ +from django.contrib.auth import authenticate, get_user_model +from djoser.conf import settings +from djoser.serializers import TokenCreateSerializer +from rest_framework.validators import ValidationError + +User = get_user_model() + + +class CustomTokenCreateSerializer(TokenCreateSerializer): + default_error_messages = { + 'invalid_credentials': ( + settings.CONSTANTS.messages.INVALID_CREDENTIALS_ERROR + ), + 'inactive_account': settings.CONSTANTS.messages.INACTIVE_ACCOUNT_ERROR, + 'missing_account': settings.CONSTANTS.messages.EMAIL_NOT_FOUND, + 'wrong_password': settings.CONSTANTS.messages.INVALID_PASSWORD_ERROR, + } + + def validate(self, attrs): + password = attrs.get('password') + params = {settings.LOGIN_FIELD: attrs.get(settings.LOGIN_FIELD)} + self.user = User.objects.filter(**params).first() + if not self.user: + raise ValidationError( + { + settings.LOGIN_FIELD: + self.default_error_messages.get('missing_account') + }, + ) + elif not self.user.check_password(password): + raise ValidationError( + { + 'password': + self.default_error_messages.get('wrong_password') + }, + ) + self.user = authenticate( + request=self.context.get('request'), **params, password=password + ) + if self.user and self.user.is_active: + return attrs + raise ValidationError( + { + 'not_active': + self.default_error_messages.get('inactive_account') + }, + ) diff --git a/infra_bt/nginx.conf b/infra_bt/nginx.conf index bb1c4a5..bfa120e 100644 --- a/infra_bt/nginx.conf +++ b/infra_bt/nginx.conf @@ -3,7 +3,7 @@ server { server_tokens off; client_max_body_size 20M; - root /usr/share/nginx/html; + root /usr/share/nginx/html/; location /api/ { proxy_set_header Host $http_host;