Cloud fixes

revert-70aa11f8
Rasika Perera 7 years ago
parent 3d3b7af168
commit 9683b066dd

@ -34,6 +34,7 @@
"username": "admin", "username": "admin",
"password": "admin" "password": "admin"
}, },
"cloudMgtHost" : "https://cloudmgt.cloudstaging.wso2.com",
"cloudMgtIndexPage": "https://cloudmgt.cloud.wso2.com/cloudmgt/site/pages/index.jag", "cloudMgtIndexPage": "https://cloudmgt.cloud.wso2.com/cloudmgt/site/pages/index.jag",
"dropDown": { "dropDown": {
"Upgrade Now": { "Upgrade Now": {

@ -50,9 +50,11 @@ function onRequest(context) {
var BILLING_INFO_RETRY_COUNT_KEY = 'BILLING_INFO_RETRY_COUNT_' + context.user.domain; var BILLING_INFO_RETRY_COUNT_KEY = 'BILLING_INFO_RETRY_COUNT_' + context.user.domain;
if (viewModal.Main.Account.billingEnabled) { if (viewModal.Main.Account.billingEnabled) {
var cookie = getLoginCookie();
if (!session.get(BILLING_INFO_KEY) || daysAfterLastCheck(session.get(BILLING_INFO_KEY).lastChecked) > 1) { if (!session.get(BILLING_INFO_KEY) || daysAfterLastCheck(session.get(BILLING_INFO_KEY).lastChecked) > 1) {
session.put(BILLING_INFO_RETRY_COUNT_KEY, 0); 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); var billingInfo = session.get(BILLING_INFO_KEY);
@ -63,6 +65,7 @@ function onRequest(context) {
var cloudMgtIndexPage = viewModal.Main.Account.cloudMgtIndexPage; var cloudMgtIndexPage = viewModal.Main.Account.cloudMgtIndexPage;
if (!billingInfo) { if (!billingInfo) {
recordFirstLogin(serviceUrl, cookie, 1);
log.info("Access denied for tenant: " + context.user.domain log.info("Access denied for tenant: " + context.user.domain
+ " with a NULL subscription. Redirected to CloudMgt"); + " with a NULL subscription. Redirected to CloudMgt");
response.sendRedirect(cloudMgtIndexPage); response.sendRedirect(cloudMgtIndexPage);
@ -158,14 +161,22 @@ function onRequest(context) {
viewModal.isCloud = mdmProps.isCloud; viewModal.isCloud = mdmProps.isCloud;
return viewModal; return viewModal;
function getBillingData(cookie, attempt) { function getBillingData(serviceUrl, cookie, attempt) {
serviceUrl = "https://cloudmgt.cloudstaging.wso2.com/cloudmgt/site/blocks/admin/admin.jag";
result = post(serviceUrl, result = post(serviceUrl,
'action=getBillingStatusOfTenant&tenantDomain=' + context.user.domain + '&cloudType=device_cloud', 'action=getBillingStatusOfTenant&tenantDomain=' + context.user.domain + '&cloudType=device_cloud',
{"Cookie": cookie}); {"Cookie": cookie});
if (result.data) { if (result.data) {
var billing = JSON.parse(result.data).data; var billing = JSON.parse(result.data).data;
if (!billing.isPaidAccount && billing.billingPlanStatus === status.INACTIVE) { 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);
}
}
}
function recordFirstLogin(serviceUrl, cookie, attempt){
var rv = post(serviceUrl, var rv = post(serviceUrl,
'action=informFirstLogin&tenantDomain=' + context.user.domain + '&cloudType=device_cloud', 'action=informFirstLogin&tenantDomain=' + context.user.domain + '&cloudType=device_cloud',
{"Cookie": cookie}); {"Cookie": cookie});
@ -173,14 +184,9 @@ function onRequest(context) {
var failStr = "First login capturing failed"; var failStr = "First login capturing failed";
var successStr = "First login captured successfully"; var successStr = "First login captured successfully";
if (rv.data.substring(0, failStr.length) === failStr && attempt < 3) { if (rv.data.substring(0, failStr.length) === failStr && attempt < 3) {
getBillingData(cookie, ++attempt); //retry recordFirstLogin(serviceUrl, cookie, ++attempt); //retry
} else if(rv.data.substring(0, successStr.length) === successStr) {
getBillingData(cookie); //get expiry details
}
} else { } else {
session.put(BILLING_INFO_KEY, JSON.parse(result.data).data); getBillingData(serviceUrl, cookie, ++attempt); //get expiry details
session.put(BILLING_INFO_RETRY_COUNT_KEY, 0);
}
} }
} }
@ -191,7 +197,7 @@ function onRequest(context) {
session.put(BILLING_INFO_RETRY_COUNT_KEY, retryCount); session.put(BILLING_INFO_RETRY_COUNT_KEY, retryCount);
var username = viewModal.Main.Account.billingApi.username; var username = viewModal.Main.Account.billingApi.username;
var password = viewModal.Main.Account.billingApi.password; 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, var result = post(serviceUrl, 'action=login&userName=' + username + '&password=' + password,
{"Content-Type": "application/x-www-form-urlencoded"}); {"Content-Type": "application/x-www-form-urlencoded"});
if (result.data && result.data.trim() === "true") { if (result.data && result.data.trim() === "true") {

Loading…
Cancel
Save