feat: add users balance to admin interface
This commit is contained in:
parent
f517621245
commit
f58a95a094
5 changed files with 33 additions and 8 deletions
13
CHANGELOG.md
13
CHANGELOG.md
|
@ -1,5 +1,18 @@
|
||||||
# Matemat Changelog
|
# Matemat Changelog
|
||||||
|
|
||||||
|
<!-- BEGIN RELEASE v0.4.7 -->
|
||||||
|
## Version 0.4.7
|
||||||
|
|
||||||
|
Feature release
|
||||||
|
|
||||||
|
### Changes
|
||||||
|
|
||||||
|
<!-- BEGIN CHANGES 0.4.7 -->
|
||||||
|
- feat: add users balance to admin interface
|
||||||
|
<!-- END CHANGES 0.4.7 -->
|
||||||
|
|
||||||
|
<!-- END RELEASE v0.4.7 -->
|
||||||
|
|
||||||
<!-- BEGIN RELEASE v0.4.6 -->
|
<!-- BEGIN RELEASE v0.4.6 -->
|
||||||
## Version 0.4.6
|
## Version 0.4.6
|
||||||
|
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
|
|
||||||
__version__ = '0.4.6'
|
__version__ = '0.4.7'
|
||||||
|
|
|
@ -130,7 +130,8 @@ class MatematDatabase(object):
|
||||||
email: Optional[str] = None,
|
email: Optional[str] = None,
|
||||||
admin: bool = False,
|
admin: bool = False,
|
||||||
member: bool = True,
|
member: bool = True,
|
||||||
logout_after_purchase: bool = False) -> User:
|
logout_after_purchase: bool = False,
|
||||||
|
balance: int = 0) -> User:
|
||||||
"""
|
"""
|
||||||
Create a new user.
|
Create a new user.
|
||||||
:param username: The name of the new user.
|
:param username: The name of the new user.
|
||||||
|
@ -139,6 +140,7 @@ class MatematDatabase(object):
|
||||||
:param admin: Whether the user is an administrator, defaults to False.
|
:param admin: Whether the user is an administrator, defaults to False.
|
||||||
:param member: Whether the user is a member, defaults to True.
|
:param member: Whether the user is a member, defaults to True.
|
||||||
:param logout_after_purchase: Whether the user should be logged out after completing a purchase.
|
:param logout_after_purchase: Whether the user should be logged out after completing a purchase.
|
||||||
|
:param balance: Initial account balance of the user.
|
||||||
:return: A User object representing the created user.
|
:return: A User object representing the created user.
|
||||||
:raises ValueError: If a user with the same name already exists.
|
:raises ValueError: If a user with the same name already exists.
|
||||||
"""
|
"""
|
||||||
|
@ -154,12 +156,13 @@ class MatematDatabase(object):
|
||||||
c.execute('''
|
c.execute('''
|
||||||
INSERT INTO users (username, email, password, balance, is_admin, is_member, lastchange, created,
|
INSERT INTO users (username, email, password, balance, is_admin, is_member, lastchange, created,
|
||||||
logout_after_purchase)
|
logout_after_purchase)
|
||||||
VALUES (:username, :email, :pwhash, 0, :admin, :member, STRFTIME('%s', 'now'), STRFTIME('%s', 'now'),
|
VALUES (:username, :email, :pwhash, :balance, :admin, :member, STRFTIME('%s', 'now'),
|
||||||
:logout_after_purchase)
|
STRFTIME('%s', 'now'), :logout_after_purchase)
|
||||||
''', {
|
''', {
|
||||||
'username': username,
|
'username': username,
|
||||||
'email': email,
|
'email': email,
|
||||||
'pwhash': pwhash,
|
'pwhash': pwhash,
|
||||||
|
'balance': balance,
|
||||||
'admin': admin,
|
'admin': admin,
|
||||||
'member': member,
|
'member': member,
|
||||||
'logout_after_purchase': logout_after_purchase
|
'logout_after_purchase': logout_after_purchase
|
||||||
|
@ -167,7 +170,7 @@ class MatematDatabase(object):
|
||||||
# Fetch the new user's rowid.
|
# Fetch the new user's rowid.
|
||||||
c.execute('SELECT last_insert_rowid()')
|
c.execute('SELECT last_insert_rowid()')
|
||||||
user_id = int(c.fetchone()[0])
|
user_id = int(c.fetchone()[0])
|
||||||
return User(user_id, username, 0, email, admin, member)
|
return User(user_id, username, balance, email, admin, member)
|
||||||
|
|
||||||
def login(self, username: str, password: Optional[str] = None, touchkey: Optional[str] = None) -> User:
|
def login(self, username: str, password: Optional[str] = None, touchkey: Optional[str] = None) -> User:
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -77,9 +77,10 @@ def handle_change(args: FormsDict, files: FormsDict, db: MatematDatabase):
|
||||||
is_member = 'ismember' in args
|
is_member = 'ismember' in args
|
||||||
is_admin = 'isadmin' in args
|
is_admin = 'isadmin' in args
|
||||||
logout_after_purchase = 'logout_after_purchase' in args
|
logout_after_purchase = 'logout_after_purchase' in args
|
||||||
|
balance = parse_chf(str(args.balance))
|
||||||
# Create the user in the database
|
# Create the user in the database
|
||||||
newuser: User = db.create_user(username, password, email, member=is_member, admin=is_admin,
|
newuser: User = db.create_user(username, password, email, member=is_member, admin=is_admin,
|
||||||
logout_after_purchase=logout_after_purchase)
|
logout_after_purchase=logout_after_purchase, balance=balance)
|
||||||
|
|
||||||
# The user requested to create a new product
|
# The user requested to create a new product
|
||||||
elif change == 'newproduct':
|
elif change == 'newproduct':
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
<th>Member</th>
|
<th>Member</th>
|
||||||
<th>Admin</th>
|
<th>Admin</th>
|
||||||
<th>Logout after purchase</th>
|
<th>Logout after purchase</th>
|
||||||
|
<th>Balance</th>
|
||||||
<th>Actions</th>
|
<th>Actions</th>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -39,6 +40,12 @@
|
||||||
<td><input class="form-check-input" id="admin-newuser-ismember" type="checkbox" name="ismember"></td>
|
<td><input class="form-check-input" id="admin-newuser-ismember" type="checkbox" name="ismember"></td>
|
||||||
<td><input class="form-check-input" id="admin-newuser-isadmin" type="checkbox" name="isadmin"></td>
|
<td><input class="form-check-input" id="admin-newuser-isadmin" type="checkbox" name="isadmin"></td>
|
||||||
<td><input class="form-check-input" id="admin-newuser-logout-after-purchase" type="checkbox" name="logout_after_purchase"></td>
|
<td><input class="form-check-input" id="admin-newuser-logout-after-purchase" type="checkbox" name="logout_after_purchase"></td>
|
||||||
|
<td>
|
||||||
|
<div class="input-group mb-3">
|
||||||
|
<span class="input-group-text">CHF</span>
|
||||||
|
<input class="form-control" id="admin-newuser-balance" type="number" step="0.01" name="balance" value="0.00">
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
<td><input class="btn btn-success" type="submit" value="Create User"></td>
|
<td><input class="btn btn-success" type="submit" value="Create User"></td>
|
||||||
</tr>
|
</tr>
|
||||||
{% for user in users %}
|
{% for user in users %}
|
||||||
|
@ -49,6 +56,7 @@
|
||||||
<td>{{ '✓' if user.is_member else '✗' }}</td>
|
<td>{{ '✓' if user.is_member else '✗' }}</td>
|
||||||
<td>{{ '✓' if user.is_admin else '✗' }}</td>
|
<td>{{ '✓' if user.is_admin else '✗' }}</td>
|
||||||
<td>{{ '✓' if user.logout_after_purchase else '✗' }}</td>
|
<td>{{ '✓' if user.logout_after_purchase else '✗' }}</td>
|
||||||
|
<td>{{ user.balance | chf }}</td>
|
||||||
<td>
|
<td>
|
||||||
<div class="btn-group" role="group">
|
<div class="btn-group" role="group">
|
||||||
<a class="btn btn-primary" href="/moduser?userid={{ user.id }}">Edit</a>
|
<a class="btn btn-primary" href="/moduser?userid={{ user.id }}">Edit</a>
|
||||||
|
@ -82,13 +90,13 @@
|
||||||
<td>
|
<td>
|
||||||
<div class="input-group mb-3">
|
<div class="input-group mb-3">
|
||||||
<span class="input-group-text">CHF</span>
|
<span class="input-group-text">CHF</span>
|
||||||
<input class="form-control" id="admin-newproduct-price-member" type="number" step="0.01" name="pricemember" value="0">
|
<input class="form-control" id="admin-newproduct-price-member" type="number" step="0.01" name="pricemember" value="0.00">
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<div class="input-group mb-3">
|
<div class="input-group mb-3">
|
||||||
<span class="input-group-text">CHF</span>
|
<span class="input-group-text">CHF</span>
|
||||||
<input class="form-control" id="admin-newproduct-price-non-member" type="number" step="0.01" name="pricenonmember" value="0">
|
<input class="form-control" id="admin-newproduct-price-non-member" type="number" step="0.01" name="pricenonmember" value="0.00">
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td><input class="form-check-input" id="admin-custom-price" type="checkbox" name="custom_price"></td>
|
<td><input class="form-check-input" id="admin-custom-price" type="checkbox" name="custom_price"></td>
|
||||||
|
|
Loading…
Reference in a new issue