Initial commit
This commit is contained in:
commit
83c902d6c3
26 changed files with 531 additions and 0 deletions
BIN
src/__pycache__/auth.cpython-313.pyc
Normal file
BIN
src/__pycache__/auth.cpython-313.pyc
Normal file
Binary file not shown.
19
src/auth.py
Normal file
19
src/auth.py
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
from database.db_session import session
|
||||
from database.models import Auth, Users
|
||||
|
||||
def register_user(login, password, username):
|
||||
if session.query(Auth).filter_by(login=login).first():
|
||||
return False, "Логин уже используется."
|
||||
new_auth = Auth(login=login, password=password)
|
||||
session.add(new_auth)
|
||||
session.commit()
|
||||
new_user = Users(user_id=new_auth.user_id, username=username)
|
||||
session.add(new_user)
|
||||
session.commit()
|
||||
return True, "Регистрация успешна."
|
||||
|
||||
def login_user(login, password):
|
||||
user = session.query(Auth).filter_by(login=login, password=password).first()
|
||||
if user:
|
||||
return True, user.user_id
|
||||
return False, "Неверный логин или пароль."
|
||||
16
src/main.py
Normal file
16
src/main.py
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
from tkinter import Tk
|
||||
from src.ui.auth_ui import DogAcademyApp # Изменил на правильный путь
|
||||
from database.db_session import init_db
|
||||
|
||||
def main():
|
||||
"""Основной запуск приложения."""
|
||||
# Инициализируем базу данных
|
||||
init_db()
|
||||
|
||||
# Запускаем графический интерфейс
|
||||
root = Tk()
|
||||
app = DogAcademyApp(root)
|
||||
root.mainloop()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
BIN
src/ui/__pycache__/admin_ui.cpython-313.pyc
Normal file
BIN
src/ui/__pycache__/admin_ui.cpython-313.pyc
Normal file
Binary file not shown.
BIN
src/ui/__pycache__/auth_ui.cpython-313.pyc
Normal file
BIN
src/ui/__pycache__/auth_ui.cpython-313.pyc
Normal file
Binary file not shown.
BIN
src/ui/__pycache__/user_ui.cpython-313.pyc
Normal file
BIN
src/ui/__pycache__/user_ui.cpython-313.pyc
Normal file
Binary file not shown.
59
src/ui/admin_ui.py
Normal file
59
src/ui/admin_ui.py
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
# admin_ui.py
|
||||
import tkinter as tk
|
||||
from config import BACKGROUND_COLOR, PRIMARY_COLOR, BUTTON_COLOR, BUTTON_TEXT_COLOR, FONT
|
||||
|
||||
class AdminApp:
|
||||
def __init__(self, root):
|
||||
self.root = root
|
||||
self.show_admin_dashboard()
|
||||
|
||||
def show_admin_dashboard(self):
|
||||
"""Показать интерфейс администратора."""
|
||||
self.clear_frame()
|
||||
self.current_frame = tk.Frame(self.root, bg=BACKGROUND_COLOR)
|
||||
self.current_frame.pack(expand=True)
|
||||
|
||||
# Заголовок
|
||||
title = tk.Label(
|
||||
self.current_frame,
|
||||
text="Админ-Панель",
|
||||
bg=BACKGROUND_COLOR,
|
||||
fg=PRIMARY_COLOR,
|
||||
font=FONT,
|
||||
)
|
||||
title.pack(pady=50)
|
||||
|
||||
# Кнопка для управления вопросами
|
||||
manage_questions_button = tk.Button(
|
||||
self.current_frame,
|
||||
text="Управление вопросами",
|
||||
bg=BUTTON_COLOR,
|
||||
fg=BUTTON_TEXT_COLOR,
|
||||
font=FONT,
|
||||
command=self.manage_questions,
|
||||
)
|
||||
manage_questions_button.pack(pady=20)
|
||||
|
||||
# Кнопка для управления пользователями
|
||||
manage_users_button = tk.Button(
|
||||
self.current_frame,
|
||||
text="Управление пользователями",
|
||||
bg=BUTTON_COLOR,
|
||||
fg=BUTTON_TEXT_COLOR,
|
||||
font=FONT,
|
||||
command=self.manage_users,
|
||||
)
|
||||
manage_users_button.pack(pady=20)
|
||||
|
||||
def manage_questions(self):
|
||||
"""Управление вопросами в игре."""
|
||||
pass
|
||||
|
||||
def manage_users(self):
|
||||
"""Управление пользователями игры."""
|
||||
pass
|
||||
|
||||
def clear_frame(self):
|
||||
"""Очистить текущий фрейм."""
|
||||
if hasattr(self, 'current_frame') and self.current_frame:
|
||||
self.current_frame.destroy()
|
||||
222
src/ui/auth_ui.py
Normal file
222
src/ui/auth_ui.py
Normal file
|
|
@ -0,0 +1,222 @@
|
|||
import tkinter as tk
|
||||
from tkinter import messagebox
|
||||
from config import BACKGROUND_COLOR, PRIMARY_COLOR, BUTTON_COLOR, BUTTON_TEXT_COLOR, FONT, BIG_FONT, ADMIN_LOGIN, ADMIN_PASSWORD
|
||||
from src.ui.admin_ui import AdminApp # Импорт интерфейса администратора
|
||||
from database.db_events import create_user, check_user
|
||||
from src.ui.user_ui import UserApp
|
||||
|
||||
class DogAcademyApp:
|
||||
def __init__(self, root):
|
||||
self.root = root
|
||||
self.root.title("Dog Academy Game")
|
||||
self.root.geometry("1920x1080")
|
||||
self.root.configure(bg=BACKGROUND_COLOR)
|
||||
self.current_frame = None
|
||||
self.show_main_menu()
|
||||
|
||||
def clear_frame(self):
|
||||
"""Очистить текущий фрейм."""
|
||||
if self.current_frame:
|
||||
self.current_frame.destroy()
|
||||
|
||||
def show_main_menu(self):
|
||||
"""Показать главное меню с названием игры и кнопками."""
|
||||
self.clear_frame()
|
||||
self.current_frame = tk.Frame(self.root, bg=BACKGROUND_COLOR)
|
||||
self.current_frame.pack(expand=True)
|
||||
|
||||
# Название игры
|
||||
title = tk.Label(
|
||||
self.current_frame,
|
||||
text="Dog Academy Game",
|
||||
bg=BACKGROUND_COLOR,
|
||||
fg=PRIMARY_COLOR,
|
||||
font=BIG_FONT,
|
||||
)
|
||||
title.pack(pady=50)
|
||||
|
||||
# Кнопка "Войти"
|
||||
login_button = tk.Button(
|
||||
self.current_frame,
|
||||
text="Войти",
|
||||
bg=BUTTON_COLOR,
|
||||
fg=BUTTON_TEXT_COLOR,
|
||||
font=FONT,
|
||||
command=self.show_login_screen,
|
||||
)
|
||||
login_button.pack(pady=20)
|
||||
|
||||
# Кнопка "Зарегистрироваться"
|
||||
register_button = tk.Button(
|
||||
self.current_frame,
|
||||
text="Зарегистрироваться",
|
||||
bg=BUTTON_COLOR,
|
||||
fg=BUTTON_TEXT_COLOR,
|
||||
font=FONT,
|
||||
command=self.show_registration_screen,
|
||||
)
|
||||
register_button.pack(pady=20)
|
||||
|
||||
def show_login_screen(self):
|
||||
"""Показать экран авторизации."""
|
||||
self.clear_frame()
|
||||
self.current_frame = tk.Frame(self.root, bg=BACKGROUND_COLOR)
|
||||
self.current_frame.pack(expand=True)
|
||||
|
||||
# Заголовок
|
||||
title = tk.Label(
|
||||
self.current_frame,
|
||||
text="Авторизация",
|
||||
bg=BACKGROUND_COLOR,
|
||||
fg=PRIMARY_COLOR,
|
||||
font=BIG_FONT,
|
||||
)
|
||||
title.pack(pady=50)
|
||||
|
||||
# Логин
|
||||
self.login_entry = tk.Entry(self.current_frame, font=FONT)
|
||||
self.login_entry.pack(pady=10)
|
||||
|
||||
# Пароль
|
||||
self.password_entry = tk.Entry(self.current_frame, show="*", font=FONT)
|
||||
self.password_entry.pack(pady=10)
|
||||
|
||||
# Кнопка "Показать пароль"
|
||||
show_password_button = tk.Button(
|
||||
self.current_frame,
|
||||
text="Показать пароль",
|
||||
bg=BUTTON_COLOR,
|
||||
fg=BUTTON_TEXT_COLOR,
|
||||
font=FONT,
|
||||
command=self.toggle_password,
|
||||
)
|
||||
show_password_button.pack(pady=10)
|
||||
|
||||
# Кнопка "Войти"
|
||||
login_button = tk.Button(
|
||||
self.current_frame,
|
||||
text="Войти",
|
||||
bg=BUTTON_COLOR,
|
||||
fg=BUTTON_TEXT_COLOR,
|
||||
font=FONT,
|
||||
command=self.login_user,
|
||||
)
|
||||
login_button.pack(pady=20)
|
||||
|
||||
# Кнопка "Вернуться на главную"
|
||||
back_button = tk.Button(
|
||||
self.current_frame,
|
||||
text="Вернуться на главную",
|
||||
bg=BUTTON_COLOR,
|
||||
fg=BUTTON_TEXT_COLOR,
|
||||
font=FONT,
|
||||
command=self.show_main_menu,
|
||||
)
|
||||
back_button.pack(pady=20)
|
||||
|
||||
def toggle_password(self):
|
||||
"""Переключение видимости пароля."""
|
||||
if self.password_entry.cget('show') == '*':
|
||||
self.password_entry.config(show='')
|
||||
else:
|
||||
self.password_entry.config(show='*')
|
||||
|
||||
def login_user(self):
|
||||
"""Проверка данных для авторизации."""
|
||||
login = self.login_entry.get()
|
||||
password = self.password_entry.get()
|
||||
|
||||
if login == ADMIN_LOGIN and password == ADMIN_PASSWORD:
|
||||
messagebox.showinfo("Успех", "Вы успешно авторизованы как администратор!")
|
||||
self.show_admin_panel() # Переходим к админ-панели
|
||||
elif check_user(login, password):
|
||||
messagebox.showinfo("Успех", "Вы успешно авторизованы!")
|
||||
self.show_user_dashboard() # Переходим к панели пользователя
|
||||
else:
|
||||
messagebox.showerror("Ошибка", "Неверные данные. Попробуйте снова.")
|
||||
|
||||
def show_admin_panel(self):
|
||||
"""Отображение интерфейса администратора."""
|
||||
self.clear_frame()
|
||||
AdminApp(self.root) # Создаем экземпляр админ-панели
|
||||
|
||||
def show_registration_screen(self):
|
||||
"""Показать экран регистрации."""
|
||||
self.clear_frame()
|
||||
self.current_frame = tk.Frame(self.root, bg=BACKGROUND_COLOR)
|
||||
self.current_frame.pack(expand=True)
|
||||
|
||||
# Заголовок
|
||||
title = tk.Label(
|
||||
self.current_frame,
|
||||
text="Регистрация",
|
||||
bg=BACKGROUND_COLOR,
|
||||
fg=PRIMARY_COLOR,
|
||||
font=BIG_FONT,
|
||||
)
|
||||
title.pack(pady=50)
|
||||
|
||||
# Логин
|
||||
self.reg_login_entry = tk.Entry(self.current_frame, font=FONT)
|
||||
self.reg_login_entry.pack(pady=10)
|
||||
|
||||
# Пароль
|
||||
self.reg_password_entry = tk.Entry(self.current_frame, show="*", font=FONT)
|
||||
self.reg_password_entry.pack(pady=10)
|
||||
|
||||
# Кнопка "Показать пароль"
|
||||
show_password_button = tk.Button(
|
||||
self.current_frame,
|
||||
text="Показать пароль",
|
||||
bg=BUTTON_COLOR,
|
||||
fg=BUTTON_TEXT_COLOR,
|
||||
font=FONT,
|
||||
command=self.toggle_registration_password,
|
||||
)
|
||||
show_password_button.pack(pady=10)
|
||||
|
||||
# Кнопка "Зарегистрироваться"
|
||||
register_button = tk.Button(
|
||||
self.current_frame,
|
||||
text="Зарегистрироваться",
|
||||
bg=BUTTON_COLOR,
|
||||
fg=BUTTON_TEXT_COLOR,
|
||||
font=FONT,
|
||||
command=self.register_user,
|
||||
)
|
||||
register_button.pack(pady=20)
|
||||
|
||||
# Кнопка "Вернуться на главную"
|
||||
back_button = tk.Button(
|
||||
self.current_frame,
|
||||
text="Вернуться на главную",
|
||||
bg=BUTTON_COLOR,
|
||||
fg=BUTTON_TEXT_COLOR,
|
||||
font=FONT,
|
||||
command=self.show_main_menu,
|
||||
)
|
||||
back_button.pack(pady=20)
|
||||
|
||||
def toggle_registration_password(self):
|
||||
"""Переключение видимости пароля для регистрации."""
|
||||
if self.reg_password_entry.cget('show') == '*':
|
||||
self.reg_password_entry.config(show='')
|
||||
else:
|
||||
self.reg_password_entry.config(show='*')
|
||||
|
||||
def register_user(self):
|
||||
"""Регистрация нового пользователя."""
|
||||
login = self.reg_login_entry.get()
|
||||
password = self.reg_password_entry.get()
|
||||
|
||||
if login and password:
|
||||
create_user(login, password)
|
||||
messagebox.showinfo("Успех", "Вы успешно зарегистрированы!")
|
||||
self.show_login_screen()
|
||||
else:
|
||||
messagebox.showerror("Ошибка", "Пожалуйста, заполните все поля.")
|
||||
|
||||
def show_user_dashboard(self):
|
||||
"""Перейти к главному меню пользователя после авторизации."""
|
||||
UserApp(self.root, self)
|
||||
|
||||
56
src/ui/user_ui.py
Normal file
56
src/ui/user_ui.py
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
import tkinter as tk
|
||||
from config import BACKGROUND_COLOR, PRIMARY_COLOR, BUTTON_COLOR, BUTTON_TEXT_COLOR, FONT
|
||||
|
||||
class UserApp:
|
||||
def __init__(self, root, dog_academy_app):
|
||||
self.root = root
|
||||
self.dog_academy_app = dog_academy_app # Сохраняем ссылку на DogAcademyApp
|
||||
self.show_user_dashboard()
|
||||
|
||||
def show_user_dashboard(self):
|
||||
"""Показать интерфейс пользователя."""
|
||||
self.clear_frame()
|
||||
self.current_frame = tk.Frame(self.root, bg=BACKGROUND_COLOR)
|
||||
self.current_frame.pack(expand=True)
|
||||
|
||||
# Заголовок
|
||||
title = tk.Label(
|
||||
self.current_frame,
|
||||
text="Главное меню",
|
||||
bg=BACKGROUND_COLOR,
|
||||
fg=PRIMARY_COLOR,
|
||||
font=FONT,
|
||||
)
|
||||
title.pack(pady=50)
|
||||
|
||||
# Кнопка "Играть"
|
||||
play_button = tk.Button(
|
||||
self.current_frame,
|
||||
text="Играть",
|
||||
bg=BUTTON_COLOR,
|
||||
fg=BUTTON_TEXT_COLOR,
|
||||
font=FONT,
|
||||
command=self.play_game,
|
||||
)
|
||||
play_button.pack(pady=20)
|
||||
|
||||
# Кнопка "Выход"
|
||||
logout_button = tk.Button(
|
||||
self.current_frame,
|
||||
text="Выход",
|
||||
bg=BUTTON_COLOR,
|
||||
fg=BUTTON_TEXT_COLOR,
|
||||
font=FONT,
|
||||
command=self.dog_academy_app.show_main_menu, # Вызываем метод из DogAcademyApp
|
||||
)
|
||||
logout_button.pack(pady=20)
|
||||
|
||||
def play_game(self):
|
||||
"""Запуск игры."""
|
||||
# TODO: Логика игры
|
||||
pass
|
||||
|
||||
def clear_frame(self):
|
||||
"""Очистить текущий фрейм."""
|
||||
if hasattr(self, 'current_frame') and self.current_frame:
|
||||
self.current_frame.destroy()
|
||||
Loading…
Add table
Add a link
Reference in a new issue