Reputation: 19
I have used rails devise gem for authentication. Specifically, I have used devise timeoutable module for session timeout with 30 minutes.
I need to make a pop up which prompts after 29 minutes & able to extend the session for next 30 minutes exactly same as that of implemented in Unfuddle.com .
On this prompt there are 2 buttons and one timer: "Stay logged in", "Logout", and timer for 60 seconds. If I click on "Stay logged in" button within 60 seconds then session should be extended up to next 30 minutes without change or refresh the page. If I click on Logout then user should be logout his session and redirects to login page. If I don't press any of the above 2 buttons within 60 seconds then it automatically redirects to the login page. Guidance will be appreciated.
I have used following code in devise session_controller:
def skip_timeout
request.env["devise.skip_trackable"] = true
end
def extend_admin_session
request.env["devise.skip_trackable"] = false
@time_left_insec = Devise.timeout_in - (Time.now - admin_session["last_request_at"]).round
render :json => @time_left_insec
end
Upvotes: 2
Views: 1145
Reputation: 10358
To dynamically set the timeout for each user, you can define a method in the user model called timeout_in that returns the timeout value.
class User < ActiveRecord::Base
devise (...), :timeoutable
def timeout_in
if self.admin?
1.year
else
2.days
end
end
end
Thing is you need to define a method and have to call accordingly ...
I would suggests you to check out source code of timeout module in Devise
Hope this help you !!!
Upvotes: 1