From 9683b066dd22310ea1c6c140a419f9a0b7a769f7 Mon Sep 17 00:00:00 2001 From: Rasika Perera Date: Fri, 14 Jul 2017 11:08:18 +0530 Subject: [PATCH] Cloud fixes --- .../devicemgt/app/conf/toplink-menu.json | 1 + .../user-menu.js | 38 +++++++++++-------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/toplink-menu.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/toplink-menu.json index 26a61985509..aaac58445a1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/toplink-menu.json +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/toplink-menu.json @@ -34,6 +34,7 @@ "username": "admin", "password": "admin" }, + "cloudMgtHost" : "https://cloudmgt.cloudstaging.wso2.com", "cloudMgtIndexPage": "https://cloudmgt.cloud.wso2.com/cloudmgt/site/pages/index.jag", "dropDown": { "Upgrade Now": { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.header.cloud.user-menu/user-menu.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.header.cloud.user-menu/user-menu.js index 2e41a3e2e60..cec47088a8e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.header.cloud.user-menu/user-menu.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.header.cloud.user-menu/user-menu.js @@ -50,9 +50,11 @@ function onRequest(context) { var BILLING_INFO_RETRY_COUNT_KEY = 'BILLING_INFO_RETRY_COUNT_' + context.user.domain; if (viewModal.Main.Account.billingEnabled) { + var cookie = getLoginCookie(); if (!session.get(BILLING_INFO_KEY) || daysAfterLastCheck(session.get(BILLING_INFO_KEY).lastChecked) > 1) { session.put(BILLING_INFO_RETRY_COUNT_KEY, 0); - getBillingData(getLoginCookie()); + var serviceUrl = viewModal.Main.Account.cloudMgtHost + "/cloudmgt/site/blocks/admin/admin.jag"; + getBillingData(serviceUrl, cookie, 1); } var billingInfo = session.get(BILLING_INFO_KEY); @@ -63,6 +65,7 @@ function onRequest(context) { var cloudMgtIndexPage = viewModal.Main.Account.cloudMgtIndexPage; if (!billingInfo) { + recordFirstLogin(serviceUrl, cookie, 1); log.info("Access denied for tenant: " + context.user.domain + " with a NULL subscription. Redirected to CloudMgt"); response.sendRedirect(cloudMgtIndexPage); @@ -158,25 +161,14 @@ function onRequest(context) { viewModal.isCloud = mdmProps.isCloud; return viewModal; - function getBillingData(cookie, attempt) { - serviceUrl = "https://cloudmgt.cloudstaging.wso2.com/cloudmgt/site/blocks/admin/admin.jag"; + function getBillingData(serviceUrl, cookie, attempt) { result = post(serviceUrl, 'action=getBillingStatusOfTenant&tenantDomain=' + context.user.domain + '&cloudType=device_cloud', {"Cookie": cookie}); if (result.data) { var billing = JSON.parse(result.data).data; - if (!billing.isPaidAccount && billing.billingPlanStatus === status.INACTIVE) { - var rv = post(serviceUrl, - 'action=informFirstLogin&tenantDomain=' + context.user.domain + '&cloudType=device_cloud', - {"Cookie": cookie}); - if (!attempt) attempt = 1; - var failStr = "First login capturing failed"; - var successStr = "First login captured successfully"; - if (rv.data.substring(0, failStr.length) === failStr && attempt < 3) { - getBillingData(cookie, ++attempt); //retry - } else if(rv.data.substring(0, successStr.length) === successStr) { - getBillingData(cookie); //get expiry details - } + if (!billing || !billing.isPaidAccount && billing.billingPlanStatus === status.INACTIVE) { + recordFirstLogin(serviceUrl, cookie, attempt); } else { session.put(BILLING_INFO_KEY, JSON.parse(result.data).data); session.put(BILLING_INFO_RETRY_COUNT_KEY, 0); @@ -184,6 +176,20 @@ function onRequest(context) { } } + function recordFirstLogin(serviceUrl, cookie, attempt){ + var rv = post(serviceUrl, + 'action=informFirstLogin&tenantDomain=' + context.user.domain + '&cloudType=device_cloud', + {"Cookie": cookie}); + if (!attempt) attempt = 1; + var failStr = "First login capturing failed"; + var successStr = "First login captured successfully"; + if (rv.data.substring(0, failStr.length) === failStr && attempt < 3) { + recordFirstLogin(serviceUrl, cookie, ++attempt); //retry + } else { + getBillingData(serviceUrl, cookie, ++attempt); //get expiry details + } + } + function getLoginCookie(){ var retryCount = session.get(BILLING_INFO_RETRY_COUNT_KEY) || 0; if (retryCount <= 3) { @@ -191,7 +197,7 @@ function onRequest(context) { session.put(BILLING_INFO_RETRY_COUNT_KEY, retryCount); var username = viewModal.Main.Account.billingApi.username; var password = viewModal.Main.Account.billingApi.password; - var serviceUrl = "https://cloudmgt.cloudstaging.wso2.com/cloudmgt/site/blocks/user/authenticate/ajax/login.jag"; + var serviceUrl = viewModal.Main.Account.cloudMgtHost + "/cloudmgt/site/blocks/user/authenticate/ajax/login.jag"; var result = post(serviceUrl, 'action=login&userName=' + username + '&password=' + password, {"Content-Type": "application/x-www-form-urlencoded"}); if (result.data && result.data.trim() === "true") {