I'd like to have the login_count attribute increment each time the user enters my site via explicit login or remember me login. Currently Authlogic only increments login_count per explicit login. Has anyone else done this, or does anyone know where to customize this inside of the plugin?
A:
Add a before_filter
to your ApplicationController
to increment the counter.
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
Note: This solution requires a new column visit_count
in your users
table.
KandadaBoggu
2010-08-19 17:09:32
Won't this also increment the counter while the user is on the site moving from page to page?
scott
2010-08-19 17:20:29
Yes, it will. I read your requirements wrong. I will update the answer with the correct reply.
KandadaBoggu
2010-08-19 17:23:21
Thank you in advance of the reply :)
scott
2010-08-19 17:50:18
A:
Update your user session class as follows:
class UserSession < Authlogic::Session::Base
def persist_by_cookie
r = super
User.increment_counter(:login_count, unauthorized_record.id) if r
r
end
end
Note: I haven't tested this code. As per Authlogic code this should work. Let me know if this works for you
KandadaBoggu
2010-08-19 19:13:38
This did not, but I don't think as a result of your code. For some reason my Authlogic system is incrementing the login_count rapidly throughout a session. Not sure why, but I found a way around this entire issue. Much thanks for the help.
scott
2010-08-20 14:16:08