From a9d0a707f635f3881ddae72552ed25ebd44eabf1 Mon Sep 17 00:00:00 2001 From: david Date: Sun, 25 Aug 2013 18:38:39 +0200 Subject: [PATCH] devel... --- app.py | 56 ++++++++++++++++++++++++++++++------------- templates/footer.html | 2 +- templates/home.html | 6 +++++ templates/layout.html | 19 +++++++++++++++ templates/login.html | 11 +++++++++ templates/status.html | 8 ++++--- 6 files changed, 82 insertions(+), 20 deletions(-) create mode 100644 templates/home.html create mode 100644 templates/layout.html create mode 100644 templates/login.html diff --git a/app.py b/app.py index c7436f2..83e9027 100755 --- a/app.py +++ b/app.py @@ -1,28 +1,52 @@ #!/usr/bin/env python -from flask import Flask, render_template, redirect, url_for, abort, request +from flask import Flask, render_template, redirect, url_for, request, session import openvpnstatus app = Flask(__name__) -@app.route('/status', methods=['GET', 'POST']) +@app.route("/") +def index(): + if "username" in session: + return render_template("home.html", username = session["username"]) + return render_template("login.html") + +@app.route("/login", methods = ["GET", "POST"]) +def login(): + if request.method == "POST": + session["username"] = request.form["username"] + if 'login' in request.referrer: + return redirect(url_for('index')) + else: + return redirect(request.referrer) + return render_template("login.html") + +@app.route("/logout") +def logout(): + session.pop("username", None) + return redirect(url_for("index")) + +@app.route("/status") def status(): - o = openvpnstatus.openvpnstatus() - return render_template('status.html', connections = o.connections, routes = o.routes) + if "username" in session: + o = openvpnstatus.openvpnstatus() + return render_template("status.html", connections = o.connections, routes = o.routes, username = session["username"]) + return render_template("login.html") -@app.route('/socialnerds') -def redir(): - return redirect('https://www.socialnerds.org') - -@app.route('/form', methods=['GET', 'POST']) +@app.route("/form", methods=["GET", "POST"]) def formular(): - something = "iatren" - if request.method == 'POST': - value = request.form['textfield'] - return render_template("footer.html", test=value, test2=value) - else: - return render_template("form.html") + if "username" in session: + something = "iatren" + if request.method == "POST": + value = request.form["textfield"] + return render_template("footer.html", test=value, test2=value) + else: + return render_template("form.html") + return render_template("login.html") -if __name__ == '__main__': +app.secret_key = 'A0Zr98j/3yX R~XHH!jmN]LWX/,?RT' + + +if __name__ == "__main__": app.run(debug=True) diff --git a/templates/footer.html b/templates/footer.html index c7c584f..5e0dc4d 100644 --- a/templates/footer.html +++ b/templates/footer.html @@ -5,6 +5,6 @@ Hello, my dear {{ test2 }}!


-form | status | socialnerds +form | status {% endif %} {% endblock %} diff --git a/templates/home.html b/templates/home.html new file mode 100644 index 0000000..9b4a3a2 --- /dev/null +++ b/templates/home.html @@ -0,0 +1,6 @@ +{% extends "layout.html" %} +{% block title %}home{% endblock %} +{% block content %} +

Home

+Hello, my dear {{ username }}! +{% endblock %} diff --git a/templates/layout.html b/templates/layout.html new file mode 100644 index 0000000..a13fa1b --- /dev/null +++ b/templates/layout.html @@ -0,0 +1,19 @@ + + + + {% block head %} + {% block title %}socialnerds.org{% endblock %} + {% endblock %} + + +
+ {% block content %}{% endblock %} +
+ + + diff --git a/templates/login.html b/templates/login.html new file mode 100644 index 0000000..380e750 --- /dev/null +++ b/templates/login.html @@ -0,0 +1,11 @@ +{% extends "layout.html" %} +{% block title %}login{% endblock %} +{% block content %} +

Login

+Please login:

+
+username:
+password:
+ +
+{% endblock %} diff --git a/templates/status.html b/templates/status.html index 2f7f961..384607e 100644 --- a/templates/status.html +++ b/templates/status.html @@ -1,7 +1,8 @@ - -OpenVPN Status +{% extends "layout.html" %} +{% block title %}status{% endblock %} +{% block content %}

OpenVPN Status

-
+

Connections:

@@ -24,3 +25,4 @@ {% endfor %} +{% endblock %}