Possible to create different session timeout lengths for different users in Python Flask? -


i have angular/flask web app , trying create admin page accessed url, "/admin_page". page require additional authentication , needs issue session timeout shorter timeout other users.

however, i'm under impression sessions generated same variable in flask application, configure such:

app.permanent_session_lifetime = timedelta(seconds=int)

so, question is: is there way change session timeout length users without affecting timeout length of other users' sessions?

i.e. if in route handler /admin_page temporarily change value of app.permanent_session_lifetime, create user's session, , restore variable original value, sessions created have timeout value altered?

yes of course!

1) if url based lifetime session want:

for each view append configuration line:

app.permanent_session_lifetime = timedelta(seconds=int) 

or

app.config['permanent_session_lifetime'] = <intended_value_in_seconds> 

2) if on per user basis:

i recommend creating groups , each group assign specific config can call config when needed.

def group_session(self, group):     if group_session == 'visitors':        return app.config['permanent_session_lifetime'] == <intended_value_in_seconds>     if group_session == 'admin':         return app.config['permanent_session_lifetime'] == <intended_value_in_seconds>     return app.config['permanent_session_lifetime'] 

3) if prefer have user session lifetime, then:

if user == <chosen_name>:     app.config['permanent_session_lifetime'] == <intended_value_in_seconds> 

i hope helps!


Comments