diff --git a/rog/management/commands/check_user_auth.py b/rog/management/commands/check_user_auth.py new file mode 100644 index 0000000..92e87b2 --- /dev/null +++ b/rog/management/commands/check_user_auth.py @@ -0,0 +1,36 @@ +from django.core.management.base import BaseCommand +from rog.models import CustomUser +from django.contrib.auth import authenticate + +class Command(BaseCommand): + help = 'Check user authentication' + + def add_arguments(self, parser): + parser.add_argument('email', type=str, help='User email to check') + parser.add_argument('--password', type=str, help='Password to test', default='') + + def handle(self, *args, **options): + email = options['email'] + password = options.get('password', '') + + self.stdout.write(f'Checking user: {email}') + + try: + user = CustomUser.objects.get(email=email) + self.stdout.write(f'āœ… User found: {user.email}') + self.stdout.write(f' Active: {user.is_active}') + self.stdout.write(f' Has password: {bool(user.password)}') + self.stdout.write(f' Password hash start: {user.password[:30]}...') + + if password: + self.stdout.write(f'\nšŸ” Testing authentication with provided password...') + auth_user = authenticate(username=email, password=password) + if auth_user: + self.stdout.write('āœ… Authentication successful') + else: + self.stdout.write('āŒ Authentication failed') + + except CustomUser.DoesNotExist: + self.stdout.write(f'āŒ User does not exist: {email}') + except Exception as e: + self.stdout.write(f'āŒ Error: {e}') diff --git a/rog/serializers.py b/rog/serializers.py index ef90f00..b2d1fdd 100755 --- a/rog/serializers.py +++ b/rog/serializers.py @@ -535,9 +535,10 @@ class LoginUserSerializer(serializers.Serializer): else: # Check if the user exists try: - user_obj = User.objects.get(email=email) + from .models import CustomUser + user_obj = CustomUser.objects.get(email=email) raise serializers.ValidationError("Incorrect password.") - except User.DoesNotExist: + except CustomUser.DoesNotExist: raise serializers.ValidationError("User with this email does not exist.") else: raise serializers.ValidationError("Must include 'email' and 'password'.") diff --git a/rog/views.py b/rog/views.py index 1c8d7df..cbbdd3b 100755 --- a/rog/views.py +++ b/rog/views.py @@ -908,11 +908,14 @@ class LoginAPI(generics.GenericAPIView): def post(self, request, *args, **kwargs): logger.info(f"Login attempt for identifier: {request.data.get('identifier', 'identifier not provided')}") logger.debug(f"Request data: {request.data}") + logger.debug(f"Request headers: {dict(request.headers)}") # ćƒ•ćƒ­ćƒ³ćƒˆć‚Øćƒ³ćƒ‰ć® 'identifier' ćƒ•ć‚£ćƒ¼ćƒ«ćƒ‰ć‚’ 'email' ć«ćƒžćƒƒćƒ”ćƒ³ć‚° data = request.data.copy() if 'identifier' in data and 'email' not in data: data['email'] = data['identifier'] + + logger.debug(f"Processed data: {data}") serializer = self.get_serializer(data=data) try: