> Is there a way to set the session timeout when a user logs in?
>
> I have a timeout setup for field agents, but there are a few users who
> only access the application from their office, and want to have the
> session timeout much longer (essentially for a working day)
>
> Is there a way to override the config setting?
>
> I tried adding
> if( $user['User']['group_id'] == 3 )
> {
> Configure::write( 'Session.timeout', '3000' );
> }
> to my login action, but cake just ignores that and uses the core.php
> setting.
>
> I'm using Configure::write( 'Session.save', 'cake' ); for my sessions.
>
> Does anyone have any ideas on how this could be achieved.
Setting that in login() won't work because it'll only be valid for
that request. Look at CakeSession's _checkValid() method (called by
SessionComponent). When it reads 'Session.timeout' it's going to get
whatever is in core.php. So the answer is that you need to alter that
value on *every* request, and before SessionComponent::startup(). A
component's startup() callback happens after
Controller::beforeFilter() so you could do it there.
Of course, you need to access the session to find out what User type
you're dealing with. But I think it should be fine because reading
from the session won't cause _checkValid() to be called.
Try this in AppController's beforeFilter() after everything else:
if ('3' == $this->Session->read('Auth.User.group_id'))
{
Configure::write( 'Session.timeout', '3000' );
}
After beforeFilter() fires, the components' startup() methods will be
called, and Auth will check the session. SessionComponent will in turn
check the session is valid, and CakeSession will get the revised
timeout value from Configure.
I think. Completely untested!
--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
No comments:
Post a Comment