Feature #4714: Update sunstone login token dialog

This commit is contained in:
Carlos Martín committed 2016-09-05 14:49:07 +02:00
1 parent c2b7864a4f
commit 91ecb7be6a
7 files changed
+120 -91

No files matched your search

+1 -1
View File
@@ -195,7 +195,7 @@ module OpenNebula
# @param uname [String] of the user
# @param token [String] the login token, if empty OpenNebula will
# generate one
# @param expire [String] valid period of the token in secs. If <= 0
# @param expire [String] valid period of the token in secs. If == 0
# the token will be reset
# @param egid [Integer] Effective GID to use with this token. To use
# the current GID and user groups set it to -1
@@ -660,6 +660,7 @@ define(function(require) {
require('./vms-tab/dialogs/vnc'),
require('./vms-tab/dialogs/spice'),
//require('./vms-tab/dialogs/saveas-template')
require('./users-tab/dialogs/login-token')
];
var Actions = require('./vms-tab/actions');
@@ -42,6 +42,7 @@ define(function(require) {
var PANEL_ID = require('./user-config/panelId');
var RESOURCE = "User";
var XML_ROOT = "USER";
var LOGIN_TOKEN_DIALOG_ID = require('tabs/users-tab/dialogs/login-token/dialogId');
/*
CONSTRUCTOR
@@ -92,14 +93,13 @@ define(function(require) {
$('#provision_user_views_select option[value="' + config['user_config']["default_view"] + '"]', context).attr('selected', 'selected');
var login_token = this.element.LOGIN_TOKEN.TOKEN;
if (login_token && login_token.length) {
$(".provision_login_token_current", context).show();
$(".provision_login_token_valid", context).text(Humanize.prettyTime(this.element.LOGIN_TOKEN.EXPIRATION_TIME));
$(".provision_login_token_value", context).text(this.element.LOGIN_TOKEN.TOKEN);
} else {
$(".provision_login_token_current", context).hide();
}
// Login token button
context.off("click", ".provision_login_token_button");
context.on("click", ".provision_login_token_button", function(){
Sunstone.getDialog(LOGIN_TOKEN_DIALOG_ID).setParams({element: that.element});
Sunstone.getDialog(LOGIN_TOKEN_DIALOG_ID).reset();
Sunstone.getDialog(LOGIN_TOKEN_DIALOG_ID).show();
});
$("#provision_change_password_form").submit(function() {
var pw = $('#provision_new_password', this).val();
@@ -136,37 +136,6 @@ define(function(require) {
return false;
});
$("#provision_login_token_form", context).submit(function() {
$(".provision_login_token_button", context).html('<i class="fa fa-spinner fa-spin"/>')
OpenNebula.User.login({
data : {
id: "-1",
'username': that.element.NAME,
//token
//expire
},
success: function(req, response){
OpenNebula.User.show({
data : {
id: that.element.ID
},
success: function(request, user_json){
$(".provision_login_token_button", context).text(Locale.tr("Get a login token"));
$(".provision_login_token_current", context).show();
$(".provision_login_token_valid", context).text(Humanize.prettyTime(user_json.USER.LOGIN_TOKEN.EXPIRATION_TIME));
$(".provision_login_token_value", context).text(user_json.USER.LOGIN_TOKEN.TOKEN);
},
error: Notifier.onError
});
},
error: Notifier.onError
});
return false;
});
$("#provision_change_view_form").submit(function() {
var sunstone_setting = {DEFAULT_VIEW : $('#provision_user_views_select', this).val()};
Sunstone.runAction("User.append_sunstone_setting_refresh", that.element.ID, sunstone_setting);
@@ -194,28 +194,15 @@
{{tr "Login Token"}}
</a>
<div id="provision_login_token_accordion" class="accordion-content" data-tab-content>
<br>
<form id="provision_login_token_form">
<br/>
<p>
{{tr "A login token acts as a password and can be used to authenticate with OpenNebula through Sunstone, the CLI, or the API"}}
</p>
<div class="provision_login_token_current">
<p>{{tr "Current login token, valid until"}} <span class="provision_login_token_valid"></span></p>
<br/>
<pre class="text-center provision_login_token_value"></pre>
<br/>
<br/>
<p class="label secondary radius float-center text-center">
<i class="fa fa-warning"/> {{tr "Getting a new token will invalidate the current one"}}
</p>
<br/>
<p>
{{tr "A login token acts as a password and can be used to authenticate with OpenNebula through Sunstone, the CLI, or the API"}}
</p>
<div class="row">
<div class="large-12 columns">
<button href"#" type="submit" class="button large radius large-12 small-12 provision_login_token_button">{{tr "Manage login tokens"}}</button>
</div>
<div class="row">
<div class="large-12 columns">
<button href"#" type="submit" class="button large radius large-12 small-12 provision_login_token_button">{{tr "Get a login token"}}</button>
</div>
</div>
</form>
</div>
</div>
</dd>
</dl>
@@ -51,6 +51,7 @@ define(function(require) {
Dialog.prototype.onShow = _onShow;
Dialog.prototype.setup = _setup;
Dialog.prototype.setParams = _setParams;
Dialog.prototype.loginSuccess = _loginSuccess;
return Dialog;
@@ -67,15 +68,63 @@ define(function(require) {
}
function _html() {
var tokens = [];
if (this.element != undefined && this.element.LOGIN_TOKEN != undefined){
if ($.isArray(this.element.LOGIN_TOKEN)){
tokens = this.element.LOGIN_TOKEN;
} else {
tokens = [this.element.LOGIN_TOKEN];
}
}
$.each(tokens, function(){
if (this.EGID == -1){
this.EGROUP = Locale.tr("None");
} else {
this.EGROUP = OpenNebula.Group.getName(this.EGID);
}
});
return TemplateHTML({
'dialogId': this.dialogId,
'element': this.element
'tokens': tokens
});
}
function _setup(context) {
var that = this;
context.on("click", "i.remove-tab", function(){
var tr = $(this).closest('tr');
$(this).closest('td').html('<i class="fa fa-spinner fa-spin"/>')
var token = $(".token-text", tr).text();
OpenNebula.User.login({
data : {
id: "-1",
'username': that.element.NAME,
'token': token,
'expire': 0
},
success: function(req, response){
OpenNebula.User.show({
data : {
id: that.element.ID
},
success: that.loginSuccess.bind(that),
error: function(request, error_json){
Sunstone.getDialog(DIALOG_ID).hide();
Notifier.onError(request, error_json);
}
});
},
error: Notifier.onError
});
});
$("#token_btn", context).click(function(){
$("#token_btn", context).html('<i class="fa fa-spinner fa-spin"/>')
@@ -92,18 +141,7 @@ define(function(require) {
data : {
id: that.element.ID
},
success: function(request, user_json){
Sunstone.getDialog(DIALOG_ID).hide();
Sunstone.getDialog(DIALOG_ID).setParams({element: user_json.USER});
Sunstone.getDialog(DIALOG_ID).reset();
Sunstone.getDialog(DIALOG_ID).show();
if (Sunstone.getTab() == USERS_TAB_ID){
Sunstone.runAction('User.refresh');
} else {
Sunstone.runAction('Settings.refresh');
}
},
success: that.loginSuccess.bind(that),
error: function(request, error_json){
Sunstone.getDialog(DIALOG_ID).hide();
Notifier.onError(request, error_json);
@@ -117,6 +155,32 @@ define(function(require) {
return false;
}
function _loginSuccess(req, response){
var that = this;
OpenNebula.User.show({
data : {
id: that.element.ID
},
success: function(request, user_json){
Sunstone.getDialog(DIALOG_ID).hide();
Sunstone.getDialog(DIALOG_ID).setParams({element: user_json.USER});
Sunstone.getDialog(DIALOG_ID).reset();
Sunstone.getDialog(DIALOG_ID).show();
if (Sunstone.getTab() == USERS_TAB_ID){
Sunstone.runAction('User.refresh');
} else {
Sunstone.runAction('Settings.refresh');
}
},
error: function(request, error_json){
Sunstone.getDialog(DIALOG_ID).hide();
Notifier.onError(request, error_json);
}
});
}
function _onShow(context) {
var tabId = Sunstone.getTab();
@@ -14,7 +14,7 @@
{{! limitations under the License. }}
{{! -------------------------------------------------------------------------- }}
<div id="{{dialogId}}" class="reveal" role="dialog" data-reveal >
<div id="{{dialogId}}" class="large reveal" role="dialog" data-reveal >
<div class="row">
<div class="large-12 columns">
<h3 class="subheader">{{tr "Login Token"}}</h3>
@@ -30,26 +30,34 @@
</p>
</div>
</div>
{{#if element.LOGIN_TOKEN.TOKEN}}
{{#if tokens}}
<div class="row">
<div class="large-12 columns">
<p>{{tr "Current login token, valid until"}} {{humanizeTime element.LOGIN_TOKEN.EXPIRATION_TIME}}</p>
<br/>
<pre class="text-center">{{element.LOGIN_TOKEN.TOKEN}}</pre>
<br/>
<br/>
<table>
<thead>
<tr>
<th>{{tr "Expiration"}}</th>
<th>{{tr "Target Group"}}</th>
<th>{{tr "Token"}}</th>
<th></th>
</tr>
</thead>
<tbody>
{{#each tokens}}
<tr>
<td>{{humanizeTime EXPIRATION_TIME}}</td>
<td>{{EGROUP}}</td>
<td class="token-text"><pre>{{TOKEN}}</pre></td>
<td>
<a href="#"><i class="fa fa-times-circle remove-tab"></i></a>
</td>
</tr>
{{/each}}
</tbody>
</table>
</div>
</div>
{{/if}}
<div class="row">
<div class="large-12 columns">
{{#if element.LOGIN_TOKEN.TOKEN}}
<p class="label secondary radius right">
<i class="fa fa-warning"/> {{tr "Getting a new token will invalidate the current one"}}
</p>
{{/if}}
</div>
</div>
<div class="row">
<button id="token_btn" type="button" class="button radius right">
{{tr "Get a new token"}}
@@ -98,7 +98,7 @@
<td class="key_td">{{tr "Login token"}}</td>
<td class="value_td">
<button id="login_token" type="button" class="button small radius secondary" style="min-width:80%">
{{tr "Get a login token"}}
{{tr "Manage login tokens"}}
</button>
</td>
<td/>