Esempio n. 1
0
    def save(self):
        account = MyUser(
            phone_number=self.validated_data['phone_number'],
            email=self.validated_data['email'],
            first_name=self.validated_data['first_name'],
            last_name=self.validated_data['last_name'],
            username=self.validated_data['username'],
        )
        password = self.validated_data['password']
        password2 = self.validated_data['password2']

        if password and password2 and password != password2:
            raise serializers.ValidationError({'گذرواژه ها باید یکسان باشند'})
        account.set_password(password)
        account.save()
        return account
Esempio n. 2
0
    def save(self):
        user = MyUser(
            email=self.validated_data['email'],
            username=self.validated_data['username'],
        )

        password1 = self.validated_data['password']
        password2 = self.validated_data['password2']

        try:
            password_validation.validate_password(password2, self.instance)
        except forms.ValidationError as error:
            raise serializers.ValidationError(
                {'password': '******'})

        if password1 and password2 and password1 != password2:
            raise serializers.ValidationError(
                {'password': '******'})

        user.set_password(password1)
        user.save()

        return user