diff --git a/osinaweb/osinacore/api/views.py b/osinaweb/osinacore/api/views.py index 487445cb..8584fa73 100644 --- a/osinaweb/osinacore/api/views.py +++ b/osinaweb/osinacore/api/views.py @@ -37,19 +37,13 @@ def authenticate_customer(request): try: user = User.objects.get(email=email) - except User.DoesNotExist: - return JsonResponse({'success': False, 'error': 'User with this email does not exist'}) - - # Since you're not checking the password, you can simply authenticate the user object - user = authenticate(request, user=user) - - if user is not None: - # Login the user + user = authenticate(request, user=user) login(request, user) return JsonResponse({'success': True, 'user': { 'id': user.id, 'email': user.email, 'username': user.username }}) - else: - return JsonResponse({'success': False, 'error': 'Authentication failed'}) + except User.DoesNotExist: + return JsonResponse({'success': False, 'error': 'User with this email does not exist'}) +