0
[solved]Flask app close session after 6 hours of usage regardless of activity
I'm not sure how to close the session after 6 hours, I need to do it even if the user is active as it is part of the security policy for the company I work for. Is this possible?
6 odpowiedzi
+ 3
'''
I assume you are referring to killing a user session?... If you are trying to terminate your Flask server you can use the same datetime imports and after a 6-hour delta, you would call "sys.exit(0)"
'''
from datetime import timedelta
from flask import session, app
@app.before_request
def make_session_permanent():
session.permanent = True
app.permanent_session_lifetime = timedelta(hours=6)
# https://stackoverflow.com/questions/11783025/is-there-an-easy-way-to-make-sessions-timeout-in-flask
+ 1
Steven M your right I am trying to kill a user session, but make session permanent resets once a user interacts with the web page, does it not?
+ 1
'''
Maybe, we can test it by changing the delta to something like 5 minutes...
'''
app.permanent_session_lifetime = timedelta(minutes=5)
+ 1
Steven M ok I'll try that :)
+ 1
Steven M your right, I had the wrong syntax and called at the wrong point, thank you
+ 1
Charlie Crease-huggett very cool, glad to help 👍🙂👍