Apparently we should use one database. Fortunately that's easily fixed
This commit is contained in:
parent
cd783945b3
commit
59d9ea4bf4
16
database.py
16
database.py
|
@ -13,7 +13,7 @@ class userstatus(enum.Enum):
|
|||
|
||||
csprng = random.SystemRandom()
|
||||
|
||||
def add_user(userdb, *, username, password, email, parent, status):
|
||||
def add_user(db, *, username, password, email, parent, status):
|
||||
"""Add a user to the database"""
|
||||
global csprgn
|
||||
|
||||
|
@ -34,15 +34,15 @@ def add_user(userdb, *, username, password, email, parent, status):
|
|||
status = status.value
|
||||
|
||||
# Add the user into the database
|
||||
cursor = userdb.cursor()
|
||||
cursor = db.cursor()
|
||||
cursor.execute('INSERT INTO users VALUES (?, ?, ?, ?, ?, ?, ?);', (userid, parent, status, password, username, email, ''))
|
||||
userdb.commit()
|
||||
db.commit()
|
||||
|
||||
def initialize_userdb(userdb, admin_user, admin_password):
|
||||
"""Creates a bare-bones user database with only admin
|
||||
def initialize_users(db, admin_user, admin_password):
|
||||
"""Creates a bare-bones database with only admin user
|
||||
This should never be run outside of the initialization script"""
|
||||
|
||||
cursor = userdb.cursor()
|
||||
cursor = db.cursor()
|
||||
|
||||
cursor.execute('''CREATE TABLE users (
|
||||
id integer NOT NULL PRIMARY KEY,
|
||||
|
@ -58,6 +58,6 @@ def initialize_userdb(userdb, admin_user, admin_password):
|
|||
comment text NOT NULL
|
||||
);''')
|
||||
|
||||
userdb.commit()
|
||||
db.commit()
|
||||
|
||||
add_user(userdb, username = admin_user, password = admin_password, email = '', parent = None, status = userstatus.admin)
|
||||
add_user(db, username = admin_user, password = admin_password, email = '', parent = None, status = userstatus.admin)
|
||||
|
|
|
@ -3,7 +3,7 @@ import sqlite3
|
|||
import database
|
||||
|
||||
if __name__ == '__main__':
|
||||
with sqlite3.connect('user.db') as userdb:
|
||||
with sqlite3.connect('buranun.db') as db:
|
||||
username = input('admin username: ')
|
||||
password = input('admin password: ')
|
||||
database.initialize_userdb(userdb, username, password)
|
||||
database.initialize_users(db, username, password)
|
||||
|
|
Loading…
Reference in New Issue