added capability to run a dev container for pa, and if we re-build we create a new .sk and remove old PA_UserState on fresh login. BUG-120 is either fixed by this or at least the log catches it and does not crash now (if we rebuild between re-use)

This commit is contained in:
2024-03-10 23:52:34 +11:00
parent 2665ab086e
commit d86893875d
5 changed files with 29 additions and 16 deletions

13
main.py
View File

@@ -11,7 +11,7 @@ from datetime import datetime
import os
import re
import socket
from shared import CreateSelect, CreateFoldersSelect, LocationIcon, DB_URL, PROD_HOST, OLDEST_LOG_LIMIT
from shared import CreateSelect, CreateFoldersSelect, LocationIcon, DB_URL, OLDEST_LOG_LIMIT
# for ldap auth
from flask_ldap3_login import LDAP3LoginManager
@@ -86,6 +86,7 @@ from files import Entry
from person import Person
from settings import Settings
from user import PAUser
from states import PA_UserState
####################################### GLOBALS #######################################
# allow jinja2 to call these python functions directly
@@ -148,6 +149,11 @@ def login():
# Successfully logged in, We can now access the saved user object via form.user.
login_user(form.user, remember=True) # Tell flask-login to log them in.
next = request.args.get("next")
# just (re)-authenticated, so clear old state from UserState, to avoid re-using old data that is no longer valid
PA_UserState.query.filter(PA_UserState.pa_user_dn==current_user.dn).delete()
db.session.commit()
if next:
return redirect(next) # Send them back where they came from
else:
@@ -242,10 +248,7 @@ def logout():
# main to be called via Flask/Gunicorn
###############################################################################
def main():
if hostname == PROD_HOST:
app.run(ssl_context=('/etc/letsencrypt/live/pa.depaoli.id.au/cert.pem', '/etc/letsencrypt/live/pa.depaoli.id.au/privkey.pem'), host="0.0.0.0", debug=False)
else:
app.run(host="0.0.0.0", debug=True)
app.run(host="0.0.0.0", debug=True)
###############################################################################
# This func creates a new filter in jinja2 to test to hand back the username