Commit 4e500cf
Changed files (7)
app
controllers
javascript
packs
views
my
sessions
app/controllers/my/sessions_controller.rb
@@ -3,7 +3,7 @@
module My
class SessionsController < ApplicationController
def index
- @sessions = current_user.sessions
+ @sessions = current_user.sessions.active
end
end
end
app/javascript/packs/application.js
@@ -10,8 +10,12 @@
import 'bootstrap/dist/js/bootstrap';
import { Application } from 'stimulus';
import { definitionsFromContext } from 'stimulus/webpack-helpers';
+import LocalTime from "local-time";
+import Rails from 'rails-ujs';
import '../application.scss';
const application = Application.start();
const context = require.context('controllers', true, /.js$/);
application.load(definitionsFromContext(context));
+LocalTime.start();
+Rails.start();
app/views/my/sessions/index.html.erb
@@ -4,12 +4,16 @@
<h1><%= t('.title') %></h1>
<table class="table">
<thead>
+ <th>Last Used</th>
<th>User Agent</th>
+ <th>IP Address</th>
</thead>
<tbody>
<% @sessions.each do |user_session| %>
<tr>
+ <td><%= local_time_ago(user_session.accessed_at) %></td>
<td><%= user_session.user_agent %></td>
+ <td><%= user_session.ip %></td>
</tr>
<% end %>
</tbody>
Gemfile
@@ -13,6 +13,7 @@ gem 'email_validator', '~> 1.6'
gem 'foreman', '~> 0.85'
gem 'jbuilder', '~> 2.5'
gem 'jwt', '~> 2.1'
+gem 'local_time', '~> 2.1'
gem 'puma', '~> 3.11'
gem 'rails', '~> 5.2.0'
gem 'rotp', '~> 3.3'
Gemfile.lock
@@ -126,6 +126,7 @@ GEM
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
ruby_dep (~> 1.2)
+ local_time (2.1.0)
loofah (2.2.2)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
@@ -311,6 +312,7 @@ DEPENDENCIES
jbuilder (~> 2.5)
jwt (~> 2.1)
listen (>= 3.0.5, < 3.2)
+ local_time (~> 2.1)
pg
puma (~> 3.11)
rails (~> 5.2.0)
package.json
@@ -11,9 +11,11 @@
"bootstrap": "^4.0.0",
"jquery": "^3.3.1",
"json-loader": "^0.5.7",
+ "local-time": "^2.1.0",
"popper.js": "^1.14.3",
"qrcode": "^1.2.0",
"rails-translations-webpack-plugin": "^1.1.0",
+ "rails-ujs": "^5.2.1",
"stimulus": "^1.0.1"
},
"devDependencies": {
yarn.lock
@@ -4133,6 +4133,10 @@ loader-utils@^1.0.0, loader-utils@^1.0.1, loader-utils@^1.0.2, loader-utils@^1.1
emojis-list "^2.0.0"
json5 "^0.5.0"
+local-time@^2.1.0:
+ version "2.1.0"
+ resolved "https://registry.yarnpkg.com/local-time/-/local-time-2.1.0.tgz#be42f06bf269f9da77cb61ea722aa424dd01d919"
+
locate-path@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-2.0.0.tgz#2b568b265eec944c6d9c0de9c3dbbbca0354cd8e"
@@ -5898,6 +5902,10 @@ rails-translations-webpack-plugin@^1.1.0:
virtual-module-webpack-plugin "^0.3.0"
yaml-js "^0.1.4"
+rails-ujs@^5.2.1:
+ version "5.2.1"
+ resolved "https://registry.yarnpkg.com/rails-ujs/-/rails-ujs-5.2.1.tgz#2869c6d54fdfefac3aaa257f4efe211d8f5a7169"
+
randomatic@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/randomatic/-/randomatic-3.1.0.tgz#36f2ca708e9e567f5ed2ec01949026d50aa10116"