Re: "keep me logged in" option

12 views
Skip to first unread message

David Underhill

unread,
Dec 8, 2010, 12:22:06 AM12/8/10
to Chris Lacy, gae-se...@googlegroups.com
Chris,

Thanks for your kind words - I'm glad gae-sessions has been serving you well :).

Another user asked about this a few months ago, so I'll point you to that discussion:

I proposed two solutions there; the second is pretty straightforward to implement and might be just what you're looking for.  The first solution is more "correct" but also a bit more complicated.  I plan to implement this (or something similar) for the next release.

All the best,

~ David



On Tue, Dec 7, 2010 at 21:15, Chris Lacy <gday...@gmail.com> wrote:
Hi David,

I have been using gaesessions for a while now, and I find it fantastic. Thank you very much for contributing this library to the community.

I have a quick question about how best to use gaesessions.

Basically, I would like to provide my users with a "keep me logged in" option (using a custom login system). What I would like, is if they select 'opt to stay logged in', the session will exist for the standard session lifetime.

But if they choose 'no' to staying logged in, I would like the session to persist for the duration of the current login, and be automatically cleared next time they load the application.

Is there an easy way to implement this behavior with gaesessions?

Thanks in advance,

Chris Lacy.


David Underhill

unread,
Dec 8, 2010, 1:20:16 AM12/8/10
to Chris Lacy, gae-se...@googlegroups.com
On Tue, Dec 7, 2010 at 21:59, Chris Lacy <gday...@gmail.com> wrote:
Thanks for getting back to me David. 

Funnily enough, Suggestion #2 is basically the workaround I was thinking about implementing. I was just curious if there was a 'proper' solution in place for this currently.

Not yet, but I'm glad the second suggestion is reasonable enough that you thought of it too :).
 

I will just go ahead with that for now I think, but if/when you implement proper support for this feature in gae-sessions, I'll definitely take a look at it ;) 

Thanks again.

Your welcome; enjoy :).

~ David

Chris Lacy

unread,
Dec 8, 2010, 2:23:18 AM12/8/10
to gae-sessions
Cheers David.

For what it's worth, I implemented solution #2.

I've pasted the code below, on the off chance it helps someone else.

In make_cookie_headers():

old:
cookies = [COOKIE_FMT % (i, cv[i*m:i*m+m], ed) for i in
xrange(num_cookies)]

new:
#Note: If you want the session data to be removed, set the
session['remember_login'] to False somewhere in your code..
if self.data.has_key('remember_login') and self.data['remember_login']
== False:
cookie_fmt = ' ' + COOKIE_NAME_PREFIX + '%02d="%s"; Path=' +
COOKIE_PATH + '; HttpOnly'
cookies = [cookie_fmt % (i, cv[i*m:i*m+m]) for i in
xrange(num_cookies)]
else:
cookies = [EXPIRE_COOKIE_FMT % (i, cv[i*m:i*m+m], ed) for i in
xrange(num_cookies)]



On Dec 8, 4:20 pm, David Underhill <doun...@gmail.com> wrote:
> On Tue, Dec 7, 2010 at 21:59, Chris Lacy <gdaych...@gmail.com> wrote:
> > Thanks for getting back to me David.
>
> > Funnily enough, Suggestion #2 is basically the workaround I was thinking
> > about implementing. I was just curious if there was a 'proper' solution in
> > place for this currently.
>
> Not yet, but I'm glad the second suggestion is reasonable enough that you
> thought of it too :).
>
>
>
> > I will just go ahead with that for now I think, but if/when you implement
> > proper support for this feature in gae-sessions, I'll definitely take a look
> > at it ;)
>
> > Thanks again.
>
> Your welcome; enjoy :).
>
> ~ David
>
>
>
>
>
>
>
>
>
> > On Wed, Dec 8, 2010 at 3:22 PM, David Underhill <doun...@gmail.com> wrote:
>
> >> Chris,
>
> >> Thanks for your kind words - I'm glad gae-sessions has been serving you
> >> well :).
>
> >> Another user asked about this a few months ago, so I'll point you to that
> >> discussion:
>
> >>http://groups.google.com/group/gae-sessions/browse_thread/thread/594e...
>
> >> I proposed two solutions there; the second is pretty straightforward to
> >> implement and might be just what you're looking for.  The first solution is
> >> more "correct" but also a bit more complicated.  I plan to implement this
> >> (or something similar) for the next release.
>
> >> All the best,
>
> >> ~ David
>

David Underhill

unread,
Dec 8, 2010, 2:36:37 AM12/8/10
to gae-sessions
Awesome, thanks for putting this together and sharing!

I've copied your work into a patch hosted on pastebin since google
groups isn't very code friendly:
http://pastebin.com/raw.php?i=PALZucES

Thanks!

~ David

Chris Lacy

unread,
Dec 8, 2010, 3:23:26 AM12/8/10
to gae-sessions
Crap, I just found a copy/paste error in my original code.

The final line:
cookies = [EXPIRE_COOKIE_FMT % (i, cv[i*m:i*m+m], ed) for i in
xrange(num_cookies)]

Should be:
cookies = [COOKIE_FMT % (i, cv[i*m:i*m+m], ed) for i in
xrange(num_cookies)]

My apologies about the run around there. David, would you mind
updating your pastebin to reflect the proper change?

Cheers :)

David Underhill

unread,
Dec 8, 2010, 9:33:19 AM12/8/10
to gae-se...@googlegroups.com
On Wed, Dec 8, 2010 at 00:23, Chris Lacy <gday...@gmail.com> wrote:
David, would you mind
updating your pastebin to reflect the proper change?

Cheers :)

np; I've tweaked the pastebin diff.
Reply all
Reply to author
Forward
0 new messages