Exemplo n.º 1
0
    def on_confirm_press(self, event):
        """
        Method override for the callback when the button is pressed
        It checkes wether the given login is possible and doesn't exist
        if so it creates the user and calls 'return_succesful_login'
        or if not 'display_error_message'
        """

        username = self._user_box.text()
        password = self._password_box.text()
        if len(username) > 0 and len(password) > 0:
            userpassregex = '([a-z]|[0-9]|\.)*'
            resu = re.match(userpassregex, username)
            resp = re.match(userpassregex, password)
            if resu.span()[1] == len(resu.string) and resp.span()[1] == len(
                    resp.string):
                credHandler = CredentialsHandler(username, password)
                credHandler.encrypt_credentials()
                if not credHandler.does_user_exist():
                    credHandler.create_user()
                    self.return_succesful_login()
                else:
                    self.display_error_message()
                    self._error_message.setText(
                        "Login exists, pick different one")
            else:
                self._error_message.setText(
                    "Invalid characters, use only a-z, 0-9 and periods (.)")
                self.display_error_message()
Exemplo n.º 2
0
    def test_basic_operations(self):
        db = DatabaseHandler(db_path="pytests/", dbIsTemp=True)
        credh = CredentialsHandler('basic_username', 'basic_password')

        credh.encrypt_credentials()

        self.assertEqual(credh.does_user_exist(), False)
        self.assertEqual(credh.are_cred_valid(), False)

        credh.create_user()

        self.assertEqual(credh.does_user_exist(), True)
        self.assertEqual(credh.are_cred_valid(), True)
        DatabaseHandler.destroy_database()