diff options
-rw-r--r-- | apioforum/__init__.py | 4 | ||||
-rw-r--r-- | apioforum/auth.py | 10 | ||||
-rw-r--r-- | apioforum/templates/auth/login.html | 7 | ||||
-rw-r--r-- | 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 %} <p>log in using an existing account here. if you don't already have an account, <a href="{{url_for('auth.register')}}">register</a> first instead.</p> <form method="post"> - <label for="username">Username</label> + <label for="username">username</label> <input name="username" id="username" required> <br> - <label for="password">Password</label> + <label for="password">password</label> <input type="password" name="password" id="password" required> <br> + <input type="checkbox" name="keep_logged_in" id="keep_logged_in"> + <label for="keep_logged_in">keep me logged in</label> + <br> <input type="submit" value="login"> </form> {% 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 %} <p>create a new account here. if you already have an account, <a href="{{url_for('auth.login')}}">login</a> instead.</p> <form method="post"> - <label for="username">Username</label> + <label for="username">username</label> <input name="username" id="username" maxlength="20" required> <br> - <label for="password">Password</label> + <label for="password">password</label> <input type="password" name="password" id="password" required> <br> + <input type="checkbox" name="keep_logged_in" id="keep_logged_in"> + <label for="keep_logged_in">keep me logged in</label> + <br> <input type="submit" value="register"> </form> {% endblock %} |