From d41484e69ab227de01e648ba65579ea1d3a109fa Mon Sep 17 00:00:00 2001 From: s3lph Date: Fri, 12 Apr 2024 23:43:01 +0200 Subject: [PATCH] fix: improve auto logout --- CHANGELOG.md | 14 ++++++++++++++ matemat/__init__.py | 2 +- matemat/db/facade.py | 2 +- matemat/webserver/pagelets/buy.py | 2 +- matemat/webserver/pagelets/logout.py | 6 ++++-- matemat/webserver/pagelets/main.py | 17 +++++++++-------- templates/base.html | 18 ++++++++++++++++++ templates/productlist.html | 21 --------------------- 8 files changed, 48 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eb5d524..b2759d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,19 @@ # Matemat Changelog + +## Version 0.3.11 + +Improve auto-logout + +### Changes + + +- Show purchase overlay after logout +- Fix state of auto-logout checkbox after changing user settings + + + + ## Version 0.3.10 diff --git a/matemat/__init__.py b/matemat/__init__.py index a32ff42..5616a14 100644 --- a/matemat/__init__.py +++ b/matemat/__init__.py @@ -1,2 +1,2 @@ -__version__ = '0.3.10' +__version__ = '0.3.11' diff --git a/matemat/db/facade.py b/matemat/db/facade.py index 4a9d8dd..4bfed61 100644 --- a/matemat/db/facade.py +++ b/matemat/db/facade.py @@ -340,7 +340,7 @@ class MatematDatabase(object): user.balance = balance user.is_admin = is_admin user.is_member = is_member - user.logout_after_purchase = user.logout_after_purchase + user.logout_after_purchase = logout_after_purchase user.receipt_pref = receipt_pref def delete_user(self, user: User) -> None: diff --git a/matemat/webserver/pagelets/buy.py b/matemat/webserver/pagelets/buy.py index a01bb45..84b7855 100644 --- a/matemat/webserver/pagelets/buy.py +++ b/matemat/webserver/pagelets/buy.py @@ -37,7 +37,7 @@ def buy(): stock_provider.update_stock(product, -1) # Logout user if configured, logged in via touchkey and no price entry input was shown if user.logout_after_purchase and authlevel < 2 and not product.custom_price: - redirect('/logout') + redirect(f'/logout?lastaction=buy&lastproduct={pid}&lastprice={price}') # Redirect to the main page (where this request should have come from) redirect(f'/?lastaction=buy&lastproduct={pid}&lastprice={price}') redirect('/') diff --git a/matemat/webserver/pagelets/logout.py b/matemat/webserver/pagelets/logout.py index d4094bf..66baa38 100644 --- a/matemat/webserver/pagelets/logout.py +++ b/matemat/webserver/pagelets/logout.py @@ -1,4 +1,6 @@ -from bottle import get, post, redirect +import urllib.parse + +from bottle import get, post, redirect, request from matemat.webserver import session @@ -16,4 +18,4 @@ def logout(): # Reset the authlevel session variable (0 = none, 1 = touchkey, 2 = password login) session.put(session_id, 'authentication_level', 0) # Redirect to the main page, showing the user list - redirect('/') + redirect(f'/?{urllib.parse.urlencode(request.query)}') diff --git a/matemat/webserver/pagelets/main.py b/matemat/webserver/pagelets/main.py index 251ca03..1dd610b 100644 --- a/matemat/webserver/pagelets/main.py +++ b/matemat/webserver/pagelets/main.py @@ -16,6 +16,13 @@ def main_page(): session_id: str = session.start() now = str(int(datetime.utcnow().timestamp())) with MatematDatabase(config['DatabaseFile']) as db: + # Fetch the list of products to display + products = db.list_products() + if request.params.lastproduct: + lastproduct = db.get_product(request.params.lastproduct) + else: + lastproduct = None + lastprice = int(request.params.lastprice) if request.params.lastprice else None # Check whether a user is logged in if session.has(session_id, 'authenticated_user'): # Fetch the user id and authentication level (touchkey vs password) from the session storage @@ -24,13 +31,6 @@ def main_page(): # Fetch the user object from the database (for name display, price calculation and admin check) users = db.list_users() user = db.get_user(uid) - # Fetch the list of products to display - products = db.list_products() - if request.params.lastproduct: - lastproduct = db.get_product(request.params.lastproduct) - else: - lastproduct = None - lastprice = int(request.params.lastprice) if request.params.lastprice else None # Prepare a response with a jinja2 template return template.render('productlist.html', authuser=user, users=users, products=products, authlevel=authlevel, @@ -44,4 +44,5 @@ def main_page(): users = db.list_users(with_touchkey=True) return template.render('userlist.html', users=users, setupname=config['InstanceName'], now=now, - signup=(config.get('SignupEnabled', '0') == '1')) + signup=(config.get('SignupEnabled', '0') == '1'), + lastaction=request.params.lastaction, lastprice=lastprice, lastproduct=lastproduct) diff --git a/templates/base.html b/templates/base.html index 5fbcfb0..3b42bd4 100644 --- a/templates/base.html +++ b/templates/base.html @@ -13,6 +13,24 @@ {% block overlay %} +{% if lastaction is defined and lastaction is not none %} +{% if lastaction == 'buy' %} + +{% elif lastaction == 'deposit' %} + +{% endif %} +{% endif %} {% endblock %}
diff --git a/templates/productlist.html b/templates/productlist.html index 93e1227..4080312 100644 --- a/templates/productlist.html +++ b/templates/productlist.html @@ -6,27 +6,6 @@ {{ super() }} {% endblock %} -{% block overlay %} -{% if lastaction is not none %} -{% if lastaction == 'buy' %} - -{% elif lastaction == 'deposit' %} - -{% endif %} -{% endif %} -{% endblock %} - {% block main %} {# Show the users current balance #}