AyushBhardwaj261
AyushBhardwaj261

Reputation: 41

Reset password for user who registered with Social Auth (Google) [Django, Djoser, Social Auth]

I am trying to using custom model with Djoser JWT endpoint but I want to reset the password for those user who register with Google OAuth. When I am using the API endpoint the password reset mail is not getting send to mail.

@action(["post"], detail=False)
def reset_password(self, request, *args, **kwargs):
    serializer = self.get_serializer(data=request.data)
    serializer.is_valid(raise_exception=True)
    user = serializer.get_user()
    if user:
            context = {"user": user}
            to = [get_user_email(user)]
            settings.EMAIL.password_reset(self.request, context).send(to)
    return Response(status=status.HTTP_200_OK)

In the above code when i am following the default procedure i.e., email password for that it is working but when i am trying to reset password for the user who came through SSO for them i am not able to reset the password in that case i am getting user = serializer.get_user() as None but in my dB i can the person's entry (email field).

Any suggestion is appreciated.

I tried to alter the reset password to get the email ID but i am not able to fetch the Email ID from custom user model.

Upvotes: 0

Views: 100

Answers (0)

Related Questions