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 helper_method :available_locales
protect_from_forgery 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 after_filter :remove_controller
around_filter :set_time_zone, :set_currency around_filter :set_time_zone, :set_currency
@ -116,6 +116,13 @@ class ApplicationController < ActionController::Base
end end
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. # 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`: # 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 def create
user = User.authenticate(params[:nick], params[:password]) user = User.authenticate(params[:nick], params[:password])
if user if user
user.update_attribute(:last_login, Time.now)
login user login user
if session[:return_to].present? if session[:return_to].present?
redirect_to_url = session[:return_to] redirect_to_url = session[:return_to]

View file

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

View file

@ -15,6 +15,10 @@
%dd= @user.email %dd= @user.email
%dt= heading_helper User, :phone %dt= heading_helper User, :phone
%dd= @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' %dt= t 'admin.access_to'
%dd= format_roles(@user) %dd= format_roles(@user)
.span5 .span5

View file

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

View file

@ -149,6 +149,7 @@ en:
user: user:
email: Email email: Email
first_name: First name first_name: First name
last_activity: Last activity
last_login: Last login last_login: Last login
last_name: Last name last_name: Last name
name: 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. # 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| create_table "article_categories", force: :cascade do |t|
t.string "name", limit: 255, default: "", null: false 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.string "reset_password_token", limit: 255
t.datetime "reset_password_expires" t.datetime "reset_password_expires"
t.datetime "last_login" t.datetime "last_login"
t.datetime "last_activity"
end end
add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree