diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 12f72ca8..711874b9 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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`: # diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index dad2f6fb..a612d957 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -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] diff --git a/app/views/admin/users/_users.html.haml b/app/views/admin/users/_users.html.haml index b38c7c54..412ef932 100644 --- a/app/views/admin/users/_users.html.haml +++ b/app/views/admin/users/_users.html.haml @@ -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' diff --git a/app/views/admin/users/show.html.haml b/app/views/admin/users/show.html.haml index 51fae993..6b9a84d2 100644 --- a/app/views/admin/users/show.html.haml +++ b/app/views/admin/users/show.html.haml @@ -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 diff --git a/config/locales/de.yml b/config/locales/de.yml index 86ec234d..c3888d2d 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -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 diff --git a/config/locales/en.yml b/config/locales/en.yml index 04d7e648..3ac99265 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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 diff --git a/db/migrate/20150301000000_add_last_activity_to_user.rb b/db/migrate/20150301000000_add_last_activity_to_user.rb new file mode 100644 index 00000000..b8a177d0 --- /dev/null +++ b/db/migrate/20150301000000_add_last_activity_to_user.rb @@ -0,0 +1,5 @@ +class AddLastActivityToUser < ActiveRecord::Migration + def change + add_column :users, :last_activity, :datetime + end +end diff --git a/db/schema.rb b/db/schema.rb index 448e1a3d..2fb34ce8 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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