From 0399c7b18b77841000ba4fd92cb920c2acdc1288 Mon Sep 17 00:00:00 2001 From: emile Date: Fri, 5 Apr 2024 22:47:46 +0300 Subject: [PATCH] ss --- osinaweb/osinacore/api/views.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/osinaweb/osinacore/api/views.py b/osinaweb/osinacore/api/views.py index fe3ffebb..487445cb 100644 --- a/osinaweb/osinacore/api/views.py +++ b/osinaweb/osinacore/api/views.py @@ -28,6 +28,8 @@ def register_customer(request): return Response({'message': 'User and Customer data are required'}, status=status.HTTP_400_BAD_REQUEST) + + @api_view(['POST']) def authenticate_customer(request): if request.method == 'POST': @@ -35,10 +37,19 @@ 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 + login(request, user) return JsonResponse({'success': True, 'user': { 'id': user.id, 'email': user.email, 'username': user.username }}) - except ObjectDoesNotExist: - return JsonResponse({'success': False, 'error': 'User with this email does not exist'}) \ No newline at end of file + else: + return JsonResponse({'success': False, 'error': 'Authentication failed'})