Tivix / django-rest-auth

This app makes it extremely easy to build Django powered SPA's (Single Page App) or Mobile apps exposing all registration and authentication related functionality as CBV's (Class Base View) and REST (JSON)
www.tivix.com
MIT License
2.41k stars 661 forks source link

Django `AUTH_PASSWORD_VALIDATORS` is not honored #226

Open fengsi opened 8 years ago

fengsi commented 8 years ago

Title said it all.

dgilge commented 6 years ago

Let me add a few details and a workaround to this. (allauth 0.38.0, rest_auth 0.9.3)

You can define a custom adapter (in your settings.py) with the following code to honor the setting for signup:

from allauth.account.adapter import DefaultAccountAdapter
from django.core.exceptions import ValidationError as DjangoValidationError
from rest_framework.exceptions import ValidationError

class RestAdapter(DefaultAccountAdapter):
    def save_user(self, request, user, form, commit=True):
        user = super().save_user(request, user, form, commit=False)
        try:
            self.clean_password(form.cleaned_data['password1'], user=user)
        except DjangoValidationError as e:
            raise ValidationError(e.messages)
        if commit:
            user.save()
        return user