Skip to content

Commit b1ef747

Browse files
author
Jessica Wang
committed
CLOUDSTACK-1065: cloudstack UI - AWS Style Regions - when switching region, set location without parameters.
1 parent 265cf42 commit b1ef747

4 files changed

Lines changed: 33 additions & 28 deletions

File tree

ui/scripts/cloud.core.callbacks.js

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,25 +52,31 @@ Below is a sample login attempt
5252
var clientApiUrl = "/client/api";
5353
var clientConsoleUrl = "/client/console";
5454

55-
$(document).ready(function() {
56-
/*
57-
condition 1: If window.location.href contains parameter 'loginUrl', save the parameter's value to a cookie, then reload the page without any URL parameter.
58-
(After the page is reloaded without any URL parameter, it will fall in condition 2.)
59-
*/
60-
if ($.urlParam('loginUrl') != 0) {
61-
$.cookie('loginUrl', $.urlParam('loginUrl'), { expires: 1});
62-
document.location.href = window.location.href.substring(0, window.location.href.indexOf('?'));
63-
}
55+
$(document).ready(function() {
6456

65-
/*
66-
condition 2: If window.location.href does not contain parameter 'loginUrl' but cookie 'loginUrl' exists,
67-
save the cookie's value to g_regionUrlParam (a global variable for switching regions),
68-
then call login API to set g_loginResponse (a global variable for single-sign-on).
69-
*/
70-
else if($.cookie('loginUrl') != null) {
71-
g_regionUrlParam = '?loginUrl=' + $.cookie('loginUrl');
57+
var url = $.urlParam("loginUrl");
58+
if (url != undefined && url != null && url.length > 0) {
59+
url = unescape(clientApiUrl+"?"+url);
60+
$.ajax({
61+
url: url,
62+
dataType: "json",
63+
async: false,
64+
success: function(json) {
65+
g_loginResponse = json.loginresponse;
66+
},
67+
error: function() {
68+
onLogoutCallback();
69+
// This means the login failed. You should redirect to your login page.
70+
},
71+
beforeSend: function(XMLHttpRequest) {
72+
return true;
73+
}
74+
});
75+
}
76+
else if(window.name != null && window.name.indexOf("command=login") != -1) { //from region switching
77+
g_loginCmdText = window.name;
7278
$.ajax({
73-
url: unescape(clientApiUrl + "?" + $.cookie('loginUrl')),
79+
url: clientApiUrl + "?" + window.name,
7480
dataType: "json",
7581
async: false,
7682
success: function(json) {
@@ -85,7 +91,6 @@ $(document).ready(function() {
8591
}
8692
});
8793
}
88-
8994
});
9095

9196

ui/scripts/cloudStack.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,11 @@
251251
array1.push("&domain=" + encodeURIComponent("/"));
252252
}
253253

254-
g_regionUrlParam = '?loginUrl=' + escape("command=login" + array1.join("") + "&response=json");
255-
$.cookie('loginUrl', escape("command=login" + array1.join("") + "&response=json"), { expires: 1});
254+
g_loginCmdText = "command=login" + array1.join("") + "&response=json";
256255

257256
$.ajax({
258257
type: "POST",
259-
data: "command=login" + array1.join("") + "&response=json",
258+
data: g_loginCmdText,
260259
dataType: "json",
261260
async: false,
262261
success: function(json) {
@@ -386,7 +385,8 @@
386385
g_timezoneoffset = null;
387386
g_timezone = null;
388387
g_supportELB = null;
389-
g_regionUrlParam = null;
388+
g_loginCmdText = null;
389+
window.name = '';
390390

391391
$.cookie('JSESSIONID', null);
392392
$.cookie('sessionKey', null);
@@ -398,8 +398,7 @@
398398
$.cookie('timezoneoffset', null);
399399
$.cookie('timezone', null);
400400
$.cookie('supportELB', null);
401-
$.cookie('loginUrl', null);
402-
401+
403402
if(onLogoutCallback()) { //onLogoutCallback() will set g_loginResponse(single-sign-on variable) to null, then bypassLoginCheck() will show login screen.
404403
document.location.reload(); //when onLogoutCallback() returns true, reload the current document.
405404
}
@@ -466,7 +465,8 @@
466465

467466
document.title = 'CloudStack';
468467

469-
if ($.cookie('loginUrl') != null || $.urlParam('loginUrl') != 0) {
468+
if ($.urlParam('loginUrl') != 0
469+
||(window.name != null && window.name.indexOf("command=login") != -1)) {
470470
// SSO
471471
loginArgs.hideLoginScreen = true;
472472
}

ui/scripts/sharedFunctions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var g_role = null; // roles - root, domain-admin, ro-admin, user
2020
var g_username = null;
2121
var g_account = null;
2222
var g_domainid = null;
23-
var g_regionUrlParam = null;
23+
var g_loginCmdText = null;
2424
var g_enableLogging = false;
2525
var g_timezoneoffset = null;
2626
var g_timezone = null;

ui/scripts/ui-custom/regions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@
8989
closeRegionSelector({
9090
complete: function() {
9191
$('#container').prepend($('<div>').addClass('loading-overlay'));
92-
93-
document.location.href = url + g_regionUrlParam;
92+
window.name = g_loginCmdText;
93+
document.location.href = url;
9494
}
9595
});
9696
};

0 commit comments

Comments
 (0)