commit ae47060409d7b499c673c0b0817bd020a87b3e5e Author: Michel Date: Mon May 12 18:14:16 2025 +0200 Initialisation du projet de gestion des inventaires multi-sites diff --git a/.env b/.env new file mode 100644 index 0000000..88e377a --- /dev/null +++ b/.env @@ -0,0 +1,4 @@ +DB_HOST=54.36.188.119 +DB_USER=michel +DB_PASSWORD=#SO2&1nf%mZ@jfh +DB_NAME=Commun \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/Ratio & inventaires.iml b/.idea/Ratio & inventaires.iml new file mode 100644 index 0000000..1a08513 --- /dev/null +++ b/.idea/Ratio & inventaires.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/dictionaries/project.xml b/.idea/dictionaries/project.xml new file mode 100644 index 0000000..aeaed86 --- /dev/null +++ b/.idea/dictionaries/project.xml @@ -0,0 +1,8 @@ + + + + acces + curdate + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..97194fb --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,19 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..2e9b9c9 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..0f30710 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Excel/Commun.xlsm b/Excel/Commun.xlsm new file mode 100644 index 0000000..8334130 Binary files /dev/null and b/Excel/Commun.xlsm differ diff --git a/Excel/login_utilisateur.txt b/Excel/login_utilisateur.txt new file mode 100644 index 0000000..8433fc5 --- /dev/null +++ b/Excel/login_utilisateur.txt @@ -0,0 +1 @@ +Sabrina \ No newline at end of file diff --git a/Excel/site_selectionne.txt b/Excel/site_selectionne.txt new file mode 100644 index 0000000..ad089bd --- /dev/null +++ b/Excel/site_selectionne.txt @@ -0,0 +1 @@ +Saclay \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/connexion.py b/connexion.py new file mode 100644 index 0000000..1230965 --- /dev/null +++ b/connexion.py @@ -0,0 +1,81 @@ +import tkinter as tk +from tkinter import messagebox +import mysql.connector +import os +import subprocess +from dotenv import load_dotenv + +# Charger les variables d'environnement +load_dotenv() + +DB_HOST = os.getenv("DB_HOST") +DB_USER = os.getenv("DB_USER") +DB_PASSWORD = os.getenv("DB_PASSWORD") +DB_NAME = os.getenv("DB_NAME") + + +def ouvrir_excel(site, login): + dossier_excel = os.path.join(os.path.dirname(__file__), "excel") + chemin_excel = os.path.join(dossier_excel, "Commun.xlsm") + subprocess.Popen(["start", chemin_excel], shell=True) + + # Écrit le nom du site + with open(os.path.join(dossier_excel, "site_selectionne.txt"), "w") as f: + f.write(site) + + # Écrit le nom de l'utilisateur connecté + with open(os.path.join(dossier_excel, "login_utilisateur.txt"), "w") as f: + f.write(login) + os.chdir(dossier_excel) # On se place dans le dossier pour lancer Excel + subprocess.Popen(["start", "Commun.xlsm"], shell=True) + +from datetime import date + +def verifier_connexion(): + login = entry_login.get() + mdp = entry_mdp.get() + + try: + conn = mysql.connector.connect( + host=DB_HOST, + user=DB_USER, + password=DB_PASSWORD, + database=DB_NAME + ) + cursor = conn.cursor() + + cursor.execute("SELECT Site, DateExpiration FROM AccesUtilisateurs WHERE NomUtilisateur=%s AND MotDePasse=%s", (login, mdp)) + result = cursor.fetchone() + + if result: + site, expiration = result + if expiration and expiration < date.today(): + messagebox.showerror("Compte expiré", f"Votre compte a expiré le {expiration}.") + else: + root.destroy() + ouvrir_excel(site, login) + else: + messagebox.showerror("Erreur", "Identifiants invalides.") + + except Exception as e: + messagebox.showerror("Erreur de connexion", str(e)) + + + +# Interface utilisateur +root = tk.Tk() +root.title("Connexion à l'inventaire") + +tk.Label(root, text="Nom d'utilisateur").grid(row=0, column=0) +tk.Label(root, text="Mot de passe").grid(row=1, column=0) + +entry_login = tk.Entry(root) +entry_mdp = tk.Entry(root, show="*") + +entry_login.grid(row=0, column=1) +entry_mdp.grid(row=1, column=1) + +tk.Button(root, text="Connexion", command=verifier_connexion).grid(row=2, columnspan=2, pady=10) + +root.mainloop() + diff --git a/gitignore.txt b/gitignore.txt new file mode 100644 index 0000000..2302ced --- /dev/null +++ b/gitignore.txt @@ -0,0 +1,6 @@ +.env +*.txt +__pycache__/ +*.pyc +*.log +.DS_Store