|
|
@ -15,17 +15,18 @@ class User():
|
|
|
|
self.pass_hash = pass_hash
|
|
|
|
self.pass_hash = pass_hash
|
|
|
|
|
|
|
|
|
|
|
|
def set_password(self, password):
|
|
|
|
def set_password(self, password):
|
|
|
|
self.pass_hash = password
|
|
|
|
self.pass_hash = generate_password_hash(password)
|
|
|
|
|
|
|
|
|
|
|
|
def set_id(self, ident):
|
|
|
|
def set_id(self, ident):
|
|
|
|
self.id = ident
|
|
|
|
self.id = ident
|
|
|
|
|
|
|
|
|
|
|
|
def check_password(self, password):
|
|
|
|
def check_password(self, password):
|
|
|
|
return self.pass_hash == password
|
|
|
|
return check_password_hash(self.pass_hash, password)
|
|
|
|
|
|
|
|
|
|
|
|
def get_id(self):
|
|
|
|
def get_id(self):
|
|
|
|
return self.id
|
|
|
|
return self.id
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Item():
|
|
|
|
class Item():
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, name):
|
|
|
|
def __init__(self, name):
|
|
|
@ -35,6 +36,7 @@ class Item():
|
|
|
|
def set_id(self, ident):
|
|
|
|
def set_id(self, ident):
|
|
|
|
self.id = ident
|
|
|
|
self.id = ident
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Entry():
|
|
|
|
class Entry():
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, item_id, date, text, rating, user_id, reviewed):
|
|
|
|
def __init__(self, item_id, date, text, rating, user_id, reviewed):
|
|
|
@ -90,14 +92,15 @@ class Database:
|
|
|
|
crs.execute(query)
|
|
|
|
crs.execute(query)
|
|
|
|
db.commit()
|
|
|
|
db.commit()
|
|
|
|
|
|
|
|
|
|
|
|
def insert_user(self, user):
|
|
|
|
def insert_user(self, username, password):
|
|
|
|
if self.get_user_by_name(user.name) is None and user.pass_hash is not None:
|
|
|
|
pass_hash = generate_password_hash(password)
|
|
|
|
|
|
|
|
if self.get_user_by_name(username) is None and pass_hash is not None:
|
|
|
|
db = self.connect()
|
|
|
|
db = self.connect()
|
|
|
|
crs = db.cursor()
|
|
|
|
crs = db.cursor()
|
|
|
|
query = "INSERT INTO " + self.USER_TABLE_FILE + \
|
|
|
|
query = "INSERT INTO " + self.USER_TABLE_FILE + \
|
|
|
|
"(`name`,`password`)" + \
|
|
|
|
"(`name`,`password`)" + \
|
|
|
|
"VALUES (?, ?) ON CONFLICT DO NOTHING"
|
|
|
|
"VALUES (?, ?) ON CONFLICT DO NOTHING"
|
|
|
|
crs.execute(query, (user.name, user.pass_hash))
|
|
|
|
crs.execute(query, (username, pass_hash))
|
|
|
|
db.commit()
|
|
|
|
db.commit()
|
|
|
|
return crs.lastrowid
|
|
|
|
return crs.lastrowid
|
|
|
|
return None
|
|
|
|
return None
|
|
|
@ -133,7 +136,10 @@ class Database:
|
|
|
|
crs = db.cursor()
|
|
|
|
crs = db.cursor()
|
|
|
|
query = "SELECT * FROM " + self.ENTRY_TABLE_FILE
|
|
|
|
query = "SELECT * FROM " + self.ENTRY_TABLE_FILE
|
|
|
|
crs.execute(query)
|
|
|
|
crs.execute(query)
|
|
|
|
return crs.fetchall()
|
|
|
|
res = []
|
|
|
|
|
|
|
|
for item in crs.fetchall():
|
|
|
|
|
|
|
|
res.append(self.db_to_entry(*item))
|
|
|
|
|
|
|
|
return res
|
|
|
|
|
|
|
|
|
|
|
|
def get_entry_by_id(self, ident):
|
|
|
|
def get_entry_by_id(self, ident):
|
|
|
|
db = self.connect()
|
|
|
|
db = self.connect()
|
|
|
@ -153,7 +159,10 @@ class Database:
|
|
|
|
" WHERE user_id = (SELECT id FROM " + self.USER_TABLE_FILE + \
|
|
|
|
" WHERE user_id = (SELECT id FROM " + self.USER_TABLE_FILE + \
|
|
|
|
" WHERE name = ?)"
|
|
|
|
" WHERE name = ?)"
|
|
|
|
crs.execute(query, (name, ))
|
|
|
|
crs.execute(query, (name, ))
|
|
|
|
return crs.fetchall()
|
|
|
|
res = []
|
|
|
|
|
|
|
|
for item in crs.fetchall():
|
|
|
|
|
|
|
|
res.append(self.db_to_entry(*item))
|
|
|
|
|
|
|
|
return res
|
|
|
|
|
|
|
|
|
|
|
|
def get_item_by_id(self, ident):
|
|
|
|
def get_item_by_id(self, ident):
|
|
|
|
db = self.connect()
|
|
|
|
db = self.connect()
|
|
|
|