|  |  | @ -6,6 +6,7 @@ from osinacore.models import * | 
			
		
	
		
		
			
				
					
					|  |  |  | from .serializers import * |  |  |  | from .serializers import * | 
			
		
	
		
		
			
				
					
					|  |  |  | from django.contrib.auth import authenticate, login |  |  |  | from django.contrib.auth import authenticate, login | 
			
		
	
		
		
			
				
					
					|  |  |  | from django.http import JsonResponse |  |  |  | from django.http import JsonResponse | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | from django.contrib.auth import AuthenticationFailed | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | @api_view(['POST']) |  |  |  | @api_view(['POST']) | 
			
		
	
	
		
		
			
				
					|  |  | @ -32,10 +33,13 @@ 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') |  |  |  |         password = request.POST.get('password') | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         try: | 
			
		
	
		
		
			
				
					
					|  |  |  |             user = authenticate(request, username=email, password=password) |  |  |  |             user = authenticate(request, username=email, password=password) | 
			
		
	
		
		
			
				
					
					|  |  |  |             if user is not None: |  |  |  |             if user is not None: | 
			
		
	
		
		
			
				
					
					|  |  |  |                 login(request, user) |  |  |  |                 login(request, user) | 
			
		
	
		
		
			
				
					
					|  |  |  |                 return JsonResponse({'success': True}) |  |  |  |                 return JsonResponse({'success': True}) | 
			
		
	
		
		
			
				
					
					|  |  |  |             else: |  |  |  |             else: | 
			
		
	
		
		
			
				
					
					|  |  |  |             # Return the original email along with the error message |  |  |  |                 return JsonResponse({'success': False, 'error': 'Invalid credentials'}) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             return JsonResponse({'success': False, 'error': 'Invalid credentials', 'email': email, 'password':password}) |  |  |  |         except AuthenticationFailed as e: | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             # Return the error message provided by the authentication system | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             return JsonResponse({'success': False, 'error': str(e)}) |