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]

View file

@ -9,17 +9,17 @@
%th= heading_helper User, :name
%th= heading_helper User, :email
%th= t 'admin.access_to'
%th= heading_helper User, :last_login
%th= heading_helper User, :last_activity
%th(colspan="2")= t 'ui.actions'
%tbody
- for user in @users
- for user in @users
%tr
%td= link_to show_user(user), [:admin, user]
- if FoodsoftConfig[:use_nick]
%td= user.name
%td= user.email
%td= format_roles(user)
%td= format_time(user.last_login)
%td= format_time(user.last_activity)
%td= link_to t('ui.edit'), edit_admin_user_path(user), class: 'btn btn-mini'
%td= link_to t('ui.delete'), [:admin, user], :data => {:confirm => t('admin.confirm', name: user.name)},
:method => :delete, class: 'btn btn-danger btn-mini'

View file

@ -15,6 +15,10 @@
%dd= @user.email
%dt= heading_helper User, :phone
%dd= @user.phone
%dt= heading_helper User, :last_login
%dd= format_time(@user.last_login)
%dt= heading_helper User, :last_activity
%dd= format_time(@user.last_activity)
%dt= t 'admin.access_to'
%dd= format_roles(@user)
.span5

View file

@ -149,6 +149,7 @@ de:
user:
email: E-Mail
first_name: Vorname
last_activity: Letzte Aktivität
last_login: Letzter login
last_name: Nachname
name: Name

View file

@ -149,6 +149,7 @@ en:
user:
email: Email
first_name: First name
last_activity: Last activity
last_login: Last login
last_name: Last name
name: Name

View file

@ -0,0 +1,5 @@
class AddLastActivityToUser < ActiveRecord::Migration
def change
add_column :users, :last_activity, :datetime
end
end

View file

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20150227161931) do
ActiveRecord::Schema.define(version: 20150301000000) do
create_table "article_categories", force: :cascade do |t|
t.string "name", limit: 255, default: "", null: false
@ -341,6 +341,7 @@ ActiveRecord::Schema.define(version: 20150227161931) do
t.string "reset_password_token", limit: 255
t.datetime "reset_password_expires"
t.datetime "last_login"
t.datetime "last_activity"
end
add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree