You are here: Forums Ask a Rails expert Managing automatic logout....
Posted in Forums : Ask a Rails expert
Authority 0
Posting Rating 70
Sign in to rate this post
|
Hi All, Before I delve into the wonderful world of background macros, etc., I was curious as to whether anyone had suggestions for managing automatic logouts. For instance, if I have users logged in for more than an hour without performing any tasks, I’d like to log them out. I’m currently using ‘restful_authentication’ to handle my users, so it’d be nice if I could “integrate” a solution to use that (although I’m sure integration wouldn’t be hard). Anyway, I’m all ears—or eyes as the case may be. Thanks, |
Authority 62
Posting Rating 0
Sign in to rate this post
|
I don’t know any built-in way to control sessions timeouts, but i think it’s not hard do implement. |
Authority 25
Posting Rating 98
Sign in to rate this post
|
The PragProg Rails Recipes book has a cool way of doing it. Here’s the jist: Use a controller filter to update a session[:expires_at] with a future time you want, updating this each time an action is taken on the site. Use periodically_call_remote to call a method that checks this value. When the time has elapsed destroy the session and render the login page. Their example also notes that you can react ahead of time and update the screen with a timeout warning message as well. I haven’t tried it myself but it sounds pretty good. |
Authority 50
Posting Rating 92
Sign in to rate this post
|
My session code works a lot like Clemens has described. Here it is for simple perusal:
class ApplicationController < ActionController::Base
before_filter :prepare_session
def prepare_session
if !session[:expiry_time].nil? and session[:expiry_time] < Time.now
reset_session
end
session[:expiry_time] = (60 * 15).seconds.from_now
return true
end
end
I rather do like the proactive ajax check approach Raul is mentioning though. It is definitely something you will have to play with to see which approach best suits your needs. |
Authority 75
Posting Rating 59
Sign in to rate this post
|
In Michael’s code :
Thanks :) |
Authority 37
Posting Rating 94
Sign in to rate this post
|
Raul idea is good. it helps a lot for me ….... Thank You, |
Ask a Rails expert : nested application ApplicationController get called intead of children::ApplicationController
Ask a Rails expert : Best way to structure a database for a large/static dataset
Ask a Rails expert : Ruby Developer (ROR) - Scottish based (Remote working from within the UK)
Ask a Rails expert : Above Ground Pool Supplies
Ask a Rails expert : How to get url params in observer or model in Rails 3.1
Ask a Rails expert : What can persuade you to hire Junior Ruby devs with significant PHP experience?
Ask a Rails expert : What industry value does the Ruby or Rails Certification currently have?
Ask a Rails expert : Louis Vuitton Damier Azur Canvas specially sale ( www.salecheaplouisvuitton.com )
Ask a Rails expert : ·How to check errors/puts statements from ruby files which are under cronob
Ask a Rails expert : Louis Vuitton cheap Soft Sided Luggagespecial offer( www.salecheaplouisvuitton.com )