Improve localization of OAuth2 client and token management
Change-Id: Iae4d34cb9b4ee4eb0101b55c7a859ebc27a12507
diff --git a/lib/Kalamar/Plugin/Auth.pm b/lib/Kalamar/Plugin/Auth.pm
index 9dba14c..d4e9e98 100644
--- a/lib/Kalamar/Plugin/Auth.pm
+++ b/lib/Kalamar/Plugin/Auth.pm
@@ -50,6 +50,12 @@
# Load localize
$app->plugin('Localize' => {
dict => {
+ de => {
+ abort => 'Abbrechen'
+ },
+ -en => {
+ abort => 'Abort'
+ },
Auth => {
_ => sub { $_->locale },
de => {
@@ -79,11 +85,22 @@
registerSuccess => 'Registrierung erfolgreich',
registerFail => 'Registrierung fehlgeschlagen',
oauthSettings => 'OAuth',
- oauthUnregister => 'Möchten sie <span class="client-name"><%= $client_name %></span> wirklich löschen?',
+ oauthUnregister => {
+ -long => 'Möchten sie <span class="client-name"><%= $client_name %></span> wirklich löschen?',
+ short => 'Löschen'
+ },
loginHint => 'Möglicherweise müssen sie sich zunächst einloggen.',
- oauthIssueToken => 'Erzeuge einen neuen Token für <span class="client-name"><%= $client_name %></span>',
+ oauthIssueToken => {
+ -long => 'Stelle einen neuen Token für <span class="client-name"><%= $client_name %></span> aus',
+ short => 'Neuen Token ausstellen'
+ },
accessToken => 'Access Token',
- oauthRevokeToken => 'Widerrufe einen Token für <span class="client-name"><%= $client_name %></span>',
+ oauthRevokeToken => {
+ -long => 'Widerrufe einen Token für <span class="client-name"><%= $client_name %></span>',
+ short => 'Widerrufe'
+ },
+ createdAt => 'Erstellt am <time datetime="<%= stash("date") %>"><%= stash("date") %></date>.',
+ expiresIn => 'Läuft in <%= stash("seconds") %> Sekunden ab.'
},
-en => {
loginSuccess => 'Login successful',
@@ -112,11 +129,22 @@
registerSuccess => 'Registration successful',
registerFail => 'Registration denied',
oauthSettings => 'OAuth',
- oauthUnregister => 'Do you really want to unregister <span class="client-name"><%= $client_name %></span>?',
+ oauthUnregister => {
+ -long => 'Do you really want to unregister <span class="client-name"><%= $client_name %></span>?',
+ short => 'Unregister'
+ },
loginHint => 'Maybe you need to log in first?',
- oauthIssueToken => 'Issue a new token for <span class="client-name"><%= $client_name %></span>',
+ oauthIssueToken => {
+ -long => 'Issue a new token for <span class="client-name"><%= $client_name %></span>',
+ short => 'Issue new token'
+ },
accessToken => 'Access Token',
- oauthRevokeToken => 'Revoka a token for <span class="client-name"><%= $client_name %></span>',
+ oauthRevokeToken => {
+ -long => 'Revoke a token for <span class="client-name"><%= $client_name %></span>',
+ short => 'Revoke'
+ },
+ createdAt => 'Created at <time datetime="<%= stash("date") %>"><%= stash("date") %></date>.',
+ expiresIn => 'Expires in <%= stash("seconds") %> seconds.'
}
}
}
diff --git a/lib/Kalamar/Plugin/Auth/templates/auth/client.html.ep b/lib/Kalamar/Plugin/Auth/templates/auth/client.html.ep
index 2fbbd80..392a514 100644
--- a/lib/Kalamar/Plugin/Auth/templates/auth/client.html.ep
+++ b/lib/Kalamar/Plugin/Auth/templates/auth/client.html.ep
@@ -28,21 +28,21 @@
<br />
<span class="button-group button-panel">
- %= link_to Unregister => url_for('oauth-unregister', client_id => stash('client_id'))->query('name' => stash('client_name')) => {} => ( class => 'client-unregister' )
- %= link_to IssueToken => url_for('oauth-issue-token', client_id => stash('client_id'))->query('name' => stash('client_name')) => {} => ( class => 'client-issue-token' )
+ %= link_to loc('Auth_oauthUnregister_short') => url_for('oauth-unregister', client_id => stash('client_id'))->query('name' => stash('client_name')) => {} => ( class => 'client-unregister' )
+ %= link_to loc('Auth_oauthIssueToken_short') => url_for('oauth-issue-token', client_id => stash('client_id'))->query('name' => stash('client_name')) => {} => ( class => 'client-issue-token' )
</span>
</li>
</ul>
- % if ($c->stash('tokens')) {
+ % if ($c->stash('tokens') && @{$c->stash('tokens')}) {
<legend>Tokens</legend>
<ul class="token-list">
% foreach (@{$c->stash('tokens')}) {
<li class="token">
%= label_for 'token' => loc('Auth_accessToken')
%= text_field '', value => $_->{token}, readonly => 'readonly', class => 'show-pwd copy-to-clipboard'
- <p name="created">Created at: <%= $_->{created_date} %></p>
- <p name="expires">Expires in: <%= $_->{expires_in} %></p>
+ <p name="created"><%== loc('Auth_createdAt', date => $_->{created_date}) %></p>
+ <p name="expires"><%== loc('Auth_expiresIn', seconds => $_->{expires_in}) %></p>
% if ($_->{scope}) {
<p name="scope">Scope: <tt><%= join ',', @{$_->{scope}} %></tt></p>
% };
@@ -51,7 +51,7 @@
%= csrf_field
<input type="hidden" name="name" value="<%= stash('client_name') %>" />
<input type="hidden" name="token" value="<%= $_->{token} %>" />
- <input type="submit" value="<%= loc 'Auth_revoke' %>" />
+ <input type="submit" value="<%= loc 'Auth_oauthRevokeToken_short' %>" />
% end
</span>
</li>
diff --git a/lib/Kalamar/Plugin/Auth/templates/auth/clients.html.ep b/lib/Kalamar/Plugin/Auth/templates/auth/clients.html.ep
index ed50b95..928e4c7 100644
--- a/lib/Kalamar/Plugin/Auth/templates/auth/clients.html.ep
+++ b/lib/Kalamar/Plugin/Auth/templates/auth/clients.html.ep
@@ -1,7 +1,5 @@
% extends 'settings', title => 'KorAP: '.loc('Auth_oauthSettings'), page => 'oauth';
-%# Rename to clients.html.ep
-
%= page_title
% my $list = stash('client_list');
diff --git a/lib/Kalamar/Plugin/Auth/templates/auth/issue-token.html.ep b/lib/Kalamar/Plugin/Auth/templates/auth/issue-token.html.ep
index 90371a7..d79a7a7 100644
--- a/lib/Kalamar/Plugin/Auth/templates/auth/issue-token.html.ep
+++ b/lib/Kalamar/Plugin/Auth/templates/auth/issue-token.html.ep
@@ -9,6 +9,6 @@
%= hidden_field 'client-id' => stash('client_id')
%= hidden_field 'name' => param('name')
%#= hidden_field 'client-secret'
- <input type="submit" value="issue" />
- %= link_to 'Abort' => url_for('oauth-tokens', client_id => stash('client_id')) => {} => (class => 'form-button button-abort')
+ <input type="submit" value="<%= loc 'Auth_oauthIssueToken_short' %>" />
+ %= link_to loc('abort') => url_for('oauth-tokens', client_id => stash('client_id')) => {} => (class => 'form-button button-abort')
% end
diff --git a/lib/Kalamar/Plugin/Auth/templates/auth/revoke-token.html.ep b/lib/Kalamar/Plugin/Auth/templates/auth/revoke-token.html.ep
index 5c53c83..d54b6f9 100644
--- a/lib/Kalamar/Plugin/Auth/templates/auth/revoke-token.html.ep
+++ b/lib/Kalamar/Plugin/Auth/templates/auth/revoke-token.html.ep
@@ -8,6 +8,6 @@
%= csrf_field
%= hidden_field 'name' => param('name')
%= hidden_field 'token' => param('token')
- <input type="submit" value="<%= loc 'Auth_revoke' %>" />
- %= link_to 'Abort' => url_for('oauth-tokens', client_id => stash('client_id')) => {} => (class => 'form-button button-abort')
+ <input type="submit" value="<%= loc 'Auth_oauthRevokeToken_short' %>" />
+ %= link_to loc('abort') => url_for('oauth-tokens', client_id => stash('client_id')) => {} => (class => 'form-button button-abort')
% end
diff --git a/lib/Kalamar/Plugin/Auth/templates/auth/unregister.html.ep b/lib/Kalamar/Plugin/Auth/templates/auth/unregister.html.ep
index 2bf66a9..a48f516 100644
--- a/lib/Kalamar/Plugin/Auth/templates/auth/unregister.html.ep
+++ b/lib/Kalamar/Plugin/Auth/templates/auth/unregister.html.ep
@@ -7,6 +7,6 @@
%= form_for 'oauth-unregister-post', class => 'form-table', begin
%= csrf_field
%= hidden_field 'client-name' => param('name')
- <input type="submit" value="Unregister" />
- %= link_to 'Abort' => 'oauth-settings' => {} => (class => 'form-button button-abort')
+ <input type="submit" value="<%= loc 'Auth_oauthUnregister_short' %>" />
+ %= link_to loc('abort') => 'oauth-settings' => {} => (class => 'form-button button-abort')
% end
diff --git a/t/plugin/auth-oauth.t b/t/plugin/auth-oauth.t
index 1159964..653ea5c 100644
--- a/t/plugin/auth-oauth.t
+++ b/t/plugin/auth-oauth.t
@@ -552,11 +552,14 @@
$t->get_ok('/settings/oauth/fCBbQkA2NDA3MzM1Yw==')
->text_is('.client-name', 'MyApp2')
->text_is('.client-desc', 'This is my application')
- ->text_is('.client-issue-token', 'IssueToken')
+ ->text_is('.client-issue-token', 'Issue new token')
->attr_is('.client-issue-token', 'href', '/settings/oauth/fCBbQkA2NDA3MzM1Yw==/token?name=MyApp2')
->header_is('Cache-Control','max-age=0, no-cache, no-store, must-revalidate')
->header_is('Expires','Thu, 01 Jan 1970 00:00:00 GMT')
->header_is('Pragma','no-cache')
+ ->text_is('ul.token-list label[for=token]', 'Access Token')
+ ->text_is('p[name=created]', 'Created at ')
+ ->text_is('p[name=expires]', 'Expires in 31533851 seconds.')
;
$csrf = $t->get_ok('/settings/oauth/fCBbQkA2NDA3MzM1Yw==/token?name=MyApp2')
@@ -567,6 +570,9 @@
->header_is('Cache-Control','max-age=0, no-cache, no-store, must-revalidate')
->header_is('Expires','Thu, 01 Jan 1970 00:00:00 GMT')
->header_is('Pragma','no-cache')
+ ->text_is('a.button-abort', 'Abort')
+ ->attr_is('#issue-token input[type=submit]', 'value', 'Issue new token')
+ ->content_like(qr!Issue a new token for!)
->tx->res->dom->at('input[name="csrf_token"]')
->attr('value')
;
@@ -607,6 +613,9 @@
->attr_is('form#revoke-token','action','/settings/oauth/fCBbQkA2NDA3MzM1Yw==/token?_method=DELETE')
->attr_is('form#revoke-token','method','POST')
->attr_is('form#revoke-token input[name=token]','value','jhkhkjhk_hjgjsfz67i')
+ ->text_is('a.button-abort', 'Abort')
+ ->attr_is('#revoke-token input[type=submit]', 'value', 'Revoke')
+ ->content_like(qr!Revoke a token for!)
;