ui: refactor and use a unified unboxing helping method in cloudStack.js

Signed-off-by: Rohit Yadav <rohit.ya...@shapeblue.com>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/aafb40fe
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/aafb40fe
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/aafb40fe

Branch: refs/heads/saml2
Commit: aafb40fe7514dbc17240da8f4675f8973a8cedb8
Parents: 22a9052
Author: Rohit Yadav <rohit.ya...@shapeblue.com>
Authored: Mon Aug 18 04:56:54 2014 +0200
Committer: Rohit Yadav <rohit.ya...@shapeblue.com>
Committed: Mon Aug 25 17:33:26 2014 +0200

----------------------------------------------------------------------
 ui/scripts/cloudStack.js | 33 +++++++++++++++++----------------
 1 file changed, 17 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aafb40fe/ui/scripts/cloudStack.js
----------------------------------------------------------------------
diff --git a/ui/scripts/cloudStack.js b/ui/scripts/cloudStack.js
index edc7c21..38cf501 100644
--- a/ui/scripts/cloudStack.js
+++ b/ui/scripts/cloudStack.js
@@ -129,24 +129,25 @@
            i.e. calling listCapabilities API with g_sessionKey from 
$.cookie('sessionKey') will succeed,
            then userValid will be set to true, then an user object (instead of 
"false") will be returned, then login screen will be bypassed.
            */
+                    var unBoxCookieValue = function (cookieName) {
+                        var cookieValue = $.cookie(cookieName);
+                        if (cookieValue && cookieValue.length > 2 && 
cookieValue[0] === '"' && cookieValue[cookieValue.length-1] === '"') {
+                            cookieValue = cookieValue.slice(1, 
cookieValue.length-1);
+                            $.cookie(cookieName, cookieValue, { expires: 1 });
+                        }
+                        return cookieValue;
+                    };
                     g_mySession = $.cookie('JSESSIONID');
-                    g_sessionKey = $.cookie('sessionKey');
-                    // Unbox quotes from sessionKey cookie value
-                    if (g_sessionKey && g_sessionKey[0] === '"' && 
g_sessionKey[g_sessionKey.length-1] === '"') {
-                        g_sessionKey = g_sessionKey.slice(1, 
g_sessionKey.length-1);
-                        $.cookie('sessionKey', g_sessionKey, {
-                            expires: 1
-                        });
-                    }
-                    g_role = $.cookie('role');
-                    g_username = $.cookie('username');
-                    g_userid = $.cookie('userid');
-                    g_account = $.cookie('account');
-                    g_domainid = $.cookie('domainid');
-                    g_userfullname = $.cookie('userfullname');
-                    g_timezone = $.cookie('timezone');
+                    g_sessionKey = unBoxCookieValue('sessionKey');
+                    g_role = unBoxCookieValue('role');
+                    g_userid = unBoxCookieValue('userid');
+                    g_domainid = unBoxCookieValue('domainid');
+                    g_account = unBoxCookieValue('account');
+                    g_username = unBoxCookieValue('username');
+                    g_userfullname = unBoxCookieValue('userfullname');
+                    g_timezone = unBoxCookieValue('timezone');
                     if ($.cookie('timezoneoffset') != null)
-                        g_timezoneoffset = isNaN($.cookie('timezoneoffset')) ? 
null : parseFloat($.cookie('timezoneoffset'));
+                        g_timezoneoffset = 
isNaN(unBoxCookieValue('timezoneoffset')) ? null : 
parseFloat(unBoxCookieValue('timezoneoffset'));
                     else
                         g_timezoneoffset = null;
                 } else { //single-sign-on      (bypass login screen)

Reply via email to