mirror of
https://gitlab.gnome.org/World/Authenticator.git
synced 2025-03-04 08:44:40 +01:00
imporve database stuff
This commit is contained in:
parent
15b9fe44b1
commit
a472d6b110
7 changed files with 41 additions and 16 deletions
|
@ -1,4 +1,4 @@
|
||||||
desktopdir = $(DATADIR)/applications
|
desktopdir = $(datadir)/applications
|
||||||
desktop_DATA = twofactorauth.desktop
|
desktop_DATA = twofactorauth.desktop
|
||||||
|
|
||||||
UPDATE_DESKTOP = update-desktop-database $(datadir)/applications || :
|
UPDATE_DESKTOP = update-desktop-database $(datadir)/applications || :
|
||||||
|
@ -15,7 +15,7 @@ logo_DATA = about.glade \
|
||||||
menu.glade \
|
menu.glade \
|
||||||
style.css
|
style.css
|
||||||
|
|
||||||
appdatadir = $(DATADIR)/appdata
|
appdatadir = $(datadir)/appdata
|
||||||
appdata_DATA = \
|
appdata_DATA = \
|
||||||
two-factor.appdata.xml
|
two-factor.appdata.xml
|
||||||
|
|
||||||
|
|
BIN
database.db
BIN
database.db
Binary file not shown.
|
@ -1,6 +0,0 @@
|
||||||
CREATE TABLE "providers" (
|
|
||||||
"id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE ,
|
|
||||||
"title" VARCHAR NOT NULL ,
|
|
||||||
"secret_code" VARCHAR NOT NULL UNIQUE ,
|
|
||||||
"image" TEXT NOT NULL
|
|
||||||
)
|
|
|
@ -19,11 +19,13 @@
|
||||||
along with UnitsConverter. If not, see <http://www.gnu.org/licenses/>.
|
along with UnitsConverter. If not, see <http://www.gnu.org/licenses/>.
|
||||||
"""
|
"""
|
||||||
import sys
|
import sys
|
||||||
|
sys.path.insert(1, '@pyexecdir@')
|
||||||
sys.path.insert(1, '@pythondir@')
|
sys.path.insert(1, '@pythondir@')
|
||||||
from twofactorauth import application
|
from twofactorauth import application
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app = application.TwoFactor(package="@PACKAGE@",
|
app = application.Application(package="@PACKAGE@",
|
||||||
version="@VERSION@",
|
version="@VERSION@",
|
||||||
pkgdatadir="@pkgdatadir@")
|
pkgdatadir="@pkgdatadir@")
|
||||||
app.run(None)
|
exit_status = app.run(sys.argv)
|
||||||
|
sys.exit(exit_status)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from gi import require_version
|
from gi import require_version
|
||||||
require_version("Gtk", "3.0")
|
require_version("Gtk", "3.0")
|
||||||
from gi.repository import Gtk, GLib, Gio, Gdk, GObject
|
from gi.repository import Gtk, GLib, Gio, Gdk, GObject
|
||||||
from ui.window import TwoFactorWindow
|
from ui.window import Window
|
||||||
import logging
|
import logging
|
||||||
from models.provider import Provider
|
from models.provider import Provider
|
||||||
|
|
||||||
|
@ -9,8 +9,7 @@ logging.basicConfig(level=logging.DEBUG,
|
||||||
format='[%(levelname)s] %(message)s',
|
format='[%(levelname)s] %(message)s',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
class Application(Gtk.Application):
|
||||||
class TwoFactor(Gtk.Application):
|
|
||||||
win = None
|
win = None
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
|
|
@ -1,13 +1,18 @@
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import logging
|
import logging
|
||||||
from os import path
|
from os import path, mknod
|
||||||
from gi.repository import GdkPixbuf, Gtk
|
from gi.repository import GdkPixbuf, Gtk
|
||||||
logging.basicConfig(level=logging.DEBUG,
|
logging.basicConfig(level=logging.DEBUG,
|
||||||
format='[%(levelname)s] %(message)s',
|
format='[%(levelname)s] %(message)s',
|
||||||
)
|
)
|
||||||
class Provider:
|
class Provider:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.conn = sqlite3.connect('/home/bilal/Projects/Two-factor-gtk/database.db')
|
database_file = '/home/bilal/.config/TwoFactorAuth/database.db'
|
||||||
|
if not (path.isfile(database_file) and path.exists(database_file)):
|
||||||
|
mknod(database_file)
|
||||||
|
self.conn = sqlite3.connect(database_file)
|
||||||
|
if not self.is_table_exists():
|
||||||
|
self.create_table()
|
||||||
|
|
||||||
def add_provider(self, name, secret_code, image):
|
def add_provider(self, name, secret_code, image):
|
||||||
t = (name, secret_code, image,)
|
t = (name, secret_code, image,)
|
||||||
|
@ -79,3 +84,28 @@ class Provider:
|
||||||
logging.error("Couldn't fetch providers list")
|
logging.error("Couldn't fetch providers list")
|
||||||
logging.error(str(e))
|
logging.error(str(e))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def create_table(self):
|
||||||
|
query = '''CREATE TABLE "providers" (
|
||||||
|
"id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE ,
|
||||||
|
"title" VARCHAR NOT NULL ,
|
||||||
|
"secret_code" VARCHAR NOT NULL UNIQUE ,
|
||||||
|
"image" TEXT NOT NULL
|
||||||
|
)'''
|
||||||
|
try:
|
||||||
|
self.conn.execute(query)
|
||||||
|
self.conn.commit()
|
||||||
|
except Exception as e:
|
||||||
|
logging.error("Error during the creation of the database table")
|
||||||
|
logging.error(str(e))
|
||||||
|
|
||||||
|
def is_table_exists(self):
|
||||||
|
query = "SELECT id from providers LIMIT 1"
|
||||||
|
c = self.conn.cursor()
|
||||||
|
try:
|
||||||
|
data = c.execute(query)
|
||||||
|
return True
|
||||||
|
except Exception as e:
|
||||||
|
logging.error("Coudln't check if a table exists")
|
||||||
|
logging.error(e)
|
||||||
|
return False
|
||||||
|
|
|
@ -13,7 +13,7 @@ logging.basicConfig(level=logging.DEBUG,
|
||||||
format='[%(levelname)s] %(message)s',
|
format='[%(levelname)s] %(message)s',
|
||||||
)
|
)
|
||||||
|
|
||||||
class TwoFactorWindow(Gtk.ApplicationWindow):
|
class Window(Gtk.ApplicationWindow):
|
||||||
app = None
|
app = None
|
||||||
selected_app_idx = None
|
selected_app_idx = None
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue