I’m writing an app using bottle.py and beaker.middleware.SessionMiddleware:
How can I modify the session.timeout and session.cookie_expires values so I can implement a login system that logs the user in for 30 days?
I already implemented the standard login system so everything works until the browser closes, but I’d like to modify those values if the user checks the Remember me checkbox.
I thought of two variants if the user checks the Remember me checkbox:
-
Set
session.cookie_expiresandsession.timeoutto 30 days, but it seems that I can’t modify these values at run-time because the cookie I recieve expires at the end of the browser session, ignoring my runtime modifications. -
Set
session.timeoutto 30 days and overwrite the cookie namedbeaker.session.idwriting the same session id but different expiry date.
But the run-time problem from point 1. remains and it seems that I can’t access the session’s id that I just created with beaker, so I don’t know what to store in the cookie.
How can I implement this?
The only solution I come up with is to implement my own little backend and setting cookies myself, without beaker.
For posterity’s sake, the code is here:
https://github.com/paulbarbu/bottle-upload/blob/master/index.py
Methods:
login_bl,upload_view(db),is_logged_in, andlogout().Please note this is some VERY old code and NOT production ready, use at your own risk, some code snippets from the above link follow:
Login:
Logout:
Is the user logged in?