From e32815acc670428bdef698cdaec692cf5bcd8ae6 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Sat, 12 Jun 2021 22:58:01 +0000 Subject: auth pages less irritating --- apioforum/auth.py | 13 ++++++++++--- apioforum/templates/base.html | 18 +++++++++++++++--- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/apioforum/auth.py b/apioforum/auth.py index 49808ea..547f15e 100644 --- a/apioforum/auth.py +++ b/apioforum/auth.py @@ -8,6 +8,9 @@ import functools bp = Blueprint("auth", __name__, url_prefix="/auth") +def get_next(): + return request.args.get('next',url_for('index')) + @bp.route("/login",methods=('GET','POST')) def login(): if request.method == "POST": @@ -28,12 +31,14 @@ def login(): if err is None: session.clear() session['user'] = username - return redirect(url_for('auth.cool')) + flash("logged in successfully") + return redirect(get_next()) flash(err) return render_template("auth/login.html") + @bp.route("/register", methods=("GET","POST")) def register(): if request.method == "POST": @@ -58,7 +63,8 @@ def register(): db.commit() flash("successfully created account") session['user'] = username - return redirect(url_for("auth.cool")) + flash("registered successfully") + return redirect(get_next()) flash(err) @@ -67,7 +73,8 @@ def register(): @bp.route("/logout") def logout(): session.clear() - return redirect(url_for("auth.cool")) + flash("logged out successfully") + return redirect(get_next()) @bp.before_app_request def load_user(): diff --git a/apioforum/templates/base.html b/apioforum/templates/base.html index 847b8b2..f81f413 100644 --- a/apioforum/templates/base.html +++ b/apioforum/templates/base.html @@ -17,10 +17,22 @@ {% if g.user %}
  • {{ g.user }}
  • -
  • logout
  • +
  • + + logout + +
  • {% else %} -
  • login
  • -
  • register
  • +
  • + + login + +
  • +
  • + + register + +
  • {% endif %} -- cgit v1.2.3