Validates a new user object before saving it in the database.
        Checks if a password is present unless must_provide_password is False.
        Checks if the username is unique unless the option username_is_unique is set to False.
        If the email column exists on the user object and the option email_is_unique is set to True,
        also checks if the email is unique.

def validate_user(self, user=None, username=None, email=None, password=None, ignore_user_id=None,
                      must_provide_password=False, flash_messages=True, raise_error=True, is_signup=False):
        """Validates a new user object before saving it in the database.
        Checks if a password is present unless must_provide_password is False.
        Checks if the username is unique unless the option username_is_unique is set to False.
        If the email column exists on the user object and the option email_is_unique is set to True,
        also checks if the email is unique.
        """
        ucol = self.options['username_column']
        emailcol = self.options['email_column']
        if user:
            username = getattr(user, ucol, None)
            email = getattr(user, emailcol, None)
            password = getattr(user, self.options["password_column"], None)
            ignore_user_id = getattr(user, 'id', None)
        if username is not None:
            username = username.strip()
        if email is not None:
            email = email.strip().lower()

        if must_provide_password and not password:
            if raise_error:
                raise SignupValidationFailedException("password_missing")
            return False

        if self.user_validator and self.override_builtin_user_validation:
            if not self.user_validator(username, email, password, is_signup):
                if raise_error:
                    raise SignupValidationFailedException("failed_validation")
                return False
            return True

        if ucol != emailcol and self.options["must_provide_username"]:
            if not username:
                if flash_messages and self.options["must_provide_username_error_message"]:
                    flash(self.options["must_provide_username_error_message"], "error")
                if raise_error:
                    raise SignupValidationFailedException("username_missing")
                return False
            if username.lower() in self.options['forbidden_usernames']:
                if flash_messages and self.options["signup_user_exists_message"]:
                    flash(self.options["signup_user_exists_message"], "error")
                if raise_error:
                    raise SignupValidationFailedException("username_forbidden")
                return False
            if len(username) < self.options['min_username_length']:
                if flash_messages and self.options["username_too_short_message"]:
                    flash(self.options["username_too_short_message"], "error")
                if raise_error:
                    raise SignupValidationFailedException("username_too_short")
                return False
            if not self.options['allow_spaces_in_username'] and " " in username:
                if flash_messages and self.options["username_has_spaces_message"]:
                    flash(self.options["username_has_spaces_message"], "error")
                if raise_error:
                    raise SignupValidationFailedException("username_has_spaces")
                return False
        if ucol != emailcol and username and self.options["username_is_unique"]:
            col = ucol if self.options["username_case_sensitive"] else ucol + '_lcase'
            uname = username if self.options["username_case_sensitive"] else username.lower()
            q = self.query.filter((col, uname))
            if ignore_user_id:
                q = q.filter(("id__ne", ignore_user_id))
            if q.count() > 0:
                if flash_messages and self.options["signup_user_exists_message"]:
                    flash(self.options["signup_user_exists_message"], "error")
                if raise_error:
                    raise SignupValidationFailedException("user_exists")
                return False
        if self.options["must_provide_email"] and not email:
            if flash_messages and self.options["must_provide_email_error_message"]:
                flash(self.options["must_provide_email_error_message"], "error")
            if raise_error:
                raise SignupValidationFailedException("email_missing")
            return False
        if self.options["email_is_unique"] and email:
            q = self.query.filter((emailcol, email))
            if ignore_user_id:
                q = q.filter(("id__ne", ignore_user_id))
            if q.count() > 0:
                if flash_messages and self.options["signup_email_exists_message"]:
                    flash(self.options["signup_email_exists_message"], "error")
                if raise_error:
                    raise SignupValidationFailedException("email_exists")
                return False

        if self.user_validator and not self.user_validator(username, email, password, is_signup):
            if raise_error:
                raise SignupValidationFailedException("failed_validation")
            return False

        return True