diff --git a/cgi-example/db.py b/cgi-example/db.py index ebcaa8e..89f2f6e 100644 --- a/cgi-example/db.py +++ b/cgi-example/db.py @@ -1,7 +1,7 @@ import sqlite3 from sqlite3 import Error -database = r"cgi-example.sqlite3" +database = r"db/cgi-example.sqlite3" def create_connection(): """ create a database connection to the SQLite database @@ -22,13 +22,13 @@ def add_user(conn): :param conn: :return: user id """ - - sql = ''' INSERT INTO users - DEFAULT VALUES ''' + sql = ''' INSERT INTO users DEFAULT VALUES ''' cur = conn.cursor() - cur.execute(sql) - conn.commit() - + try: + cur.execute(sql) + conn.commit() + except: + return 'error in insert' return cur.lastrowid def add_hash(conn, cert_user): @@ -38,12 +38,10 @@ def add_hash(conn, cert_user): :param cert_user: :return: id """ - sql = ''' INSERT INTO certs(hash,user_id) - VALUES(?,?) ''' + sql = ''' INSERT INTO certs(hash,user_id) VALUES(?,?) ''' cur = conn.cursor() cur.execute(sql, cert_user) conn.commit() - return cur.lastrowid def get_user(conn, tls_client_hash): @@ -70,7 +68,6 @@ def check_hash(tls_client_hash): :param tls_client_hash: :return: user id """ - conn = create_connection() with conn: user_id = get_user(conn, tls_client_hash) diff --git a/cgi-example/index.gmi b/cgi-example/index.gmi index 7383540..eab5442 100755 --- a/cgi-example/index.gmi +++ b/cgi-example/index.gmi @@ -1,4 +1,5 @@ #!/usr/bin/env python3 + from helpers import get_client_cert from db import check_hash