Expire on Browser Closed?

17 views
Skip to first unread message

mitch

unread,
Sep 4, 2010, 9:30:09 PM9/4/10
to gae-sessions
In our application, we normally keep users logged in for 7 days. I am
trying to implement a "This is a public computer" style login
checkbox. Is there an easy way for me to tell gae-sessions to expire
some sessions on browser close and use the default expiration for
others?

Thanks,

Mitch

David Underhill

unread,
Sep 13, 2010, 7:20:03 PM9/13/10
to gae-se...@googlegroups.com
Mitch,

Good question.  Unfortunately gae-sessions doesn't provide direct support for expiring cookies when the user closes their browser (i.e., not setting an expiration date for the cookie).

You could, however, implement this without too much trouble.  Two possible approaches:
1) One approach might be to change the handling of the expire_ts parameter (to various functions) so that when it is None, the expiration date would not be set on the cookie.  You'd also need to update code which relies on get_expiration() (as well as that function itself) to handle sessions without a specified expiration date.
2) A simpler approach might be to set a variable on each session which specifies what kind of session it is.  For example, set session['public_pc'] to True or False based on whether the user is on a public computer or not.  Then, in make_cookie_headers(), you can check the value of this session variable before deciding whether to use the existing COOKIE_FMT string, or a modified version of COOKIE_FMT which doesn't supply an expiration time.

The latter should be pretty easy to work in, at the expense of a tiny bit of overhead in the session.  The former is probably the more "correct" solution but would require a little more hacking.  Let me know how it turns out!

~ David

PS.  Sorry for the slow reply, I overlooked this message!

Mitch Hastings

unread,
Sep 14, 2010, 1:36:36 PM9/14/10
to gae-se...@googlegroups.com
No problem. I appreciate any response, especially such a thoughtful one. I agree that option #1 would be cleaner. I am going to dig into the code base to see if I can wrap my head around it. Thank you very much for your insights and a great product. I have been developing in other languages for several years, but I am new to python and GAE so this has been a tremendous help. 

David Underhill

unread,
Sep 14, 2010, 6:56:26 PM9/14/10
to gae-se...@googlegroups.com
You're welcome and good luck.  I'll look forward to seeing how it turns out (if you're able to share the improvements when you're done).

All the best ~ David
Reply all
Reply to author
Forward
0 new messages