diff --git a/api/views/auth.py b/api/views/auth.py index 35d6d76..edce144 100644 --- a/api/views/auth.py +++ b/api/views/auth.py @@ -61,8 +61,13 @@ def post(self, request, *args, **kwargs): try: serializer.is_valid(raise_exception=True) except ValidationError as e: - u = User.objects.get(email=request.data['username']) - if not u.is_active: + u = User.objects.filter(email=request.data['username']).first() + if not u: + return Response( + status=status.HTTP_404_NOT_FOUND, + data={'error': _('Usuario no encontrado.')} + ) + elif not u.is_active: return Response( status=status.HTTP_403_FORBIDDEN, data={'error': _('Tu cuenta no está activa, revisa tu bandeja de entrada de correo.')} @@ -74,22 +79,30 @@ def post(self, request, *args, **kwargs): token, created = APIToken.objects.get_or_create(user=user) login(request, user) - # RESPONSE RETROCOMPATIBLE, PENDING REFACTOR - account = Account.objects.get(owner=user) - is_provider = isinstance(account, Provider) - + # RESPONSE RETROCOMPATIBLE, PENDING REFACTOR WHEN APPS ARE READY + type = None entity = None person = None - if is_provider: - entity = parse_entity_data(account) + if user.is_superuser: + type = 'superuser' + elif user.is_staff: + type = 'staff' else: - person = parse_person_data(account) + account = Account.objects.get(owner=user) + is_provider = isinstance(account, Provider) + + if is_provider: + entity = parse_entity_data(account) + type = 'entity' + else: + person = parse_person_data(account) + type = 'person' data = { 'api_key': token.key, 'user_id': user.pk, - 'type': 'entity' if is_provider else 'person', + 'type': type, 'entity': entity, 'person': person, } diff --git a/requirements.txt b/requirements.txt index f89c30d..96b7c27 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,6 @@ django==5.0.0 django-admin-interface==0.24.2 django-ckeditor==6.7.0 django-cleanup==8.1.0 -django-compressor==4.4 django-csp==3.7 django-environ==0.11.2 django-filter==23.5