Development
This commit is contained in:
parent
d8d1d46fd2
commit
eed1d295dc
69 changed files with 3355 additions and 3230 deletions
0
docker/routlin-dash/app/pages/accountdelete/__init__.py
Normal file
0
docker/routlin-dash/app/pages/accountdelete/__init__.py
Normal file
50
docker/routlin-dash/app/pages/accountdelete/action.py
Normal file
50
docker/routlin-dash/app/pages/accountdelete/action.py
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
from flask import Blueprint, request, session, redirect, flash
|
||||
import json
|
||||
from auth import require_level
|
||||
from config_utils import ACCOUNTS_FILE
|
||||
|
||||
bp = Blueprint('accountdelete', __name__)
|
||||
|
||||
|
||||
|
||||
def _load_accounts():
|
||||
try:
|
||||
with open(ACCOUNTS_FILE) as f:
|
||||
return json.load(f)
|
||||
except Exception:
|
||||
return {'accounts': []}
|
||||
|
||||
def _save_accounts(data):
|
||||
with open(ACCOUNTS_FILE, 'w') as f:
|
||||
json.dump(data, f, indent=2)
|
||||
|
||||
|
||||
@bp.route('/action/delete_account', methods=['POST'])
|
||||
@require_level('manager')
|
||||
def delete_account():
|
||||
try:
|
||||
row_index = int(request.form.get('row_index', ''))
|
||||
except (ValueError, TypeError):
|
||||
flash('Invalid request.', 'error')
|
||||
return redirect('/view/view_manageaccounts')
|
||||
|
||||
data = _load_accounts()
|
||||
accounts = data.get('accounts', [])
|
||||
|
||||
if row_index < 0 or row_index >= len(accounts):
|
||||
flash('Account not found.', 'error')
|
||||
return redirect('/view/view_manageaccounts')
|
||||
|
||||
target = accounts[row_index]
|
||||
|
||||
if target.get('email_address', '').lower() == session.get('email_address', '').lower():
|
||||
flash('You cannot remove your own account.', 'error')
|
||||
return redirect('/view/view_manageaccounts')
|
||||
|
||||
removed_email = target.get('email_address', '')
|
||||
accounts.pop(row_index)
|
||||
data['accounts'] = accounts
|
||||
_save_accounts(data)
|
||||
|
||||
flash(f'Account for {removed_email} has been removed.', 'success')
|
||||
return redirect('/view/view_manageaccounts')
|
||||
Loading…
Add table
Add a link
Reference in a new issue