correct miscellaneous issues with user login history

This commit is contained in:
Bianca Nenciu 2018-09-02 09:24:54 +02:00 committed by Sam
parent 8e70b82baa
commit f5e0356fb2
7 changed files with 73 additions and 26 deletions

View File

@ -164,16 +164,16 @@
{{#if canCheckEmails}} {{#if canCheckEmails}}
<div class="control-group pref-auth-tokens"> <div class="control-group pref-auth-tokens">
<label class="control-label">{{i18n 'user.auth_tokens.title'}}</label> <label class="control-label">{{i18n 'user.auth_tokens.title'}}</label>
<a {{action "revokeAuthToken"}}>{{d-icon "sign-out"}} {{i18n 'user.auth_tokens.logout'}}</a> <a {{action "revokeAuthToken"}} class="pull-right">{{d-icon "sign-out"}} {{i18n 'user.auth_tokens.logout'}}</a>
{{#each model.user_auth_tokens as |token|}} {{#each model.user_auth_tokens as |token|}}
<div class="perf-auth-token"> <a class="perf-auth-token" {{action "toggleToken" token}}>
<div class="row auth-token-summary"> <div class="row auth-token-summary">
<div class="auth-token-label"> <div class="auth-token-label">
{{d-icon token.icon}} {{token.device_name}} {{d-icon token.icon}} {{token.device_name}}
{{#if token.visible}} {{#if token.visible}}
<a {{action "toggleToken" token}}>{{d-icon "angle-double-up"}}</a> {{d-icon "angle-double-up"}}
{{else}} {{else}}
<a {{action "toggleToken" token}}>{{d-icon "angle-double-down"}}</a> {{d-icon "angle-double-down"}}
{{/if}} {{/if}}
</div> </div>
<div class="auth-token-value"> <div class="auth-token-value">
@ -200,7 +200,7 @@
</div> </div>
</div> </div>
{{/if}} {{/if}}
</div> </a>
{{/each}} {{/each}}
</div> </div>
{{/if}} {{/if}}

View File

@ -565,11 +565,13 @@ select {
} }
.muted { .muted {
color: #888; color: $primary-medium;
} }
.perf-auth-token { .perf-auth-token {
background: #f9f9f9; background-color: $primary-very-low;
color: $primary;
display: block;
padding: 5px; padding: 5px;
margin-bottom: 10px; margin-bottom: 10px;
} }
@ -585,12 +587,12 @@ select {
} }
.auth-token-details { .auth-token-details {
background: #fff; background: $secondary;
padding: 5px 10px; padding: 5px 10px;
margin: 10px 5px 5px 5px; margin: 10px 5px 5px 5px;
.auth-token-label { .auth-token-label {
color: #888; color: $primary-medium;
} }
} }

View File

@ -1102,7 +1102,7 @@ class UsersController < ApplicationController
user = fetch_user_from_params user = fetch_user_from_params
guardian.ensure_can_edit!(user) guardian.ensure_can_edit!(user)
UserAuthToken.where(user_id: user.id).destroy_all UserAuthToken.where(user_id: user.id).each(&:destroy!)
MessageBus.publish "/file-change", ["refresh"], user_ids: [user.id] MessageBus.publish "/file-change", ["refresh"], user_ids: [user.id]

View File

@ -35,14 +35,14 @@ class UserAuthTokenSerializer < ApplicationSerializer
case object.user_agent case object.user_agent
when /Android/i when /Android/i
'Android' 'Android'
when /iPhone|iPad|iPod/i
'iOS'
when /Macintosh/i
'macOS'
when /Linux/i when /Linux/i
'Linux' 'Linux'
when /Windows/i when /Windows/i
'Windows' 'Windows'
when /Macintosh|Mac OS X|macOS/i
'macOS'
when /iPhone|iPad|iPod/i
'iOS'
else else
I18n.t('staff_action_logs.unknown') I18n.t('staff_action_logs.unknown')
end end
@ -52,20 +52,20 @@ class UserAuthTokenSerializer < ApplicationSerializer
case object.user_agent case object.user_agent
when /Android/i when /Android/i
I18n.t('user_auth_tokens.devices.android') I18n.t('user_auth_tokens.devices.android')
when /Linux/i
I18n.t('user_auth_tokens.devices.linux')
when /Windows/i
I18n.t('user_auth_tokens.devices.windows')
when /Macintosh|Mac OS X|macOS/i
I18n.t('user_auth_tokens.devices.mac')
when /iPhone/i
I18n.t('user_auth_tokens.devices.iphone')
when /iPad/i when /iPad/i
I18n.t('user_auth_tokens.devices.ipad') I18n.t('user_auth_tokens.devices.ipad')
when /iPhone/i
I18n.t('user_auth_tokens.devices.iphone')
when /iPod/i when /iPod/i
I18n.t('user_auth_tokens.devices.ipod') I18n.t('user_auth_tokens.devices.ipod')
when /Mobile/i when /Mobile/i
I18n.t('user_auth_tokens.devices.mobile') I18n.t('user_auth_tokens.devices.mobile')
when /Macintosh/i
I18n.t('user_auth_tokens.devices.mac')
when /Linux/i
I18n.t('user_auth_tokens.devices.linux')
when /Windows/i
I18n.t('user_auth_tokens.devices.windows')
else else
I18n.t('user_auth_tokens.devices.unknown') I18n.t('user_auth_tokens.devices.unknown')
end end
@ -73,14 +73,14 @@ class UserAuthTokenSerializer < ApplicationSerializer
def icon def icon
case os case os
when 'Android'
'android'
when 'macOS', 'iOS'
'apple'
when 'Linux' when 'Linux'
'linux' 'linux'
when 'Windows' when 'Windows'
'windows' 'windows'
when 'macOS', 'iOS'
'apple'
when 'Android'
'android'
else else
'question' 'question'
end end

View File

@ -250,6 +250,25 @@ describe UserAuthToken do
end end
it "calls before_destroy" do
SiteSetting.verbose_auth_token_logging = true
user = Fabricate(:user)
token = UserAuthToken.generate!(user_id: user.id,
user_agent: "some user agent",
client_ip: "1.1.2.3")
expect(user.user_auth_token_logs.count).to eq(1)
token.destroy
expect(user.user_auth_token_logs.count).to eq(2)
expect(user.user_auth_token_logs.last.action).to eq("destroy")
expect(user.user_auth_token_logs.last.user_agent).to eq("some user agent")
expect(user.user_auth_token_logs.last.client_ip).to eq("1.1.2.3")
end
it "will not mark token unseen when prev and current are the same" do it "will not mark token unseen when prev and current are the same" do
user = Fabricate(:user) user = Fabricate(:user)

View File

@ -3167,4 +3167,24 @@ describe UsersController do
end end
end end
describe '#revoke_auth_token' do
context 'while logged in' do
before do
sign_in(user)
end
it 'logs user out' do
expect(user.user_auth_tokens.count).to eq(1)
post "/u/#{user.username}/preferences/revoke-auth-token.json"
expect(response.status).to eq(200)
expect(user.user_auth_tokens.count).to eq(0)
end
end
end
end end

View File

@ -211,6 +211,12 @@ QUnit.test("default avatar selector", async assert => {
); );
}); });
QUnit.test("email field always shows up", async assert => {
await visit("/u/eviltrout/preferences");
assert.ok(exists(".pref-auth-tokens"), "it shows the auth tokens");
});
acceptance("Avatar selector when selectable avatars is enabled", { acceptance("Avatar selector when selectable avatars is enabled", {
loggedIn: true, loggedIn: true,
settings: { selectable_avatars_enabled: true }, settings: { selectable_avatars_enabled: true },