Record and show the last time users have logged in

This commit is contained in:
Jyri-Petteri Paloposki 2020-08-10 16:54:48 +03:00
parent 950da89d76
commit 1936c90c95
4 changed files with 10 additions and 1 deletions

View file

@ -14,6 +14,7 @@ class LoginController < ApplicationController
case request.method
when 'POST'
if @user = User.authenticate(params['user_login'], params['user_password'])
@user.update_attribute(:last_login_at, Time.now)
return handle_post_success
else
handle_post_failure

View file

@ -14,6 +14,7 @@
<th><%= t('users.total_projects') %></th>
<th><%= t('users.total_notes') %></th>
<th><%= User.human_attribute_name('created_at') %></th>
<th><%= User.human_attribute_name('last_login_at') %></th>
<th>&nbsp;</th>
</tr>
<% for user in @users %>
@ -28,6 +29,7 @@
<td><%= h user.projects.size %></td>
<td><%= h user.notes.size %></td>
<td><%= format_date(user.created_at) %></td>
<td><%= format_date(user.last_login_at) %></td>
<td><%= !user.is_admin? ? remote_delete_user(user) : "&nbsp;".html_safe %></td>
</tr>
<% end %>

View file

@ -0,0 +1,5 @@
class AddLastloginToUser < ActiveRecord::Migration[5.2]
def change
add_column :users, :last_login_at, :datetime
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2020_08_07_175610) do
ActiveRecord::Schema.define(version: 2020_08_10_123316) do
create_table "attachments", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.integer "todo_id"
@ -223,6 +223,7 @@ ActiveRecord::Schema.define(version: 2020_08_07_175610) do
t.string "email"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "last_login_at"
t.index ["login"], name: "index_users_on_login"
end