emile 1 year ago
parent c72a6f2d93
commit 19290ed9a2

@ -31,22 +31,16 @@ def register_customer(request):
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)
user = authenticate(request, email=email)
# Check authentication result
if user is not None:
# Authentication successful
login(request, user)
return JsonResponse({'success': True})
else:
# Authentication failed due to invalid password
return JsonResponse({'success': False, 'error': 'Invalid password'})
return JsonResponse({'success': False, 'error': 'Authentication failed'})

Loading…
Cancel
Save