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