使用Authlogic增加login_count

时间:2010-08-19 16:28:22

标签: ruby-on-rails login authlogic

我希望每次用户通过显式登录进入我的网站时都会增加login_count属性,或者记住我登录。目前,Authlogic仅在每次显式登录时增加login_count。有没有其他人这样做过,或者有人知道在插件里面自定义这个吗?

2 个答案:

答案 0 :(得分:0)

before_filter添加ApplicationController以增加计数器。

class ApplicationController < ActionController::Base    

  before_filter :increment_visit_count    

private

  def increment_visit_count
    User.increment_counter(:visit_count, current_user.id) if current_user
  end    
end

注意:此解决方案需要visit_count表中的新列users

答案 1 :(得分:0)

按如下方式更新您的用户会话类:

class UserSession < Authlogic::Session::Base
  def persist_by_cookie
    r = super
    User.increment_counter(:login_count, unauthorized_record.id) if r
    r
  end
end

注意:我还没有测试过这段代码。根据Authlogic代码,这应该工作。如果这对您有用,请告诉我