private cloud update 2020-06-14

1. completed i18n for private cloud (foreground and background)
2. fixed issues
This commit is contained in:
strawmanbobi
2020-06-14 11:56:18 +08:00
parent 7fc902a540
commit f94a89faef
28 changed files with 899 additions and 1227 deletions

View File

@@ -5,39 +5,39 @@
require('../mini_poem/configuration/constants');
var AdminAuth = require('../authentication/admin_auth.js');
var RequestSender = require('../mini_poem/http/request.js');
let AdminAuth = require('../authentication/admin_auth.js');
let RequestSender = require('../mini_poem/http/request.js');
var ErrorCode = require('../constants/error_code.js');
var logger = require('../mini_poem/logging/logger4js').helper;
let ErrorCode = require('../constants/error_code.js');
let logger = require('../mini_poem/logging/logger4js').helper;
var errorCode = new ErrorCode();
let errorCode = new ErrorCode();
var adminAuth = new AdminAuth(REDIS_HOST, REDIS_PORT, null, REDIS_PASSWORD);
let adminAuth = new AdminAuth(REDIS_HOST, REDIS_PORT, null, REDIS_PASSWORD);
var SIGN_IN_SERVICE = "/irext/certificate/admin_login";
var CHANGE_PASSWORD_SERVICE = "/irext/certificate/change_pw";
let SIGN_IN_SERVICE = "/irext/certificate/admin_login";
let CHANGE_PASSWORD_SERVICE = "/irext/certificate/change_pw";
exports.adminLoginWorkUnit = function (userName, password, callback) {
var queryParams = new Map();
let queryParams = new Map();
var requestSender =
let requestSender =
new RequestSender(EXTERNAL_SERVER_ADDRESS,
EXTERNAL_SERVER_PORT,
SIGN_IN_SERVICE,
queryParams);
var signinInfo = {
let signinInfo = {
user_name : userName,
password : password
};
requestSender.sendPostRequest(signinInfo,
function(signInRequestErr, signInResponse) {
if (signInRequestErr == errorCode.SUCCESS.code && null != signInResponse) {
var resp = JSON.parse(signInResponse);
if (undefined != resp.entity) {
var admin = resp.entity;
var token,
if (signInRequestErr === errorCode.SUCCESS.code && null != signInResponse) {
let resp = JSON.parse(signInResponse);
if (undefined !== resp.entity) {
let admin = resp.entity;
let token,
key,
ttl = 24 * 60 * 60 * 14,
timeStamp,
@@ -46,11 +46,11 @@ exports.adminLoginWorkUnit = function (userName, password, callback) {
token = admin.token;
key = "admin_" + admin.id;
adminAuth.setAuthInfo(key, token, ttl, function(setAdminAuthErr) {
if (errorCode.SUCCESS.code == setAdminAuthErr.code) {
if (errorCode.SUCCESS.code === setAdminAuthErr.code) {
key = "admin_name_" + admin.id;
name = admin.user_name;
adminAuth.setAuthInfo(key, name, ttl, function(setAdminNameErr) {
if (errorCode.SUCCESS.code == setAdminNameErr.code) {
if (errorCode.SUCCESS.code === setAdminNameErr.code) {
admin.token = token;
}
callback(setAdminNameErr, admin);
@@ -68,9 +68,9 @@ exports.adminLoginWorkUnit = function (userName, password, callback) {
};
exports.verifyTokenWorkUnit = function (id, token, callback) {
var key = "admin_" + id;
let key = "admin_" + id;
adminAuth.validateAuthInfo(key, token, function(validateAdminAuthErr, result) {
if (validateAdminAuthErr.code != errorCode.SUCCESS.code) {
if (validateAdminAuthErr.code !== errorCode.SUCCESS.code) {
logger.info("token validation failed");
}
callback(validateAdminAuthErr);
@@ -78,12 +78,12 @@ exports.verifyTokenWorkUnit = function (id, token, callback) {
};
exports.verifyTokenWithPermissionWorkUnit = function (id, token, permissions, callback) {
var key = "admin_" + id;
let key = "admin_" + id;
adminAuth.validateAuthInfo(key, token, function(validateAdminAuthErr, result) {
if (validateAdminAuthErr.code == errorCode.SUCCESS.code) {
if (validateAdminAuthErr.code === errorCode.SUCCESS.code) {
logger.info("token validation successfully");
if (undefined != result && null != result && "" != result) {
if (result.indexOf(permissions) != -1) {
if (undefined !== result && null !== result && "" !== result) {
if (result.indexOf(permissions) !== -1) {
callback(errorCode.SUCCESS);
} else {
logger.info("permission do not match");
@@ -98,23 +98,23 @@ exports.verifyTokenWithPermissionWorkUnit = function (id, token, permissions, ca
};
exports.sendChangePwMailWorkUnit = function (userName, callbackURL, callback) {
var queryParams = new Map();
let queryParams = new Map();
var requestSender =
let requestSender =
new RequestSender(EXTERNAL_SERVER_ADDRESS,
EXTERNAL_SERVER_PORT,
CHANGE_PASSWORD_SERVICE,
queryParams);
var userInfo = {
let userInfo = {
user_name : userName,
callback_url :callbackURL
};
requestSender.sendPostRequest(userInfo,
function(changePwRequestErr, changePwResponse) {
if (changePwRequestErr == errorCode.SUCCESS.code && null != changePwResponse) {
var resp = JSON.parse(changePwResponse);
if (undefined != resp.status && errorCode.SUCCESS == resp.status) {
if (changePwRequestErr === errorCode.SUCCESS.code && null != changePwResponse) {
let resp = JSON.parse(changePwResponse);
if (undefined !== resp.status && errorCode.SUCCESS === resp.status) {
callback(errorCode.SUCCESS);
} else {
callback(errorCode.FAILED);

File diff suppressed because it is too large Load Diff

View File

@@ -5,31 +5,31 @@
// global inclusion
require('../mini_poem/configuration/constants');
var logger = require('../mini_poem/logging/logger4js').helper;
let logger = require('../mini_poem/logging/logger4js').helper;
// local inclusion
var Category = require('../model/category_dao.js');
var Brand = require('../model/brand_dao.js');
var City = require('../model/city_dao.js');
var RemoteIndex = require('../model/remote_index_dao.js');
let Category = require('../model/category_dao.js');
let Brand = require('../model/brand_dao.js');
let City = require('../model/city_dao.js');
let RemoteIndex = require('../model/remote_index_dao.js');
var Enums = require('../constants/enums.js');
var ErrorCode = require('../constants/error_code.js');
let Enums = require('../constants/enums.js');
let ErrorCode = require('../constants/error_code.js');
var enums = new Enums();
var errorCode = new ErrorCode();
let enums = new Enums();
let errorCode = new ErrorCode();
var async = require('async');
let async = require('async');
exports.countRemoteWorkUnit = function(callback) {
var conditions = {
let conditions = {
status: enums.ITEM_VALID
};
Category.countCategories(conditions, function(countCategoriesErr, categoriesCount) {
Brand.countBrands(conditions, function(countBrandsErr, brandsCount) {
RemoteIndex.countRemoteIndexes(conditions, function(countRemoteIndexesErr, remoteIndexesCount) {
var statInfo = new Object();
let statInfo = {};
statInfo.categories_count = categoriesCount;
statInfo.brands_count = brandsCount;
statInfo.remote_indexes_count = remoteIndexesCount;
@@ -40,29 +40,29 @@ exports.countRemoteWorkUnit = function(callback) {
};
exports.statCategoriesWorkUnit = function(callback) {
var conditions = {
let conditions = {
status: enums.ITEM_VALID
};
var retCategoriesCount = [];
let retCategoriesCount = [];
Category.listCategories(conditions, 0, 200, "id", function(findCategoriesErr, categories) {
if (errorCode.FAILED.code == findCategoriesErr.code) {
if (errorCode.FAILED.code === findCategoriesErr.code) {
logger.error("failed to find categories");
callback(findCategoriesErr, null);
} else {
async.eachSeries(categories, function (category, innerCallback) {
var categoryName = category.name;
var categoryID = category.id;
if (enums.CATEGORY_STB != categoryID) {
var countConditions = {
let categoryName = category.name;
let categoryID = category.id;
if (enums.CATEGORY_STB !== categoryID) {
let countConditions = {
category_id: categoryID,
status: enums.ITEM_VALID
};
Brand.countBrands(countConditions,
function(countBrandsErr, brandsCount) {
if (errorCode.SUCCESS.code == countBrandsErr.code) {
var categoryStat = new Object();
if (errorCode.SUCCESS.code === countBrandsErr.code) {
let categoryStat = {};
categoryStat.id = categoryID;
categoryStat.name = categoryName;
categoryStat.brands_count = brandsCount;
@@ -73,11 +73,11 @@ exports.statCategoriesWorkUnit = function(callback) {
innerCallback();
});
} else {
var countConditions = "code LIKE '__0000';";
let countConditions = "code LIKE '__0000';";
City.countCities(countConditions,
function(countCitiesErr, citiesCount) {
if (errorCode.SUCCESS.code == countCitiesErr.code) {
var categoryStat = new Object();
if (errorCode.SUCCESS.code === countCitiesErr.code) {
let categoryStat = {};
categoryStat.id = categoryID;
categoryStat.name = categoryName;
categoryStat.brands_count = citiesCount[0].number;
@@ -97,31 +97,31 @@ exports.statCategoriesWorkUnit = function(callback) {
};
exports.statBrandsWorkUnit = function (categoryID, callback) {
var conditions = {
let conditions = {
category_id: categoryID,
status: enums.ITEM_VALID
};
var retBrandsCount = [];
let retBrandsCount = [];
Brand.listBrands(conditions, 0, 200, "priority", function(findBrandsErr, brands) {
if (errorCode.FAILED.code == findBrandsErr.code) {
if (errorCode.FAILED.code === findBrandsErr.code) {
logger.error("failed to find brands");
callback(findBrandsErr, null);
} else {
async.eachSeries(brands, function (brand, innerCallback) {
var brandName = brand.name;
var brandID = brand.id;
let brandName = brand.name;
let brandID = brand.id;
if (enums.CATEGORY_STB != categoryID) {
var countConditions = {
if (enums.CATEGORY_STB !== categoryID) {
let countConditions = {
brand_id: brandID,
status: enums.ITEM_VALID
};
RemoteIndex.countRemoteIndexes(countConditions,
function(countRemoteIndexesErr, remoteIndexesCount) {
if (errorCode.SUCCESS.code == countRemoteIndexesErr.code) {
var brandStat = new Object();
if (errorCode.SUCCESS.code === countRemoteIndexesErr.code) {
let brandStat = {};
brandStat.id = brandID;
brandStat.name = brandName;
brandStat.remote_indexes_count = remoteIndexesCount;
@@ -140,22 +140,22 @@ exports.statBrandsWorkUnit = function (categoryID, callback) {
};
exports.statCitiesWorkUnit = function (callback) {
var retCitiesCount = [];
let retCitiesCount = [];
City.listProvinces(function(listProvincesErr, provinces) {
if (errorCode.FAILED.code == listProvincesErr.code) {
if (errorCode.FAILED.code === listProvincesErr.code) {
logger.error("failed to find brands");
callback(listProvincesErr, null);
} else {
async.eachSeries(provinces, function (province, innerCallback) {
var provinceName = province.name;
var provinceCode = province.code;
var provincePrefix = provinceCode.substring(0, 2);
var countConditions = "code LIKE '" + provincePrefix + "__00' AND code <> '" + provincePrefix + "0000';";
let provinceName = province.name;
let provinceCode = province.code;
let provincePrefix = provinceCode.substring(0, 2);
let countConditions = "code LIKE '" + provincePrefix + "__00' AND code <> '" + provincePrefix + "0000';";
City.countCities(countConditions,
function(countCitiesErr, citiesCount) {
if (errorCode.SUCCESS.code == countCitiesErr.code) {
var cityStat = new Object();
if (errorCode.SUCCESS.code === countCitiesErr.code) {
let cityStat = {};
cityStat.name = provinceName;
cityStat.city_count = citiesCount[0].number;
retCitiesCount.push(cityStat);