From 16515ad7ce645c8172019a2ba3016418b53574be Mon Sep 17 00:00:00 2001 From: emile Date: Fri, 5 Apr 2024 22:30:15 +0300 Subject: [PATCH] sss --- osinaweb/osinacore/api/views.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/osinaweb/osinacore/api/views.py b/osinaweb/osinacore/api/views.py index f72319ab..49ae5b94 100644 --- a/osinaweb/osinacore/api/views.py +++ b/osinaweb/osinacore/api/views.py @@ -6,6 +6,7 @@ from osinacore.models import * from .serializers import * from django.contrib.auth import authenticate, login from django.http import JsonResponse +from django.contrib.auth import AuthenticationFailed @api_view(['POST']) @@ -32,10 +33,13 @@ def authenticate_customer(request): if request.method == 'POST': email = request.POST.get('email') password = request.POST.get('password') - user = authenticate(request, username=email, password=password) - if user is not None: - login(request, user) - return JsonResponse({'success': True}) - else: - # Return the original email along with the error message - return JsonResponse({'success': False, 'error': 'Invalid credentials', 'email': email, 'password':password}) \ No newline at end of file + try: + user = authenticate(request, username=email, password=password) + if user is not None: + login(request, user) + return JsonResponse({'success': True}) + else: + return JsonResponse({'success': False, 'error': 'Invalid credentials'}) + except AuthenticationFailed as e: + # Return the error message provided by the authentication system + return JsonResponse({'success': False, 'error': str(e)}) \ No newline at end of file