From 00e0b45a731a6de8dff4106ec8686d70189ca182 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Sat, 6 Nov 2021 17:35:41 +0000 Subject: keep logged in, doing it better like this instead --- apioforum/__init__.py | 4 ---- apioforum/auth.py | 10 +++++++++- apioforum/templates/auth/login.html | 7 +++++-- apioforum/templates/auth/register.html | 7 +++++-- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/apioforum/__init__.py b/apioforum/__init__.py index 037afd7..b9077a2 100644 --- a/apioforum/__init__.py +++ b/apioforum/__init__.py @@ -65,10 +65,6 @@ def create_app(): def md_render(s): return render(s) - @app.before_request - def permanent_session(): - session.permanent = True - app.add_url_rule("/",endpoint="index") return app diff --git a/apioforum/auth.py b/apioforum/auth.py index 39cf1f8..8864fc0 100644 --- a/apioforum/auth.py +++ b/apioforum/auth.py @@ -31,6 +31,9 @@ def login(): if err is None: session.clear() session['user'] = username + if 'keep_logged_in' in request.form: + session['keep_logged_in']=True + session.permanent = True flash("logged in successfully") return redirect(get_next()) @@ -65,8 +68,11 @@ def register(): (username,generate_password_hash(password)) ) db.commit() - flash("successfully created account") session['user'] = username + if 'keep_logged_in' in request.form: + session['keep_logged_in'] = True + session.permanent = True + flash("successfully created account") return redirect(get_next()) flash(err) @@ -82,6 +88,8 @@ def logout(): @bp.before_app_request def load_user(): username = session.get("user") + if session.get("keep_logged_in",False): + session.permanent = True if username is None: g.user = None g.user_info = None diff --git a/apioforum/templates/auth/login.html b/apioforum/templates/auth/login.html index 3e69134..89f490f 100644 --- a/apioforum/templates/auth/login.html +++ b/apioforum/templates/auth/login.html @@ -6,12 +6,15 @@ {% block content %}

log in using an existing account here. if you don't already have an account, register first instead.

- +
- +
+ + +
{% endblock %} diff --git a/apioforum/templates/auth/register.html b/apioforum/templates/auth/register.html index 5d27b90..082a95b 100644 --- a/apioforum/templates/auth/register.html +++ b/apioforum/templates/auth/register.html @@ -6,12 +6,15 @@ {% block content %}

create a new account here. if you already have an account, login instead.

- +
- +
+ + +
{% endblock %} -- cgit v1.2.3