Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add last user login and activity #357

Merged
merged 1 commit into from
Apr 3, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -116,6 +116,13 @@ def authenticate_or_token(prefix, role = 'any')
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`:
#
Expand Down
1 change: 1 addition & 0 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def new
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]
Expand Down
6 changes: 3 additions & 3 deletions app/views/admin/users/_users.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
4 changes: 4 additions & 0 deletions app/views/admin/users/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20150301000000_add_last_activity_to_user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddLastActivityToUser < ActiveRecord::Migration
def change
add_column :users, :last_activity, :datetime
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -341,6 +341,7 @@
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
Expand Down