Beispiel #1
0
  def validate(self):
    """
    Checks if the attributes of the class are valid

    :returns: Boolean
    """
    # TODO: Edit cannot change username!
    # TODO: Verify validation of User Object
    if not (self.password or self.username):
      return False
    ObjectValidator.validateAlNum(self,
                                  'username',
                                  minLength=3,
                                  maxLength=254)
    # Don't update if the password is already a hash
    if not (self.password == 'EXTERNALAUTH') and re.match('^[0-9a-f]{40}$',
                                                          self.password) is None:
      ObjectValidator.validateRegex(self,
                                    'password',
                                    r'(?=^.{8,}$)(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[\W_])(?=^.*[^\s].*$).*$',
                                    'Password has to be set and contain Upper and Lower cases, symbols and numbers and have at least a length of 8'
                                    )

    ObjectValidator.validateEmailAddress(self, 'email')
    ObjectValidator.validateAlNum(self, 'name', minLength=3, withSymbols=True)
    ObjectValidator.validateAlNum(self, 'sirname', minLength=3, withSymbols=True)

    # if self.gpg_key:
    #  ObjectValidator.validateRegex(self,
    #                                'gpg_key',
    #                                '-----BEGIN PGP PUBLIC KEY BLOCK-----(.*?)-----END PGP PUBLIC KEY BLOCK-----',
    #                                'GPG Key not under the right format')
    if self.last_login is not None:
      ObjectValidator.validateDateTime(self, 'last_login')
    return ObjectValidator.isObjectValid(self)
Beispiel #2
0
  def validate(self, full=True):
    """
    Checks if the attributes of the class are valid

    :returns: Boolean
    """
    ObjectValidator.validateDigits(self, 'def_attribute_id')
    # validate attribute value
    value_obj = self.__get_value_obj()
    # TODO: encoding error
    ObjectValidator.validateRegex(value_obj,
                                  'value',
                                  getattr(self.definition, 'regex'),
                                  u'The value "{0}" does not match {1} for definition {2}'.format(value_obj.value,
                                                                                                  getattr(self.definition, 'regex'),
                                                                                                  getattr(self.definition, 'name')).encode('utf-8'),
                                  True)
    errors = not getattr(value_obj, 'validate')()
    if errors:
      return False

    if full:
      ObjectValidator.validateDigits(self, 'object_id')
      ObjectValidator.validateDigits(self, 'creator_id')
      ObjectValidator.validateDigits(self, 'modifier_id')
    ObjectValidator.validateDateTime(self, 'created')
    ObjectValidator.validateDateTime(self, 'modified')
    return ObjectValidator.isObjectValid(self)
Beispiel #3
0
    def validate(self):
        """
    Checks if the attributes of the class are valid

    :returns: Boolean
    """
        # validate attribute value
        value_instance = self.__get_value_instance()
        # TODO: encoding error
        ObjectValidator.validateRegex(
            value_instance, 'value', getattr(self.definition, 'regex'),
            u'The value "{0}" does not match {1} for definition {2}'.format(
                value_instance.value, getattr(self.definition, 'regex'),
                getattr(self.definition, 'name')).encode('utf-8'), True)
        if not isinstance(value_instance, FailedValidation):
            errors = not getattr(value_instance, 'validate')()
            if errors:
                return False
        return ObjectValidator.isObjectValid(self)