-
-
Save parzibyte/31a41dcac825e03734a1c6b4433ee965 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Un "middleware" que se ejecuta antes de responder a cualquier ruta. Aquí verificamos si el usuario ha iniciado sesión | |
@app.before_request | |
def antes_de_cada_peticion(): | |
ruta = request.path | |
# Si no ha iniciado sesión y no quiere ir a algo relacionado al login, lo redireccionamos al login | |
if not 'usuario' in session and ruta != "/login" and ruta != "/hacer_login" and ruta != "/logout" and not ruta.startswith("/static"): | |
flash("Inicia sesión para continuar") | |
return redirect("/login") | |
# Si ya ha iniciado, no hacemos nada, es decir lo dejamos pasar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment