Add app.py
This commit is contained in:
parent
596843ef92
commit
6aa7fc2fbc
|
|
@ -0,0 +1,50 @@
|
||||||
|
import os
|
||||||
|
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
from flask import Flask, redirect, render_template, request, session, url_for
|
||||||
|
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
app.secret_key = os.environ["SECRET_KEY"]
|
||||||
|
|
||||||
|
SITE_PASSWORD = os.environ["SITE_PASSWORD"]
|
||||||
|
|
||||||
|
|
||||||
|
@app.after_request
|
||||||
|
def add_noindex_header(response):
|
||||||
|
response.headers["X-Robots-Tag"] = "noindex, nofollow"
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/")
|
||||||
|
def index():
|
||||||
|
if not session.get("authenticated"):
|
||||||
|
return redirect(url_for("login"))
|
||||||
|
return render_template("dashboard.html")
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/login", methods=["GET", "POST"])
|
||||||
|
def login():
|
||||||
|
if session.get("authenticated"):
|
||||||
|
return redirect(url_for("index"))
|
||||||
|
|
||||||
|
error = None
|
||||||
|
if request.method == "POST":
|
||||||
|
if request.form.get("password") == SITE_PASSWORD:
|
||||||
|
session["authenticated"] = True
|
||||||
|
return redirect(url_for("index"))
|
||||||
|
error = "Wrong password."
|
||||||
|
|
||||||
|
return render_template("login.html", error=error)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/logout")
|
||||||
|
def logout():
|
||||||
|
session.clear()
|
||||||
|
return redirect(url_for("login"))
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/robots.txt")
|
||||||
|
def robots():
|
||||||
|
return "User-agent: *\nDisallow: /\n", 200, {"Content-Type": "text/plain"}
|
||||||
Loading…
Reference in New Issue