How to detect session restart (remembered sessions)?

9 views
Skip to first unread message

RangerRick

unread,
Oct 11, 2009, 3:39:55 PM10/11/09
to Authlogic
Hi,

I'm in need of detecting when a persisted session is restarted, so I
can handle some application-specific things.

Is there a standard way to detect "session restart" w/ AuthLogic?

Many thanks.

Rick

RangerRick

unread,
Oct 12, 2009, 10:58:26 AM10/12/09
to Authlogic
Let me rephrase. I need to redirect to a specific page after
AuthLogic automatically logs in using its persistent cookie
login.

Currently, the browser is caching my page and I need to force
a page refresh to ensure the page is showing fresh data upon
session restore.

Anyone?

Rick

gobigdave

unread,
Oct 22, 2009, 11:18:22 PM10/22/09
to Authlogic
I'm interested in this answer as well. For my app, users get
reputation points when they login, but it doesn't work if they use
remember me. I use the UserSession after_save callback to track
username/password logins, but how do I detect that the user came back
in using the persisted cookie?

-Dave

Bertg

unread,
Oct 29, 2009, 5:31:23 AM10/29/09
to Authlogic
Hey,

I'm working on this as well,

Currently I'm able to detect if a session is persisted by cookie:

module Authlogic

module Session

module Cookies

module InstanceMethods

private

def persist_by_cookie_with_login_count
if persist_by_cookie_without_login_count
Rails.logger.debug "### Persisted via cookie"
else
Rails.logger.debug "### Did not persisted via cookie"
end
end

alias_method_chain :persist_by_cookie, :login_count

end

end

end
end

Problem is that persisting via cookie is done before persisting via
session, so it is always persisting via cookie if it's available.
I'm now trying to figure out how to change that order without
modifying the gem.

Greetz,

Bertg

unread,
Oct 29, 2009, 6:30:12 AM10/29/09
to Authlogic
This is how i changed the order of persistence via an initialiser.

persistance_chain = Authlogic::Session::Base.persist_callback_chain

persistance_chain_methods = persistance_chain.collect(&:method)

if persistance_chain_methods.index(:persist_by_cookie) <
persistance_chain_methods.index(:persist_by_session)
a = persistance_chain_methods.index(:persist_by_cookie)
b = persistance_chain_methods.index(:persist_by_session)

#
# We can do this, because we get a reference to the array, not a dup
#

persistance_chain[a], persistance_chain[b] = persistance_chain[b],
persistance_chain[a]

end

On Oct 29, 10:31 am, Bertg <bertgoeth...@gmail.com> wrote:
> Hey,
>
> I'm working on this as well,
>
> Currently I'm able to detect if asessionis persisted bycookie:
>
> module Authlogic
>
>   moduleSession
>
>     module Cookies
>
>       module InstanceMethods
>
>       private
>
>         def persist_by_cookie_with_login_count
>           if persist_by_cookie_without_login_count
>             Rails.logger.debug "### Persisted viacookie"
>           else
>             Rails.logger.debug "### Did not persisted viacookie"
>           end
>         end
>
>         alias_method_chain :persist_by_cookie, :login_count
>
>       end
>
>     end
>
>   end
> end
>
> Problem is that persisting viacookieis donebeforepersisting viasession, so it is always persisting viacookieif it's available.
> I'm now trying to figure out how to change that order without
> modifying the gem.
>
> Greetz,
>
> On Oct 12, 3:58 pm, RangerRick <rbra...@gmail.com> wrote:
>
>
>
> > Let me rephrase. I need to redirect to a specific page after
> > AuthLogic automatically logs in using its persistentcookie
> > login.
>
> > Currently, the browser is caching my page and I need to force
> > a page refresh to ensure the page is showing fresh data upon
> >sessionrestore.
>
> > Anyone?
>
> > Rick
>
> > On Oct 11, 2:39 pm, RangerRick <rbra...@gmail.com> wrote:> Hi,
>
> > > I'm in need of detecting when a persistedsessionis restarted, so I
> > > can handle some application-specific things.
>
> > > Is there a standard way to detect "sessionrestart" w/ AuthLogic?
>
> > > Many thanks.
>
> > > Rick

Bertg

unread,
Nov 27, 2009, 3:45:17 AM11/27/09
to Authlogic
Did any of this work for you?
Reply all
Reply to author
Forward
0 new messages