Initial commit
This commit is contained in:
commit
ff50ea6784
12 changed files with 509 additions and 0 deletions
48
controllers/auth_controller.py
Normal file
48
controllers/auth_controller.py
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
from models.user_model import UserModel
|
||||
from views.login_view import LoginView
|
||||
from controllers.catalog_controller import CatalogController
|
||||
|
||||
|
||||
class AuthController:
|
||||
def __init__(self, database):
|
||||
self.database = database
|
||||
self.model = UserModel(database)
|
||||
self.view = LoginView()
|
||||
|
||||
self.view.login_button.clicked.connect(
|
||||
self.login
|
||||
)
|
||||
self.view.guest_button.clicked.connect(
|
||||
self.login_as_guest
|
||||
)
|
||||
|
||||
def show(self):
|
||||
self.view.show()
|
||||
|
||||
def login(self):
|
||||
login = self.view.login_input.text()
|
||||
password = self.view.password_input.text()
|
||||
user = self.model.authenticate(login, password)
|
||||
|
||||
if user:
|
||||
self.open_catalog(
|
||||
user["full_name"],
|
||||
user["role_name"],
|
||||
)
|
||||
else:
|
||||
self.view.status_label.setText(
|
||||
"Неверный логин или пароль"
|
||||
)
|
||||
|
||||
def login_as_guest(self):
|
||||
self.open_catalog("Гость", "Гость")
|
||||
|
||||
def open_catalog(self, full_name: str, role: str):
|
||||
self.catalog = CatalogController(
|
||||
self.database,
|
||||
full_name,
|
||||
role,
|
||||
self,
|
||||
)
|
||||
self.catalog.show()
|
||||
self.view.close()
|
||||
Loading…
Add table
Add a link
Reference in a new issue