-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
64 lines (51 loc) · 2.06 KB
/
main.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from tkinter import *
from tkinter import messagebox
from expediente import ExpedienteWindow
import connection as con
from signup import SignupWindow
import customtkinter as ct
def main():
principalWindow()
def principalWindow():
win = ct.CTk()
ct.set_appearance_mode("light")
win.title("Login")
etiTitle = ct.CTkLabel(win, text="Login", font=("Arial", 20, "bold"))
etiUsername = ct.CTkLabel(win, text="Username")
inputUsername = ct.CTkEntry(win)
etiPassword = ct.CTkLabel(win, text="Password")
inputPassword = ct.CTkEntry(win, show = "*")
buttonLogin = ct.CTkButton(win, text="Login", command= lambda: login(inputPassword, inputUsername, win), width=100)
buttonCrearUsuario = ct.CTkButton(win, text="Crear Usuario", width=100, command= lambda: SignupWindow(win))
etiTitle.pack(pady=5)
etiUsername.pack()
inputUsername.pack(pady=5)
etiPassword.pack()
inputPassword.pack(pady=5)
buttonLogin.pack(pady=5)
buttonCrearUsuario.pack(pady=5)
win.geometry("300x250")
win.mainloop()
# Login function
def login(inputUsername, inputPassword, win):
usuario = inputUsername.get()
contrasena = inputPassword.get()
query = f"SELECT COUNT(*) FROM usuarios WHERE usuario='{usuario}' AND contrasena='{contrasena}'" # Query
results = con.connect(query)
query2 = f"SELECT administrador FROM usuarios WHERE usuario='{usuario}' AND contrasena='{contrasena}'"
results2 = con.connect(query2)
query3 = f"SELECT encargado_bodega FROM usuarios WHERE usuario='{usuario}' AND contrasena='{contrasena}'"
results3 = con.connect(query3)
try:
results2 = results2[0][0]
results3 = results3[0][0]
except:
pass
# None type data verification
if results is not None and results[0][0] == 1:
ExpedienteWindow(win, results2, results3, inputUsername)
# Error message if credentials do not match
else:
messagebox.showerror("Error de inicio de sesión", "Usuario o contraseña incorrectos")
if __name__ == '__main__':
main()