added route for token backup

This commit is contained in:
Simon Pirkelmann 2021-04-06 17:53:14 +02:00
parent f021f7494f
commit 312549ac15

View File

@ -529,6 +529,19 @@ def create_application(config):
flash(f"Error during store_tokens. Exception: {e}") flash(f"Error during store_tokens. Exception: {e}")
return redirect('/tokens') return redirect('/tokens')
@app.route('/backup_tokens')
@auth_required()
def backup_tokens():
# get list of defined admin users for backup
tokens = door.get_tokens()
try:
with tempfile.TemporaryDirectory() as tmpdir:
file = Path(tmpdir, 'token_data.txt')
file.write_text(json.dumps(tokens))
return send_file(file, as_attachment=True, cache_timeout=-1)
except Exception as e:
return str(e)
@app.route('/open') @app.route('/open')
@auth_required() @auth_required()
def open_door(): def open_door():