Make signup honor AUTH_PASSWORD_VALIDATORS

This commit is contained in:
Daniel Gilge 2018-11-10 19:05:24 +01:00 committed by GitHub
parent 479a40d2cc
commit de0b2d5028
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,3 +1,4 @@
from django.core.exceptions import ValidationError as DjangoValidationError
from django.http import HttpRequest
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth import get_user_model
@ -207,7 +208,12 @@ class RegisterSerializer(serializers.Serializer):
adapter = get_adapter()
user = adapter.new_user(request)
self.cleaned_data = self.get_cleaned_data()
adapter.save_user(request, user, self)
user = adapter.save_user(request, user, self, commit=False)
try:
adapter.clean_password(self.cleaned_data['password1'], user=user)
except DjangoValidationError as e:
raise serializers.ValidationError(e.messages)
user.save()
self.custom_signup(request, user)
setup_user_email(request, user, [])
return user