Exemplo n.º 1
0
                        def created_cb(user_details):
                            logging.debug("indx_pg2 create_box, created_cb")
                            rw_user, rw_user_pass, ro_user, ro_user_pass = user_details

                            # assign ownership now to db_owner
                            rw_pw_encrypted = encrypt(rw_user_pass,
                                                      db_owner_pass)
                            ro_pw_encrypted = encrypt(ro_user_pass,
                                                      db_owner_pass)

                            def indx_db(conn_indx):
                                logging.debug("indx_pg2 create_box, indx_db")
                                d_q = conn_indx.runOperation(
                                    "INSERT INTO tbl_keychain (user_id, db_name, db_user, db_user_type, db_password_encrypted) VALUES ((SELECT id_user FROM tbl_users WHERE username = %s), %s, %s, %s, %s), ((SELECT id_user FROM tbl_users WHERE username = %s), %s, %s, %s, %s)",
                                    [
                                        db_owner, db_name, rw_user, 'rw',
                                        rw_pw_encrypted, db_owner, db_name,
                                        ro_user, 'ro', ro_pw_encrypted
                                    ])

                                def inserted(empty):
                                    logging.debug(
                                        "indx_pg2 create_box, inserted - create_box finished"
                                    )
                                    return_d.callback(True)

                                d_q.addCallbacks(inserted, return_d.errback)

                            # connect to INDX db to add new DB accounts to keychain
                            self.connect_indx_db().addCallbacks(
                                indx_db, return_d.errback)
Exemplo n.º 2
0
                        def created_cb(user_details):
                            logging.debug("indx_pg2 create_box, created_cb")
                            rw_user, rw_user_pass, ro_user, ro_user_pass = user_details

                            # assign ownership now to db_owner
                            rw_pw_encrypted = encrypt(rw_user_pass, db_owner_pass)
                            ro_pw_encrypted = encrypt(ro_user_pass, db_owner_pass)

                            def indx_db(conn_indx):
                                logging.debug("indx_pg2 create_box, indx_db")
                                d_q = conn_indx.runOperation("INSERT INTO tbl_keychain (user_id, db_name, db_user, db_user_type, db_password_encrypted) VALUES ((SELECT id_user FROM tbl_users WHERE username = %s), %s, %s, %s, %s), ((SELECT id_user FROM tbl_users WHERE username = %s), %s, %s, %s, %s)", [db_owner, db_name, rw_user, 'rw', rw_pw_encrypted, db_owner, db_name, ro_user, 'ro', ro_pw_encrypted])

                                def inserted(empty):
                                    logging.debug("indx_pg2 create_box, inserted - create_box finished")
                                    return_d.callback(True)

                                d_q.addCallbacks(inserted, return_d.errback)

                            # connect to INDX db to add new DB accounts to keychain
                            self.connect_indx_db().addCallbacks(indx_db, return_d.errback)
Exemplo n.º 3
0
    def save_token(self, token):
        """ Save a token into the db. """
        return_d = Deferred()

        password_encrypted = encrypt(token.password, self.db_pass)
        def conn_cb(conn):

            query = "INSERT INTO tbl_tokens (token_id, username, password_encrypted, boxid, appid, origin, clientip, server_id, created) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, now())"
            params = [token.id, token.username, password_encrypted, token.boxid, token.appid, token.origin or '', token.clientip, token.server_id]

            conn.runOperation(query, params).addCallbacks(lambda empty: return_d.callback(True), return_d.errback)

        self.connect_indx_db().addCallbacks(conn_cb, return_d.errback)
        return return_d
Exemplo n.º 4
0
    def create_user(self, new_username, new_password):
        """ Create a new INDX user. """
        return_d = Deferred()

        pw_hash = make_hash(new_password)
        pw_encrypted = encrypt(new_password, self.db_pass)

        def connected(conn):
            d = conn.runOperation("INSERT INTO tbl_users (username, username_type, password_hash, password_encrypted) VALUES (%s, %s, %s, %s)",[new_username, 'local_owner', pw_hash, pw_encrypted])
            d.addCallbacks(lambda *x: return_d.callback(None), return_d.errback)
            return

        self.connect_indx_db().addCallbacks(connected, return_d.errback)
        return return_d
Exemplo n.º 5
0
    def save_token(self, token):
        """ Save a token into the db. """
        return_d = Deferred()

        password_encrypted = encrypt(token.password, self.db_pass)
        def conn_cb(conn):

            query = "INSERT INTO tbl_tokens (token_id, username, password_encrypted, boxid, appid, origin, clientip, server_id, created) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, now())"
            params = [token.id, token.username, password_encrypted, token.boxid, token.appid, token.origin or '', token.clientip, token.server_id]

            conn.runOperation(query, params).addCallbacks(lambda empty: return_d.callback(True), return_d.errback)

        self.connect_indx_db().addCallbacks(conn_cb, return_d.errback)
        return return_d
Exemplo n.º 6
0
    def create_user(self, new_username, new_password):
        """ Create a new INDX user. """
        return_d = Deferred()

        pw_hash = make_hash(new_password)
        pw_encrypted = encrypt(new_password, self.db_pass)

        def connected(conn):
            d = conn.runOperation(
                "INSERT INTO tbl_users (username, username_type, password_hash, password_encrypted) VALUES (%s, %s, %s, %s)",
                [new_username, 'local_owner', pw_hash, pw_encrypted])
            d.addCallbacks(lambda *x: return_d.callback(None),
                           return_d.errback)
            return

        self.connect_indx_db().addCallbacks(connected, return_d.errback)
        return return_d