开发者

Authlogic. Logging the logout timeout

开发者 https://www.devze.com 2023-03-21 15:32 出处:网络
I am using Authlogic with the logout timeout.What I need to do is log when the User has actually timed out.I have gone so far as to try to make a t开发者_如何学Chread that notices users that go away f

I am using Authlogic with the logout timeout. What I need to do is log when the User has actually timed out. I have gone so far as to try to make a t开发者_如何学Chread that notices users that go away from the User.logged_in list. It seems when I put a thread in there I get 2 threads rather then one, so I am looking for a better solution.

What would be the best way to do this?


I ended up fixing my threading by putting the following at the top of the application controller:

 def check_logout
     previous_user = {}
     loop {
         x = User.logged_in
         active_user = {}
         x.each { |a|
             active_user[a[:login]] = a[:login]
             previous_user[a[:login]] = a[:login]
         }
         puts "active = #{active_user}"  
         previous_user.each { |key,value|
         if active_user[key] == nil then
             puts "Login timeout for #{value}"  
             InternalLog.notify_msg("Login timeout for #{value}")
             previous_user.delete(key)
         end
         }
       sleep(30)      
     }
     rescue => e0
         puts "WORKER THREAD RESCUE"
         puts e0
         exit     end



    if $BACKGROUND_THREAD == nil then
        $BACKGROUND_THREAD = Thread.new do
            check_logout
        end 
    end
0

精彩评论

暂无评论...
验证码 换一张
取 消