Projet_multi_stream_obs/methode1/mysqlco.py

95 lines
3.0 KiB
Python

from main import *
from tkinter import *
from tkinter import messagebox
import mysql.connector
class Mysql:
def __init__(self, root):
self.root = root
self.root.title("Launcher OBS Extension Multistreaming")
self.root.geometry("400x300")
self.root.grid_rowconfigure(0, weight=1)
self.root.grid_rowconfigure(1, weight=1)
self.root.grid_rowconfigure(2, weight=1)
self.root.grid_rowconfigure(3, weight=1)
self.root.grid_columnconfigure(0, weight=1)
self.root.grid_columnconfigure(1, weight=0)
self.root.grid_columnconfigure(2, weight=0)
self.root.grid_columnconfigure(3, weight=0)
def authenticate_user(self, username, password):
try:
cnx = mysql.connector.connect(user='root', password='',
host='127.0.0.1',
database='obs_project')
cur = cnx.cursor()
query = "SELECT * FROM utilisateurs WHERE username = %s AND password = %s"
cur.execute(query, (username, password))
user = cur.fetchone()
if user:
messagebox.showinfo("Validé", "Authentification réussi")
self.ouvrir_nouvelle_fenetre(username, password)
else:
messagebox.showerror("Erreur", "Authentification erroné")
except mysql.connector.Error as err:
messagebox.showerror("Erreur", f"Erreur: {err}")
finally:
cur.close()
cnx.close()
def ouvrir_nouvelle_fenetre(self, username, password):
if self.root.winfo_exists():
self.root.withdraw()
NouvelleFenetre(self.root, username, password)
def click_identifiant(self, event):
entry_identifiant.configure(state=NORMAL)
entry_identifiant.delete(0, END)
entry_identifiant.unbind('<Button-1>', self.click_identifiant)
def click_pass(self, event):
entry_pass.configure(state=NORMAL)
entry_pass.delete(0, END)
entry_pass.unbind('<Button-1>', self.click_pass)
def msg_call_back(self):
username = entry_identifiant.get()
password = entry_pass.get()
self.authenticate_user(username, password)
fenetre = Tk()
obj = Mysql(fenetre)
label = Label(fenetre, text="Connexion")
label.grid(row = 0, column= 0)
entry_identifiant = Entry(fenetre)
entry_identifiant.grid(row = 1, column=0)
entry_identifiant.focus()
entry_identifiant.insert(0, "Admin")
entry_identifiant.bind('<Button-1>', obj.click_identifiant)
entry_pass = Entry(fenetre, show='*')
entry_pass.grid(row = 2, column=0)
entry_pass.insert(0, "Admin")
entry_pass.bind('<Button-1>', obj.click_pass)
boutonconnexion = Button(fenetre, text="Connexion", command=obj.msg_call_back, activebackground = "green")
boutonconnexion.grid(row = 3, column = 0)
fenetre.mainloop()