Répartion du fichier users

This commit is contained in:
2025-11-19 00:39:26 +01:00
parent 0c1489ea6f
commit 788785d982
6 changed files with 82 additions and 594 deletions

View File

@@ -85,25 +85,33 @@ logout_button()
def get_pool():
load_dotenv()
host = os.getenv("DB_HOST")
port = int(os.getenv("MYSQL_PORT", "3306"))
user = os.getenv("DB_USER")
pwd = os.getenv("DB_PASSWORD")
db = os.getenv("DB_NAME")
port = int(os.getenv("MYSQL_PORT", "3306")) # ✅ valeur par défaut 3306
user = os.getenv("DB_USER2")
pwd = os.getenv("DB_PASSWORD2")
db = os.getenv("DB_NAME2")
# ✅ contrôle des variables indispensables
missing = [k for k, v in {
"DB_HOST": host, "MYSQL_PORT": port, "DB_USER": user, "DB_PASSWORD": pwd, "DB_NAME": db
"DB_HOST": host,
"DB_USER2": user,
"DB_PASSWORD2": pwd,
"DB_NAME2": db,
}.items() if v in (None, "")]
if missing:
raise RuntimeError(f"Variables manquantes dans .env : {', '.join(missing)}")
return pooling.MySQLConnectionPool(
pool_name="users_pool",
pool_size=5,
pool_reset_session=True,
host=host, port=port, user=user, password=pwd, database=db,
autocommit=True
host=host,
port=port,
user=user,
password=pwd,
database=db,
autocommit=True,
)
pool = get_pool()
# -----------------------
# Helpers SQL + validations
# -----------------------
@@ -300,7 +308,11 @@ def get_user_email_and_field(cnx, username: str, field: str):
# -----------------------
st.set_page_config(page_title="Acces.Utilisateurs", page_icon="👤", layout="wide")
st.title("Gestion des utilisateurs")
try:
pool = get_pool()
except Exception as e:
st.error(f"❌ Impossible d'initialiser le pool MySQL : {e}")
st.stop()
tab_list, tab_create, tab_edit, tab_security = st.tabs(["Liste", "Créer", "Modifier", "Sécurité"])
# -----------------------