emile 1 year ago
parent c72a6f2d93
commit 19290ed9a2

@ -31,22 +31,16 @@ def register_customer(request):
def authenticate_customer(request): def authenticate_customer(request):
if request.method == 'POST': if request.method == 'POST':
email = request.POST.get('email') email = request.POST.get('email')
password = request.POST.get('password')
# Check if user with provided email exists
try: try:
user = User.objects.get(email=email) user = User.objects.get(email=email)
except User.DoesNotExist: except User.DoesNotExist:
return JsonResponse({'success': False, 'error': 'User with this email does not exist'}) return JsonResponse({'success': False, 'error': 'User with this email does not exist'})
# Perform authentication user = authenticate(request, email=email)
user = authenticate(request, email=email, password=password)
# Check authentication result
if user is not None: if user is not None:
# Authentication successful
login(request, user) login(request, user)
return JsonResponse({'success': True}) return JsonResponse({'success': True})
else: else:
# Authentication failed due to invalid password return JsonResponse({'success': False, 'error': 'Authentication failed'})
return JsonResponse({'success': False, 'error': 'Invalid password'})

Loading…
Cancel
Save