From 7c9c54bcad4a63c70d9106179600e2b7b1172be5 Mon Sep 17 00:00:00 2001 From: Andrew Nesbitt Date: Wed, 7 Feb 2018 11:13:35 +0000 Subject: [PATCH] Record last login timestamp on users during when logging in --- app/controllers/sessions_controller.rb | 3 ++- db/migrate/20180207110908_add_last_login_at_to_users.rb | 5 +++++ db/schema.rb | 3 ++- 3 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20180207110908_add_last_login_at_to_users.rb diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 2e35b49e4..7048d4539 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -48,7 +48,8 @@ def create flash[:notice] = nil session[:user_id] = identity.user.id end - + + identity.user.update_columns(last_login_at: Time.current) identity.user.update_repo_permissions_async login_destination = pre_login_destination diff --git a/db/migrate/20180207110908_add_last_login_at_to_users.rb b/db/migrate/20180207110908_add_last_login_at_to_users.rb new file mode 100644 index 000000000..16b27abc3 --- /dev/null +++ b/db/migrate/20180207110908_add_last_login_at_to_users.rb @@ -0,0 +1,5 @@ +class AddLastLoginAtToUsers < ActiveRecord::Migration[5.0] + def change + add_column :users, :last_login_at, :datetime + end +end diff --git a/db/schema.rb b/db/schema.rb index dd6450c2f..0c07bb6d5 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20171109154509) do +ActiveRecord::Schema.define(version: 20180207110908) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -292,6 +292,7 @@ t.datetime "last_synced_at" t.boolean "emails_enabled", :default=>true t.boolean "optin", :default=>false + t.datetime "last_login_at" end create_table "versions", force: :cascade do |t|