diff --git a/osinaweb/osinacore/api/views.py b/osinaweb/osinacore/api/views.py index e1e9455a..a1454baf 100644 --- a/osinaweb/osinacore/api/views.py +++ b/osinaweb/osinacore/api/views.py @@ -34,19 +34,23 @@ def register_customer(request): def authenticate_customer(request): if request.method == 'POST': email = request.POST.get('email') + password = 'ibiye4700' try: user = User.objects.get(email=email) - user = authenticate(request, user=user) - if user is not None: - login(request, user) - return JsonResponse({'success': True, 'user': { - 'id': user.id, - 'email': user.email, - 'username': user.username - }}) - else: - return JsonResponse({'success': False, 'error': 'Invalid credentials'}) except User.DoesNotExist: return JsonResponse({'success': False, 'error': 'User with this email does not exist'}) + + user = authenticate(request, username=email, password=password) + + if user is not None: + # Login the user + login(request, user) + return JsonResponse({'success': True, 'user': { + 'id': user.id, + 'email': user.email, + 'username': user.username + }}) + else: + return JsonResponse({'success': False, 'error': 'Authentication failed'})