def validate(self, validated_data): data = super().validate(validated_data) # we create a fake user obj with validated data so we can validate # password properly (we have a password validator that requires # a user object) user = models.User(username=data["username"], email=data["email"]) get_adapter().clean_password(data["password1"], user) return data
def save(self, request): adapter = get_adapter() user = adapter.new_user(request) self.cleaned_data = self.get_cleaned_data() adapter.save_user(request, user, self) self.custom_signup(request, user) setup_user_email(request, user, []) return user
def validate_email(self, email): email = get_adapter().clean_email(email) if email and email_address_exists(email): raise serializers.ValidationError( _("A user is already registered with this e-mail address.")) if not str(email).endswith("@uwaterloo.ca"): raise serializers.ValidationError( "Must be a uwaterloo.ca e-mail address.") return email
def save(self, request): adapter = get_adapter() user = adapter.new_user(request) self.cleaned_data = self.get_cleaned_data() try: user.avatar = models.Avatar.objects.get(pk=self.cleaned_data["avatar"]) except: pass adapter.save_user(request, user, self) self.custom_signup(request, user) setup_user_email(request, user, []) return user
def validate_password1(self, password): return get_adapter().clean_password(password)