#38 ✓resolved
James Coleman

logout_on_timeout not functioning as expected

Reported by James Coleman | February 10th, 2009 @ 02:58 PM

I have logout_on_timeout true in my model and the setting for the length of a session before timeout. This works correctly, and users are logged out after the specified time. However, in the documentation for logout_on_timeout (Authlogic::Session::Config::ClassMethods) it states: "Lastly, UserSession.find will still return a object is the session is stale, but you will not get a record. This allows you to determine if the user needs to log back in because their session went stale, or because they just aren‘t logged in. Just call current_user_session.stale? as your flag."

So I have tried using current_user_session.stale? in several different places (I need to clear some extra data out of the session when a user logs out or is logged out) but I always get an error the current_user_session is nil when used right after UserSession.find on an just auto-logged out user.

Comments and changes to this ticket

  • Ben Johnson

    Ben Johnson February 11th, 2009 @ 02:40 AM

    • State changed from “new” to “resolved”

    Hmm, this should done in a global before_filter. So your current_user_session method should look something like:

    def current_user_session
    return @current_user_session if defined?(@current_user_session)
    @current_user_session = UserSession.find
    if @current_user_session && @current_user_session.stale?
    redirect_to new_user_session_url(:stale => true)
    return false
    end
    end
    

    Then using that "stale" parameter you can display the proper message. Hope this helps.

  • James Coleman

    James Coleman February 11th, 2009 @ 10:09 AM

    I did already have current_user as a global before_filter. I modified my current_user_session to look like this for testing purposes:

    @@@ Ruby def current_user_session

    RAILS_DEFAULT_LOGGER.error("\n In current_user_session \n")
    return @current_user_session if defined?(@current_user_session)
    @current_user_session = UserSession.find
    RAILS_DEFAULT_LOGGER.error("\n After UserSession.find \n")
    if @current_user_session && @current_user_session.stale?
      RAILS_DEFAULT_LOGGER.error("\n Stale current_user_session \n")
      return false
    end
    return @current_user_session
    
    

    end

    
    
    As expected in the log I get "In current_user_session" and then the SQL calls and then "After UserSession.find" but while the user is being automatically logged out, "Stale current_user_session" does not appear in the log. So it appears that even when the session is detected as stale, the UserSession.find returns nil as opposed to returning an object that I can call .stale? on as it says in the documentation.
    
  • Ben Johnson

    Ben Johnson February 11th, 2009 @ 01:51 PM

    I uploaded a fix. If the session is stale it will return a session, but there will be no record associated with it. But calling stale? on the session object will return true. I put some tests in place to make sure this is the case and they all passes.

  • James Coleman

    James Coleman February 11th, 2009 @ 04:38 PM

    logout_on_timeout true should still work in the user_session.rb correct? Because I have that set to true, and now it is not even automatically logging stale sessions out. I have a logged in user and to force a test, in the console I set user.last_request_at = 45.minutes.ago and saved. I then ran script/server --debugger and stepped through the current_user_session method. UserSession.find did return an object now instead of nil, but the @current_user_session.stale? returns false and the user is also not automatically logged out. Before this update, the user was automatically being logged out but you couldn't call stale? on a nil object. Now it seems like the code to set the stale flag isn't working. Am I doing something wrong here?

  • Ben Johnson

    Ben Johnson February 11th, 2009 @ 04:45 PM

    Alright, this is fixed and I put specific tests in place for this. Let me know if you have any other problems.

  • James Coleman

    James Coleman February 11th, 2009 @ 06:26 PM

    That update seems to have solved all of the problems! Thanks for the quick attention.

  • kyqizog

    kyqizog June 19th, 2019 @ 05:31 AM

    When I have entered with the page of the good one for the log in then we have to mention some requested timed out. That would be considering as far from the bestessays scam website by the conditionally making only some reviews.

  • naomiyang

    naomiyang August 15th, 2019 @ 06:13 AM

    Hi there! I assume that every student once during studying at college ordered different kind of paper at writing service. I want to recommend writing service where you can order affordable paper. Our essay writer service has been known worldwide as one of the most trustworthy, reliable, industrious, and devoted service in the online academic writing industry.

  • jane909192

    jane909192 January 8th, 2020 @ 09:29 AM

    Very nice update to users for windows 7 support end date it is the users for all.

  • rosstaylor505

    rosstaylor505 January 9th, 2020 @ 04:43 AM

    Hey, great blog, but I don’t understand how to add your site in my reader. Can you Help me please?
    socks men

  • rosstaylor505

    rosstaylor505 January 30th, 2020 @ 02:57 AM

    wow, great, I was wondering how to cure acne naturally. and found your site by google, learned a lot, now i’m a bit clear. I’ve bookmark your site and also add rss. keep us updated.
    ผลหวย

  • PhoenixAiden
  • HoustonHacker

    HoustonHacker February 5th, 2020 @ 06:34 AM

    Continue the nice function, We study couple of articles about this web site as well as I believe that the internet weblog is actually actual fascinating and it has obtained arenas associated with wonderful info.
    best CBD oil for anxiety

  • aliana
  • anuskseo

    anuskseo February 11th, 2020 @ 05:29 AM

    Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon. Big thanks for the useful info. india visa for finland citizens

  • Essie Fitz

    Essie Fitz February 13th, 2020 @ 06:03 AM

    Have in the past experienced a similar problem. Had to consult with a specialist and it happened again when working on essays.

  • anuskseo

    anuskseo February 13th, 2020 @ 07:20 AM

    Thanks for posting this info. I just want to let you know that I just check out your site and I find it very interesting and informative. I can't wait to read lots of your posts. avalon bitcoin miners

  • Philip Daniels
  • joancooper
  • nushra
  • Marilyn Matthews

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Object based authentication solution that handles all of the non sense for you. It's as easy as ActiveRecord is with a database.

People watching this ticket

Pages