From c72a6f2d932924b30283e7efde01dfc29eb3c76e Mon Sep 17 00:00:00 2001 From: emile Date: Fri, 5 Apr 2024 22:33:10 +0300 Subject: [PATCH] ss --- osinaweb/osinacore/api/views.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/osinaweb/osinacore/api/views.py b/osinaweb/osinacore/api/views.py index 38f86c93..aaca4912 100644 --- a/osinaweb/osinacore/api/views.py +++ b/osinaweb/osinacore/api/views.py @@ -32,9 +32,21 @@ def authenticate_customer(request): if request.method == 'POST': email = request.POST.get('email') password = request.POST.get('password') + + # Check if user with provided email exists + try: + user = User.objects.get(email=email) + except User.DoesNotExist: + return JsonResponse({'success': False, 'error': 'User with this email does not exist'}) + + # Perform authentication user = authenticate(request, email=email, password=password) + + # Check authentication result if user is not None: + # Authentication successful login(request, user) return JsonResponse({'success': True}) else: - return JsonResponse({'success': False, 'error': 'Invalid credentials'}) \ No newline at end of file + # Authentication failed due to invalid password + return JsonResponse({'success': False, 'error': 'Invalid password'}) \ No newline at end of file