Example #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)
Example #2
0
    def validate(self):
        """
    Checks if the attributes of the class are valid

    :returns: Boolean
    """
        ObjectValidator.validateAlNum(self,
                                      'name',
                                      withSymbols=True,
                                      minLength=3)
        ObjectValidator.validateAlNum(self,
                                      'description',
                                      minLength=5,
                                      withSpaces=True,
                                      withNonPrintableCharacters=True,
                                      withSymbols=True)
        ObjectValidator.validateDigits(self,
                                       'can_download',
                                       minimal=0,
                                       maximal=1)
        ObjectValidator.validateDigits(self, 'usermails', minimal=0, maximal=1)
        if self.usermails == 0:
            ObjectValidator.validateEmailAddress(self, 'email')
        return ObjectValidator.isObjectValid(self)
Example #3
0
    def validateEmailAddress(string):
        """
      Validates if the attribute is an email.

      Note: The actual object is changed internally

      :param string: Text to be analyzed
      :type string: String
      :param changeAttribute: If set the given attribute will be changed to a
                              type of FailedValidation
      :type changeAttribute: Boolean

      :return Boolean
    """

        obj = Container(string)
        return ObjectValidator.validateEmailAddress(obj,
                                                    'value',
                                                    changeAttribute=False)
Example #4
0
  def validateEmailAddress(string):
    """
      Validates if the attribute is an email.

      Note: The actual object is changed internally

      :param string: Text to be analyzed
      :type string: String
      :param changeAttribute: If set the given attribute will be changed to a
                              type of FailedValidation
      :type changeAttribute: Boolean

      :return Boolean
    """

    obj = Container(string)
    return ObjectValidator.validateEmailAddress(obj,
                                                'value',
                                                changeAttribute=False)