from flask import Flask, request, redirect, url_for, session app=Flask(__name__) app.secret_key="salajane" users={"admin":"kala", "juku":"kala"} @app.route("/kodu") def home(): app.logger.info("Kasutaja aadressilt "+request.remote_addr) if "user" in session: return "tere, "+session["user"]+"! Logout" return "Tundmatu kasutaja. Logi sisse" @app.route("/login", methods=["GET", "POST"]) def login(): if request.method=="POST": username=request.form["username"] password=request.form["password"] if username in users and users[username]==password: session["user"]=username return "Tere, "+username return "Valed mandaadid" return """
""" @app.route("/logout") def logout(): session.pop("user", None) return redirect(url_for("home"))