Esempio n. 1
0
def test2():
    try:
        input = Person()
        input.uniquename = '== Hans =='

        details = user_detail()
        details.firstname = 'Hans'
        details.lastname = 'van der Pol'
        details.gender = 'Men'
        details.dob = '6-3-1966'
        input.details = details
        input.username = '******'
        input.password = None
        input.code = '456'
        input.enabled = True

        autorisation = Autorisation()
        autorisation.write_enabled = True
        autorisation.enabled = True
        autorisation.module_config = pickle.dumps(obj="unique name", protocol=None, fix_imports=False)

        actions = dict()
        actions[ActionEnum.LOGIN] = autorisation
        input.autorisations = actions
        ConnectLongMemory().storeNewPerson(input)

    except Thrift.TException as tx:
        print("%s" % (tx.message))
Esempio n. 2
0
    def enterFirstPerson(self):
        try:
            input = Person()
            input.uniquename = self.__uniquename

            details = user_detail()
            details.firstname = 'Mock'
            details.lastname = 'Person'
            details.gender = 'Cat'
            details.dob = '03-09-1966'
            input.details = details
            input.username = self.__username
            input.password = self.__password
            input.code = self.__code
            input.enabled = True
            input.autorisations = AutorisationsStructProvider(
            ).generate_full_autorisations()
            self.__person = input
            ConnectLongMemory().storeNewPerson(input)

        except UniqueFailedException as unique:
            print('catching unique failed Exception')
            for field in unique.fields:
                print('unique field %s already in database with value' % field)
        except Thrift.TException as tx:
            print("%s" % (tx.message))
Esempio n. 3
0
    def enterNewPerson(self):
        try:
            input = Person()
            input.uniquename = self.__secondUniquename
            details = user_detail()
            details.firstname = 'Celyne'
            details.lastname = 'Van der Pol'
            details.gender = 'Cat'
            details.dob = '03-09-1966'
            input.details = details
            input.username = self.__secondUsername
            encrypted_password = PasswordHelper.encryptPassword(
                self.__password)
            input.password = encrypted_password
            encrypted_code = PasswordHelper.encryptPassword(self.__secondCode)
            input.code = encrypted_code
            input.enabled = True
            tokenInput = self.createEarPiAuthObject()
            self.__token = ConnectEarPi().storeNewPerson(person=input,
                                                         tokenInput=tokenInput)
            print(self.__token)

        except UniqueFailedException as unique:
            print('catching unique failed Exception')
            for field in unique.fields:
                print('unique field %s already in database with value' % field)
        except Thrift.TException as tx:
            print("%s" % (tx.message))
        except Exception as ex:
            print(ex)
Esempio n. 4
0
 def changeUser(self):
     try:
         # create person
         person = Person()
         person.uniquename = self.__uniquename
         person.code = PasswordHelper.hashPassword('123456789')
         details = user_detail()
         details.firstname = 'Changed'
         details.lastname = 'Person'
         details.gender = 'Cat'
         details.dob = '03-09-1966'
         person.details = details
         tokenInput = self.createEarPiAuthObject()
         print(person)
         token = ConnectEarPi().changeUser("details", person, tokenInput)
         self.__token = token
     except Thrift.TException as tx:
         print("%s" % (tx.message))
Esempio n. 5
0
def test1():
    try:
        input = Person()
        input.uniquename = 'AnyRandomString'

        details = user_detail()
        details.firstname = 'Celyne'
        details.lastname = 'van der Pol'
        details.gender = 'undefined'
        details.dob = '5-1-2017'
        input.details = details
        input.username = '******'
        input.password = None
        input.code = '12345'
        input.enabled = False

        ConnectLongMemory().storeNewPerson(input)
        ConnectLongMemory().getPersonConfig('AnyRandomString')

    except Thrift.TException as tx:
        print("%s" % (tx.message))
Esempio n. 6
0
    def __JsonToThrift(jsondata):
        # thrift_string = TSerialization.deserialize(
        #     jsondata, None, TBinaryProtocol.TBinaryProtocolFactory())
        # person = thrift_string

        person = Person()
        person.uniquename = '%s' % jsondata['uniquename']
        if 'details' in jsondata:
            user_detail_json = jsondata['details']
            details = user_detail()
            if 'firstname' in user_detail_json:
                details.firstname = '%s' % user_detail_json['firstname']
            if 'lastname' in user_detail_json:
                details.lastname = '%s' % user_detail_json['lastname']
            if 'gender' in user_detail_json:
                details.gender = '%s' % user_detail_json['gender']
            if 'dob' in user_detail_json:
                details.dob = '%s' % user_detail_json['dob']
            person.details = details
        if 'enabled' in jsondata:
            person.enabled = True if jsondata['enabled'] else False
        if 'autorisations' in jsondata:
            autorisation_json = jsondata['autorisations']
            print(autorisation_json)
            autorisations = dict()
            for key in autorisation_json:
                value = autorisation_json[key]
                autorisation = Autorisation()
                autorisation.write_enabled = True if value[
                    'write_enabled'] else False
                autorisation.enabled = True if value['enabled'] else False
                if 'module_config' in value and value[
                        'module_config'] is not None:
                    autorisation.module_config = str.encode(
                        value['module_config'])
                autorisations[int(key)] = autorisation
            person.autorisations = autorisations
        return person