Refonte domo91
This commit is contained in:
101
domo91.py
101
domo91.py
@@ -235,6 +235,45 @@ def ajouter_utilisateur(utilisateur, mot_de_passe, role, lieu, expiration):
|
||||
except Exception as e:
|
||||
return False, f"⚠️ Erreur : {e}"
|
||||
|
||||
def afficher_gestion_expiration(conn):
|
||||
st.subheader("🔐 Gestion des expirations d'accès")
|
||||
|
||||
# Récupérer les utilisateurs avec leurs dates d'expiration
|
||||
cursor = conn.cursor(dictionary=True)
|
||||
cursor.execute("SELECT Id, utilisateur, Expiration FROM MotsDePasse")
|
||||
users = cursor.fetchall()
|
||||
cursor.close()
|
||||
|
||||
df = pd.DataFrame(users)
|
||||
df['Expiration'] = pd.to_datetime(df['Expiration']).dt.date
|
||||
|
||||
for _, row in df.iterrows():
|
||||
est_expire = row['Expiration'] < date.today()
|
||||
fond = "#ffe6e6" if est_expire else "#f8f9fa"
|
||||
with st.container():
|
||||
st.markdown(f"<div style='background-color:{fond}; padding:10px; border-radius:8px;'>",
|
||||
unsafe_allow_html=True)
|
||||
col1, col2, col3 = st.columns([4, 2, 1])
|
||||
with col1:
|
||||
st.markdown(f"**Utilisateur :** {row['utilisateur']}")
|
||||
if est_expire:
|
||||
st.markdown("<span style='color:red; font-weight:bold;'>⛔ Accès expiré</span>",
|
||||
unsafe_allow_html=True)
|
||||
|
||||
with col2:
|
||||
new_date = st.date_input("Expiration", row['Expiration'], key=f"exp_{row['Id']}")
|
||||
with col3:
|
||||
if st.button("✅", key=f"save_{row['Id']}"):
|
||||
try:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("UPDATE MotsDePasse SET Expiration = %s WHERE Id = %s",
|
||||
(new_date, row['Id']))
|
||||
conn.commit()
|
||||
st.success(f"✅ {row['utilisateur']} mis à jour")
|
||||
cursor.close()
|
||||
except Exception as e:
|
||||
st.error(f"Erreur : {e}")
|
||||
|
||||
# 📄 Affichage bouton PDF si une date est choisie
|
||||
site_pdf = (
|
||||
st.session_state.get("lieu_autorise")
|
||||
@@ -627,46 +666,8 @@ if st.session_state["authenticated"]:
|
||||
elif onglet == "Entretien":
|
||||
st.markdown("## 🧰 Gestion des sondes en entretien")
|
||||
|
||||
# --- Gérer les expirations comptes ---
|
||||
def afficher_gestion_expiration(conn):
|
||||
st.subheader("🔐 Gestion des expirations d'accès")
|
||||
|
||||
# Récupérer les utilisateurs avec leurs dates d'expiration
|
||||
cursor = conn.cursor(dictionary=True)
|
||||
cursor.execute("SELECT Id, utilisateur, Expiration FROM MotsDePasse")
|
||||
users = cursor.fetchall()
|
||||
cursor.close()
|
||||
|
||||
df = pd.DataFrame(users)
|
||||
df['Expiration'] = pd.to_datetime(df['Expiration']).dt.date
|
||||
|
||||
for _, row in df.iterrows():
|
||||
est_expire = row['Expiration'] < date.today()
|
||||
fond = "#ffe6e6" if est_expire else "#f8f9fa" # rouge clair si expiré, gris clair sinon
|
||||
with st.container():
|
||||
st.markdown(f"<div style='background-color:{fond}; padding:10px; border-radius:8px;'>",
|
||||
unsafe_allow_html=True)
|
||||
col1, col2, col3 = st.columns([4, 2, 1])
|
||||
with col1:
|
||||
st.markdown(f"**Utilisateur :** {row['utilisateur']}")
|
||||
if est_expire:
|
||||
st.markdown("<span style='color:red; font-weight:bold;'>⛔ Accès expiré</span>",
|
||||
unsafe_allow_html=True)
|
||||
|
||||
with col2:
|
||||
new_date = st.date_input("Expiration", row['Expiration'], key=f"exp_{row['Id']}")
|
||||
with col3:
|
||||
if st.button("✅", key=f"save_{row['Id']}"):
|
||||
try:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("UPDATE MotsDePasse SET Expiration = %s WHERE Id = %s",
|
||||
(new_date, row['Id']))
|
||||
conn.commit()
|
||||
st.success(f"✅ {row['utilisateur']} mis à jour")
|
||||
cursor.close()
|
||||
except Exception as e:
|
||||
st.error(f"Erreur : {e}")
|
||||
st.markdown("</div><br>", unsafe_allow_html=True)
|
||||
st.markdown("</div><br>", unsafe_allow_html=True)
|
||||
role = st.session_state.get("role", "utilisateur")
|
||||
lieu = st.session_state.get("lieu_autorise") if role != "superviseur" else st.selectbox("Choisir un lieu :",
|
||||
["Saclay", "Meudon"])
|
||||
@@ -709,16 +710,6 @@ if st.session_state["authenticated"]:
|
||||
except Exception as e:
|
||||
st.error(f"Erreur lors du chargement des sondes : {e}")
|
||||
|
||||
# 👉 Gestion des expirations visibles uniquement pour les superviseurs
|
||||
if role == "superviseur":
|
||||
try:
|
||||
conn = mysql.connector.connect(**db_config)
|
||||
afficher_gestion_expiration(conn)
|
||||
conn.close()
|
||||
except Exception as e:
|
||||
st.error(f"Erreur lors du chargement des comptes : {e}")
|
||||
|
||||
|
||||
# --- ONGLET TRAFFIC ------
|
||||
elif onglet == "Traffic":
|
||||
st.markdown("## 🚦 Connexions récentes")
|
||||
@@ -778,14 +769,18 @@ if st.session_state["authenticated"]:
|
||||
cursor.execute("SELECT utilisateur, role, Lieu, Expiration FROM MotsDePasse ORDER BY utilisateur")
|
||||
users = cursor.fetchall()
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
if users:
|
||||
import pandas as pd
|
||||
|
||||
df_users = pd.DataFrame(users)
|
||||
st.dataframe(df_users)
|
||||
else:
|
||||
st.info("Aucun utilisateur trouvé.")
|
||||
|
||||
# ✅ Appel de la gestion des expirations
|
||||
afficher_gestion_expiration(conn)
|
||||
conn.close()
|
||||
|
||||
except Exception as e:
|
||||
st.error(f"Erreur lors du chargement des utilisateurs : {e}")
|
||||
st.error(f"Erreur lors du chargement des utilisateurs : {e}")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user