From 85e4aa140d7769ac1f1b29433378104093393e9f Mon Sep 17 00:00:00 2001 From: emile Date: Fri, 5 Apr 2024 22:45:32 +0300 Subject: [PATCH] ss --- osinaweb/osinacore/api/views.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/osinaweb/osinacore/api/views.py b/osinaweb/osinacore/api/views.py index c05c297d..fe3ffebb 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.core.exceptions import ObjectDoesNotExist @api_view(['POST']) @@ -32,5 +33,12 @@ def authenticate_customer(request): if request.method == 'POST': email = request.POST.get('email') - user = User.objects.get(email=email) - return JsonResponse({'success': False, 'user': user}) + try: + user = User.objects.get(email=email) + 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