質問

I apologize for not having any initial code to support this question

I have authlogic set up to logged_in_timeout after 20 minutes. What I would like to do is build a jQuery function that will pull in the 'last_request_at' value from my users model and then run a timer that will alert the use at 18 minutes "You are about the be logged out".

Can jQuery pull directly from the DB, or should I pass a session to the function?

Then, I would like to have two buttons in the model/alert "Log Me Out" or "Stay Logged In".

 If the user clicks "Stay Logged In" how would I have jQuery update the last_request_at field in the DB? 
役に立ちましたか?

解決

I just used coffeescript to make this work.

   setTimeout (->
    setTimeout (->
      parent.location.reload true
    ), 70000
 $('#inactivity_modal').modal()
   $("#inactivity_modal").bind "hidden", ->
   parent.location.reload true
   ), 540000

In my app a user is automatically logged out at 10 minutes since last request. So, at 9 minutes (54000 milliseconds) this function activates a modal that includes two buttons; one to log out and one to stay logged in. The stay logged in button simply closes the modal and refreshes the parent thereby updating Authlogics last_request_at field and giving the user another 9 minutes until it happens again. Of course, any time a page loads the timer gets reset, therefor any active user wont see the modal. If the user does not respond to the warning modal, Authlogic ends their session one minute later (at 10 minutes) and 10 seconds after that (70000) the parent page is refreshed to conceal any content that may have been visible on the previous page.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top