forked from s3lph/matemat
fix: improve auto logout
This commit is contained in:
parent
c8243fd9d5
commit
d41484e69a
8 changed files with 48 additions and 34 deletions
14
CHANGELOG.md
14
CHANGELOG.md
|
@ -1,5 +1,19 @@
|
||||||
# Matemat Changelog
|
# Matemat Changelog
|
||||||
|
|
||||||
|
<!-- BEGIN RELEASE v0.3.11 -->
|
||||||
|
## Version 0.3.11
|
||||||
|
|
||||||
|
Improve auto-logout
|
||||||
|
|
||||||
|
### Changes
|
||||||
|
|
||||||
|
<!-- BEGIN CHANGES 0.3.11 -->
|
||||||
|
- Show purchase overlay after logout
|
||||||
|
- Fix state of auto-logout checkbox after changing user settings
|
||||||
|
<!-- END CHANGES 0.3.11 -->
|
||||||
|
|
||||||
|
<!-- END RELEASE v0.3.11 -->
|
||||||
|
|
||||||
<!-- BEGIN RELEASE v0.3.10 -->
|
<!-- BEGIN RELEASE v0.3.10 -->
|
||||||
## Version 0.3.10
|
## Version 0.3.10
|
||||||
|
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
|
|
||||||
__version__ = '0.3.10'
|
__version__ = '0.3.11'
|
||||||
|
|
|
@ -340,7 +340,7 @@ class MatematDatabase(object):
|
||||||
user.balance = balance
|
user.balance = balance
|
||||||
user.is_admin = is_admin
|
user.is_admin = is_admin
|
||||||
user.is_member = is_member
|
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
|
user.receipt_pref = receipt_pref
|
||||||
|
|
||||||
def delete_user(self, user: User) -> None:
|
def delete_user(self, user: User) -> None:
|
||||||
|
|
|
@ -37,7 +37,7 @@ def buy():
|
||||||
stock_provider.update_stock(product, -1)
|
stock_provider.update_stock(product, -1)
|
||||||
# Logout user if configured, logged in via touchkey and no price entry input was shown
|
# 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:
|
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 to the main page (where this request should have come from)
|
||||||
redirect(f'/?lastaction=buy&lastproduct={pid}&lastprice={price}')
|
redirect(f'/?lastaction=buy&lastproduct={pid}&lastprice={price}')
|
||||||
redirect('/')
|
redirect('/')
|
||||||
|
|
|
@ -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
|
from matemat.webserver import session
|
||||||
|
|
||||||
|
@ -16,4 +18,4 @@ def logout():
|
||||||
# Reset the authlevel session variable (0 = none, 1 = touchkey, 2 = password login)
|
# Reset the authlevel session variable (0 = none, 1 = touchkey, 2 = password login)
|
||||||
session.put(session_id, 'authentication_level', 0)
|
session.put(session_id, 'authentication_level', 0)
|
||||||
# Redirect to the main page, showing the user list
|
# Redirect to the main page, showing the user list
|
||||||
redirect('/')
|
redirect(f'/?{urllib.parse.urlencode(request.query)}')
|
||||||
|
|
|
@ -16,6 +16,13 @@ def main_page():
|
||||||
session_id: str = session.start()
|
session_id: str = session.start()
|
||||||
now = str(int(datetime.utcnow().timestamp()))
|
now = str(int(datetime.utcnow().timestamp()))
|
||||||
with MatematDatabase(config['DatabaseFile']) as db:
|
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
|
# Check whether a user is logged in
|
||||||
if session.has(session_id, 'authenticated_user'):
|
if session.has(session_id, 'authenticated_user'):
|
||||||
# Fetch the user id and authentication level (touchkey vs password) from the session storage
|
# 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)
|
# Fetch the user object from the database (for name display, price calculation and admin check)
|
||||||
users = db.list_users()
|
users = db.list_users()
|
||||||
user = db.get_user(uid)
|
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
|
# Prepare a response with a jinja2 template
|
||||||
return template.render('productlist.html',
|
return template.render('productlist.html',
|
||||||
authuser=user, users=users, products=products, authlevel=authlevel,
|
authuser=user, users=users, products=products, authlevel=authlevel,
|
||||||
|
@ -44,4 +44,5 @@ def main_page():
|
||||||
users = db.list_users(with_touchkey=True)
|
users = db.list_users(with_touchkey=True)
|
||||||
return template.render('userlist.html',
|
return template.render('userlist.html',
|
||||||
users=users, setupname=config['InstanceName'], now=now,
|
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)
|
||||||
|
|
|
@ -13,6 +13,24 @@
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
{% block overlay %}
|
{% block overlay %}
|
||||||
|
{% if lastaction is defined and lastaction is not none %}
|
||||||
|
{% if lastaction == 'buy' %}
|
||||||
|
<aside id="overlay">
|
||||||
|
<h2>{{ lastproduct.name }}</h2>
|
||||||
|
<img src="/static/upload/thumbnails/products/{{ lastproduct.id }}.png?cacheBuster={{ now }}" alt="Picture of {{ lastproduct.name }}" draggable="false"/>
|
||||||
|
{% if lastprice is not none %}
|
||||||
|
<div class="price">{{ lastprice|chf }}</div>
|
||||||
|
{% endif %}
|
||||||
|
</aside>
|
||||||
|
{% elif lastaction == 'deposit' %}
|
||||||
|
<aside id="overlay">
|
||||||
|
<h2>Deposit</h2>
|
||||||
|
{% if lastprice is not none %}
|
||||||
|
<div class="price">{{ lastprice|chf }}</div>
|
||||||
|
{% endif %}
|
||||||
|
</aside>
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
<header>
|
<header>
|
||||||
|
|
|
@ -6,27 +6,6 @@
|
||||||
{{ super() }}
|
{{ super() }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block overlay %}
|
|
||||||
{% if lastaction is not none %}
|
|
||||||
{% if lastaction == 'buy' %}
|
|
||||||
<aside id="overlay">
|
|
||||||
<h2>{{ lastproduct.name }}</h2>
|
|
||||||
<img src="/static/upload/thumbnails/products/{{ lastproduct.id }}.png?cacheBuster={{ now }}" alt="Picture of {{ lastproduct.name }}" draggable="false"/>
|
|
||||||
{% if lastprice is not none %}
|
|
||||||
<div class="price">{{ lastprice|chf }}</div>
|
|
||||||
{% endif %}
|
|
||||||
</aside>
|
|
||||||
{% elif lastaction == 'deposit' %}
|
|
||||||
<aside id="overlay">
|
|
||||||
<h2>Deposit</h2>
|
|
||||||
{% if lastprice is not none %}
|
|
||||||
<div class="price">{{ lastprice|chf }}</div>
|
|
||||||
{% endif %}
|
|
||||||
</aside>
|
|
||||||
{% endif %}
|
|
||||||
{% endif %}
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% block main %}
|
{% block main %}
|
||||||
|
|
||||||
{# Show the users current balance #}
|
{# Show the users current balance #}
|
||||||
|
|
Loading…
Reference in a new issue