From 11ebd8379d4ab6b3956650990e649f9162672fd4 Mon Sep 17 00:00:00 2001 From: obayemi Date: Tue, 16 Jan 2024 17:00:38 +0100 Subject: [PATCH] actually use USER_ID_FIELD in some places it wasnt used --- djoser/email.py | 6 +++--- djoser/serializers.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/djoser/email.py b/djoser/email.py index 8c01925e..3f7451a9 100644 --- a/djoser/email.py +++ b/djoser/email.py @@ -13,7 +13,7 @@ def get_context_data(self): context = super().get_context_data() user = context.get("user") - context["uid"] = utils.encode_uid(user.pk) + context["uid"] = utils.encode_uid(getattr(user, settings.USER_ID_FIELD)) context["token"] = default_token_generator.make_token(user) context["url"] = settings.ACTIVATION_URL.format(**context) return context @@ -31,7 +31,7 @@ def get_context_data(self): context = super().get_context_data() user = context.get("user") - context["uid"] = utils.encode_uid(user.pk) + context["uid"] = utils.encode_uid(getattr(user, settings.USER_ID_FIELD)) context["token"] = default_token_generator.make_token(user) context["url"] = settings.PASSWORD_RESET_CONFIRM_URL.format(**context) return context @@ -52,7 +52,7 @@ def get_context_data(self): context = super().get_context_data() user = context.get("user") - context["uid"] = utils.encode_uid(user.pk) + context["uid"] = utils.encode_uid(getattr(user, settings.USER_ID_FIELD)) context["token"] = default_token_generator.make_token(user) context["url"] = settings.USERNAME_RESET_CONFIRM_URL.format(**context) return context diff --git a/djoser/serializers.py b/djoser/serializers.py index 805bf01c..1211698d 100644 --- a/djoser/serializers.py +++ b/djoser/serializers.py @@ -177,7 +177,7 @@ def validate(self, attrs): # doesn't work with modelserializer try: uid = utils.decode_uid(self.initial_data.get("uid", "")) - self.user = User.objects.get(pk=uid) + self.user = User.objects.get(**{settings.USER_ID_FIELD: uid}) except (User.DoesNotExist, ValueError, TypeError, OverflowError): key_error = "invalid_uid" raise ValidationError(