"""Authentication module for Water Police application.""" import streamlit as st import streamlit_authenticator as stauth import yaml from pathlib import Path CONFIG_FILE = Path(__file__).parent.parent / "config.yaml" def load_config(): """Carga la configuración desde config.yaml""" with open(CONFIG_FILE, encoding="utf-8") as file: return yaml.safe_load(file) def save_config(config): """Guarda la configuración en config.yaml""" with open(CONFIG_FILE, "w", encoding="utf-8") as file: yaml.dump(config, file, default_flow_style=False, allow_unicode=True) def setup_authenticator(): """Configura y retorna el autenticador.""" config = load_config() # Hashear contraseñas si están en texto plano (primera ejecución) stauth.Hasher.hash_passwords(config["credentials"]) save_config(config) # Crear autenticador authenticator = stauth.Authenticate( config["credentials"], config["cookie"]["name"], config["cookie"]["key"], config["cookie"]["expiry_days"], ) return authenticator def render_login(authenticator): """Renderiza la pantalla de login con estilos CSS.""" # Estilos CSS para centrar y mejorar el diseño st.markdown(""" """, unsafe_allow_html=True) # Header con branding st.markdown("""
Sistema de Predicción de Riesgo Hídrico