Django Rest Framework + Django-Allauth Password Reset

I am trying to create a password recovery thread using Django Rest Framework and Django-Allauth.

Django-Allauth already does everything I need, my question is if I can programmatically call the django-allauth function or view from DRF that receives the email I want to reset and continues with the rest of the normal allauth flow (e.g. generating temporary tokens and sending email to the client?

I see no reason to rewrite all this code if one of the applications does everything that I need. just need help on how to "glue" them :)

+3


source to share


2 answers


I understood that

I added this to my DRF resource



@list_route(
    methods=['post'], permission_classes=[AllowAny],
    authentication_classes=[NoAuthentication]
)
def recover_password(self, request):
    if request.DATA.get('email'):
        # Lets be smart and reuse django-allauth password recovery system
        form = ResetPasswordForm({'email': request.DATA.get('email')})
        if form.is_valid():
            form.save()
            return Response(status=200)
    return Response(status=400)

      

+3


source


In case it helps, solved this problem by simply creating a new class to override the password serializer.

from rest_auth.serializers import PasswordResetSerializer
from allauth.account.forms import ResetPasswordForm

class PasswordSerializer (PasswordResetSerializer):
    password_reset_form_class = ResetPasswordForm

      



Then be sure to add this to your settings:

REST_AUTH_SERIALIZERS = {
    'PASSWORD_RESET_SERIALIZER': 'api.helpers.pwdreset.PasswordSerializer',
}

      

+3


source







All Articles