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()
|
||||
38
controllers/catalog_controller.py
Normal file
38
controllers/catalog_controller.py
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
from models.toy_model import ToyModel
|
||||
from views.catalog_view import CatalogView
|
||||
|
||||
|
||||
class CatalogController:
|
||||
def __init__(self, database, full_name, role, auth):
|
||||
self.database = database
|
||||
self.model = ToyModel(database)
|
||||
self.view = CatalogView(full_name, role)
|
||||
self.auth = auth
|
||||
self.role = role
|
||||
|
||||
self.view.refresh_button.clicked.connect(
|
||||
self.load_data
|
||||
)
|
||||
self.view.sort_button.clicked.connect(
|
||||
self.sort_by_price
|
||||
)
|
||||
self.view.logout_button.clicked.connect(
|
||||
self.logout
|
||||
)
|
||||
|
||||
self.load_data()
|
||||
|
||||
def show(self):
|
||||
self.view.show()
|
||||
|
||||
def load_data(self):
|
||||
toys = self.model.get_all()
|
||||
self.view.load_data(toys)
|
||||
|
||||
def sort_by_price(self):
|
||||
toys = self.model.sort_by_price()
|
||||
self.view.load_data(toys)
|
||||
|
||||
def logout(self):
|
||||
self.view.close()
|
||||
self.auth.show()
|
||||
Loading…
Add table
Add a link
Reference in a new issue