Login
This commit is contained in:
@@ -31,6 +31,8 @@ download_ui.setupUi(UiDownloadWindow)
|
||||
|
||||
if __name__ == "__main__":
|
||||
UiMainWindow.show()
|
||||
from modules.login import loginload
|
||||
ui.username_box.setText(loginload())
|
||||
|
||||
|
||||
# Functions
|
||||
@@ -170,6 +172,11 @@ def change_email_gui():
|
||||
change(ui.email_box.toPlainText())
|
||||
|
||||
|
||||
def login_logout_gui():
|
||||
from modules.login import login
|
||||
ui.username_box.setText(login())
|
||||
|
||||
|
||||
# Run functions on startup
|
||||
if __name__ == "__main__":
|
||||
# Checking version
|
||||
@@ -212,6 +219,7 @@ if __name__ == "__main__":
|
||||
f"/registration"))
|
||||
ui.changepass_button.clicked.connect(change_password_gui)
|
||||
ui.changeemail_button.clicked.connect(change_email_gui)
|
||||
ui.loginlogout_button.clicked.connect(login_logout_gui)
|
||||
|
||||
# Handle GUI exiting to exit whole program
|
||||
sys.exit(app.exec_())
|
||||
|
||||
@@ -2,7 +2,7 @@ import json
|
||||
import modules.vars as horsy_vars
|
||||
|
||||
|
||||
def get_auth(is_gui=False, login_ui=None, Ui_LoginWindow=None):
|
||||
def get_auth(is_gui=False, login_ui=None, Ui_LoginWindow=None, *args):
|
||||
with open(horsy_vars.horsypath + 'config.cfg') as f:
|
||||
config = json.load(f)
|
||||
|
||||
@@ -29,6 +29,11 @@ def get_auth(is_gui=False, login_ui=None, Ui_LoginWindow=None):
|
||||
login_ui.login_button.clicked.connect(lambda: get_gui_auth(login_ui=login_ui,
|
||||
Ui_LoginWindow=Ui_LoginWindow))
|
||||
|
||||
try:
|
||||
args()
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
def get_gui_auth(login_ui, Ui_LoginWindow):
|
||||
with open(horsy_vars.horsypath + 'config.cfg') as f:
|
||||
|
||||
@@ -91,7 +91,8 @@ class Ui_MainWindow(object):
|
||||
self.username_box.setGeometry(QtCore.QRect(720, 70, 151, 31))
|
||||
self.username_box.setStyleSheet("background-color: rgb(74, 76, 83);\n"
|
||||
"border-radius: 5px; \n"
|
||||
"color: rgb(242, 242, 242);")
|
||||
"color: rgb(242, 242, 242);\n"
|
||||
"padding: 0px 5px 0px 5px;\n")
|
||||
self.username_box.setText("")
|
||||
self.username_box.setReadOnly(True)
|
||||
self.username_box.setObjectName("username_box")
|
||||
|
||||
41
modules/login.py
Normal file
41
modules/login.py
Normal file
@@ -0,0 +1,41 @@
|
||||
import requests
|
||||
from PyQt5 import QtWidgets
|
||||
import modules.gui as gui
|
||||
from modules.auth import get_auth, del_auth
|
||||
import modules.vars as horsy_vars
|
||||
import json
|
||||
|
||||
|
||||
def loginload():
|
||||
UiLoginWindow = QtWidgets.QMainWindow()
|
||||
login_ui = gui.Ui_LoginWindow()
|
||||
login_ui.setupUi(UiLoginWindow)
|
||||
UiMainWindow = QtWidgets.QMainWindow()
|
||||
ui = gui.Ui_MainWindow()
|
||||
ui.setupUi(UiMainWindow)
|
||||
try:
|
||||
with open(horsy_vars.horsypath + 'config.cfg') as f:
|
||||
config = json.load(f)
|
||||
if config['auth'] is not None:
|
||||
return (lambda x: (x if x != "Forbidden" else "Invalid login"))\
|
||||
(requests.get(horsy_vars.protocol + horsy_vars.server_url + '/users/login',
|
||||
json={'auth': config['auth']}).json()['message'])
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
def login():
|
||||
UiLoginWindow = QtWidgets.QMainWindow()
|
||||
login_ui = gui.Ui_LoginWindow()
|
||||
login_ui.setupUi(UiLoginWindow)
|
||||
with open(horsy_vars.horsypath + 'config.cfg') as f:
|
||||
config = json.load(f)
|
||||
try:
|
||||
if config['auth'] is not None:
|
||||
del_auth()
|
||||
gui.popup('Authentication', 'Auth deleted')
|
||||
return 'Log in first'
|
||||
else:
|
||||
raise 'No auth'
|
||||
except:
|
||||
auth = get_auth(True, login_ui, QtWidgets.QMainWindow(), loginload()) # TODO: fix this
|
||||
Reference in New Issue
Block a user