开发者

rails -- track number of user login

I'd like to track how many times a user logs in to my site which is a Rails app. Is there any other call like "created_on or updated_on" that can make a little counter in my model that tracks that kind of info? I'm usi开发者_StackOverflow中文版ng restful-authentication currently.


I would add login_count field to your User/Account model. Then change this method in User/Account model:

def self.authenticate(login, password)
  return nil if login.blank? || password.blank?
  u = find_by_login(login) # need to get the salt
  u && u.authenticated?(password) ? u.increase_login_count : nil
end

and add this method to model:

def increase_login_count
  self.login_count += 1
  self.save
  self
end


You could create a column in the user table called login_count or something and then in the SessionsController.create method

if user
    user.login_count += 1
    user.save(false)     #update without validations.

    # .... other RestfulAuthentication generated code ....
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜