Add last user login and activity

This commit is contained in:
Patrick Gansterer 2015-03-03 14:55:30 +01:00
parent c59ee3a6a7
commit 700eed27b8
8 changed files with 25 additions and 5 deletions

View file

@ -4,7 +4,7 @@ class ApplicationController < ActionController::Base
helper_method :available_locales
protect_from_forgery
before_filter :select_foodcoop, :authenticate, :store_controller, :items_per_page
before_filter :select_foodcoop, :authenticate, :set_user_last_activity, :store_controller, :items_per_page
after_filter :remove_controller
around_filter :set_time_zone, :set_currency
@ -116,6 +116,13 @@ class ApplicationController < ActionController::Base
end
end
def set_user_last_activity
if current_user && (session[:last_activity] == nil || session[:last_activity] < 1.minutes.ago)
current_user.update_attribute(:last_activity, Time.now)
session[:last_activity] = Time.now
end
end
# Many plugins can be turned on and off on the fly with a `use_` configuration option.
# To disable a controller in the plugin, you can use this as a `before_action`:
#

View file

@ -9,6 +9,7 @@ class SessionsController < ApplicationController
def create
user = User.authenticate(params[:nick], params[:password])
if user
user.update_attribute(:last_login, Time.now)
login user
if session[:return_to].present?
redirect_to_url = session[:return_to]