54 lines
1.9 KiB
Python
54 lines
1.9 KiB
Python
import sqlite3
|
|
from services.encryption import Encryption
|
|
|
|
class Log:
|
|
def __init__(self, connection : sqlite3.Connection, id = None, username = None, date = None, time = None, description = None, additional_information = None, suspicious = None):
|
|
self.connection = connection
|
|
self.id = id
|
|
self.username = username
|
|
self.date = date
|
|
self.time = time
|
|
self.description = description
|
|
self.additional_information = additional_information
|
|
self.suspicious = suspicious
|
|
|
|
def load_by_id(self):
|
|
cur = self.connection.cursor()
|
|
row = cur.execute("SELECT * FROM logs WHERE id = ?", (self.id,)).fetchone()
|
|
|
|
if row == None:
|
|
return False
|
|
|
|
self._set_row_values(row)
|
|
|
|
cur.close()
|
|
return True
|
|
|
|
def save(self):
|
|
cur = self.connection.cursor()
|
|
|
|
cur.execute("""
|
|
INSERT INTO logs
|
|
(id, username, date, time, description, additional_information, suspicious) VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
""", (self.id, Encryption.encrypt(self.username), Encryption.encrypt(self.date), Encryption.encrypt(self.time), Encryption.encrypt(self.description), Encryption.encrypt(self.additional_information), self.suspicious))
|
|
|
|
self.connection.commit()
|
|
cur.close()
|
|
return True
|
|
|
|
def delete(self):
|
|
cur = self.connection.cursor()
|
|
cur.execute("""DELETE FROM logs WHERE id = ?""", (self.id))
|
|
self.connection.commit()
|
|
cur.close()
|
|
return True
|
|
|
|
def _set_row_values(self, row):
|
|
self.id = row[0]
|
|
self.username = Encryption.decrypt(row[1])
|
|
self.date = Encryption.decrypt(row[2])
|
|
self.time = Encryption.decrypt(row[3])
|
|
self.description = Encryption.decrypt(row[4])
|
|
self.additional_information = Encryption.decrypt(row[5])
|
|
self.suspicious = row[6]
|
|
return self |