Hot to do the: Remember me (for 30 days) by default?

482 views
Skip to first unread message

Constantine Vasil

unread,
Dec 1, 2011, 5:52:46 PM12/1/11
to web...@googlegroups.com
I want to set the option Remember me (for 30 days)
to take effect by default whether or not the user checked 
the checkbox when login. And if possible to hide the checkbox.

How to do that?

Alan Etkin

unread,
Dec 1, 2011, 6:55:55 PM12/1/11
to web2py-users
The default scaffolding app calls auth() wich returns a form to be
shown in the client. It is a web2py helper class instance, so it can
be examined and modified. FORM instances have an elements() function
that returns a sequence of childs:

You could modify the user action (in controller) to customize the form
returned by the auth() call. So you would be able to set a default
value to the "remember" checkbox input and hide it (by passing the
attribute _style="display:none;").

Maybe this is not the best approach (deforming the helper output).
There is got to be a simpler way of customization of the standard
scaffolding authentication service that i missed. Or it could be added
as a project task.

Alan Etkin

unread,
Dec 1, 2011, 8:23:40 PM12/1/11
to web2py-users
I actually missed a lot of ways of customizing authentication
services. You can have a look at the web2py book. (Chapter 8.3 on
authorization)

Section 8.3.6 covers customization with auth object settings

There is an auth settings attribute called long_expiration (specified
in seconds) wich controls the user's session expiration time.

User session expiration is treated here:
http://groups.google.com/group/web2py/browse_thread/thread/e70e186d960d7163/c33cd28bb4e37bf4

Constantine Vasil

unread,
Dec 2, 2011, 12:04:16 AM12/2/11
to web...@googlegroups.com
Thank you. Actually I have more pressing issue - the session expires very quickly
and the user has to login after several minutes (don't know exactly) in-activity.

How to set it for example 1 hour? When I have presentations this quick 
expiration is annoying.

Alan Etkin

unread,
Dec 2, 2011, 5:54:57 AM12/2/11
to web2py-users
In this thread Massimo covers the user session administration.
http://groups.google.com/group/web2py/browse_thread/thread/ab2ace730fd85578/d7ca6ed70b1a4d4c

Have you tried setting a long (in seconds) auth.settings.expiration
value?

Anthony

unread,
Dec 2, 2011, 10:58:11 AM12/2/11
to web...@googlegroups.com
To get rid of the checkbox, set auth.settings.remember_me_form=False.

To set the long login, I think it just looks for the existence of request.vars.remember (which would be there if the checkbox were included in the form and checked). So, you should be able to force the long login by adding a 'remember' variable to request.vars. Something like:

auth.settings.login_onvalidation = lambda f: request.vars.update(remember=True)

Note, you can adjust the length of the long login via auth.settings.long_expiration.

Anthony

Constantine Vasil

unread,
Dec 2, 2011, 12:04:43 PM12/2/11
to web...@googlegroups.com
Thank you, Anthony! I will check it out.
Reply all
Reply to author
Forward
0 new messages