-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth_window.py
49 lines (38 loc) · 1.63 KB
/
auth_window.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import tkinter as tk
from tkinter import messagebox
from db_connection import connect_to_db
from table_window import TableWindow
class AuthWindow:
"""Окно авторизации."""
def __init__(self, root):
self.root = root
self.root.title("Авторизация")
frame = tk.Frame(root)
frame.pack(padx=20, pady=20)
tk.Label(frame, text="Логин").pack(anchor="w", pady=5)
self.login_entry = tk.Entry(frame)
self.login_entry.pack(fill="x", pady=5)
tk.Label(frame, text="Пароль").pack(anchor="w", pady=5)
self.password_entry = tk.Entry(frame, show="*")
self.password_entry.pack(fill="x", pady=5)
tk.Button(frame, text="Войти", command=self.authenticate).pack(pady=10)
def authenticate(self):
"""Проверка логина и пароля."""
login = self.login_entry.get()
password = self.password_entry.get()
if not login or not password:
messagebox.showerror("Ошибка", "Заполните все поля!")
return
connection = connect_to_db()
if connection:
cursor = connection.cursor()
query = "SELECT id FROM users WHERE login = %s AND passwd = %s"
cursor.execute(query, (login, password))
result = cursor.fetchone()
connection.close()
if result:
user_id = result[0]
self.root.destroy()
TableWindow(user_id)
else:
messagebox.showerror("Ошибка", "Неверный логин или пароль!")