|
|
|
@ -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'})
|
|
|
|
|
# Authentication failed due to invalid password
|
|
|
|
|
return JsonResponse({'success': False, 'error': 'Invalid password'})
|