Skip to content

Commit

Permalink
#160 - api login fix
Browse files Browse the repository at this point in the history
- removed django compressor (failing docker launch)
  • Loading branch information
jbc25 committed May 28, 2024
1 parent bf71204 commit 0f68bb2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
33 changes: 23 additions & 10 deletions api/views/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.')}
Expand All @@ -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,
}
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0f68bb2

Please sign in to comment.