diff --git a/apps/account/serializers/user.py b/apps/account/serializers/user.py index 1c0a605..90d07ce 100644 --- a/apps/account/serializers/user.py +++ b/apps/account/serializers/user.py @@ -26,6 +26,10 @@ class UserProfileSerializer(serializers.ModelSerializer): read_only_fields = ['email', 'info', 'skill', 'device_id', 'slug', 'saved_location'] def get_saved_location(self, obj): + # Check if user is authenticated and has location_history attribute + if not obj.is_authenticated or not hasattr(obj, 'location_history'): + return None + last_location = obj.location_history.order_by('-at_time').first() if last_location: return { diff --git a/apps/course/views/course.py b/apps/course/views/course.py index 59c57b7..ece8362 100644 --- a/apps/course/views/course.py +++ b/apps/course/views/course.py @@ -454,6 +454,22 @@ class CourseOnlineClassTokenValidateAPIView(GenericAPIView): print(f"[Online Validate GET] user={request.user}") print(f"[Online Validate GET] user.is_authenticated={request.user.is_authenticated}") print(f"[Online Validate GET] user.id={request.user.id if request.user.is_authenticated else 'N/A'}") + print(f"[Online Validate GET] Authorization Header={request.META.get('HTTP_AUTHORIZATION', 'NOT FOUND')}") + print(f"[Online Validate GET] All Headers={dict((k, v) for k, v in request.META.items() if k.startswith('HTTP_'))}") + + # Debug: Check if token exists in database + auth_header = request.META.get('HTTP_AUTHORIZATION', '') + if auth_header.startswith('Token '): + token_key = auth_header.split(' ')[1] + try: + from rest_framework.authtoken.models import Token + token_obj = Token.objects.get(key=token_key) + print(f"[Online Validate GET] Token found in DB - user={token_obj.user} user_id={token_obj.user.id}") + except Token.DoesNotExist: + print(f"[Online Validate GET] Token NOT found in DB - token={token_key[:10]}...") + except Exception as e: + print(f"[Online Validate GET] Token check error - {str(e)}") + print("=" * 80) logger.info(f"[Online Validate GET] Request received - slug={slug} user_id={request.user.id if request.user.is_authenticated else 'anonymous'}")