Merge pull request #845 from rasika/cloud-fixes

Cloud fixes
revert-70aa11f8
Rasika Perera 7 years ago committed by GitHub
commit c6cce05b11

@ -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,25 +161,14 @@ 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) {
var rv = post(serviceUrl, recordFirstLogin(serviceUrl, cookie, attempt);
'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
}
} else { } else {
session.put(BILLING_INFO_KEY, JSON.parse(result.data).data); session.put(BILLING_INFO_KEY, JSON.parse(result.data).data);
session.put(BILLING_INFO_RETRY_COUNT_KEY, 0); 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(){ function getLoginCookie(){
var retryCount = session.get(BILLING_INFO_RETRY_COUNT_KEY) || 0; var retryCount = session.get(BILLING_INFO_RETRY_COUNT_KEY) || 0;
if (retryCount <= 3) { if (retryCount <= 3) {
@ -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