fixed post request issue and admin verification issue
This commit is contained in:
@@ -61,7 +61,17 @@ function tokenValidation (req, res, next) {
|
||||
|
||||
if (req.url.indexOf("/irext/int/list_remote_indexes") != -1) {
|
||||
// override for get method
|
||||
adminID = req.query.id;
|
||||
adminID = req.query.admin_id;
|
||||
token = req.query.token;
|
||||
}
|
||||
if (req.url.indexOf("/irext/int/search_remote_indexes") != -1) {
|
||||
// override for get method
|
||||
adminID = req.query.admin_id;
|
||||
token = req.query.token;
|
||||
}
|
||||
if (req.url.indexOf("/irext/int/download_remote_index") != -1) {
|
||||
// override for get method
|
||||
adminID = req.query.admin_id;
|
||||
token = req.query.token;
|
||||
}
|
||||
if (req.url.indexOf("/irext/int") != -1) {
|
||||
|
||||
@@ -12,8 +12,6 @@ app.post('/irext/int/list_operators', intService.listOperators);
|
||||
app.post('/irext/int/list_categories', intService.listCategories);
|
||||
app.post('/irext/int/list_brands', intService.listBrands);
|
||||
app.post('/irext/int/list_ir_protocols', intService.listIRProtocols);
|
||||
app.post('/irext/int/search_remote_indexes', intService.searchRemoteIndexes);
|
||||
app.post('/irext/int/download_remote_index', intService.downloadRemoteIndex);
|
||||
|
||||
app.post('/irext/int/list_unpublished_brands', intService.listUnpublishedBrands);
|
||||
app.post('/irext/int/list_unpublished_remote_indexes', intService.listUnpublishedRemoteIndexes);
|
||||
@@ -29,4 +27,6 @@ app.post('/irext/int/publish_brands', intService.publishBrands);
|
||||
|
||||
app.post('/irext/int/create_protocol', intService.createProtocol);
|
||||
|
||||
app.get('/irext/int/list_remote_indexes', intService.listRemoteIndexes);
|
||||
app.get('/irext/int/list_remote_indexes', intService.listRemoteIndexes);
|
||||
app.get('/irext/int/search_remote_indexes', intService.searchRemoteIndexes);
|
||||
app.get('/irext/int/download_remote_index', intService.downloadRemoteIndex);
|
||||
@@ -202,9 +202,9 @@ exports.listRemoteIndexes = function (req, res) {
|
||||
* return : Remote Index List
|
||||
*/
|
||||
exports.searchRemoteIndexes = function (req, res) {
|
||||
var remoteMap = req.body.remote_map;
|
||||
var from = req.body.from;
|
||||
var count = req.body.count;
|
||||
var remoteMap = req.query.remote_map;
|
||||
var from = req.query.from;
|
||||
var count = req.query.count;
|
||||
|
||||
internalLogic.searchRemoteIndexesWorkUnit(remoteMap, from, count,
|
||||
function (listRemoteIndexesErr, remoteIndexes) {
|
||||
@@ -221,7 +221,7 @@ exports.searchRemoteIndexes = function (req, res) {
|
||||
* return : Redirect to binary download
|
||||
*/
|
||||
exports.downloadRemoteIndex = function (req, res) {
|
||||
var remoteIndexID = req.body.remote_index_id;
|
||||
var remoteIndexID = req.query.remote_index_id;
|
||||
|
||||
internalLogic.downloadRemoteBinCachedWorkUnit(remoteIndexID, function (serveBinErr, filePath) {
|
||||
if (errorCode.SUCCESS.code == serveBinErr.code) {
|
||||
@@ -265,8 +265,7 @@ exports.createRemoteIndex = function (req, res) {
|
||||
var remoteIndex;
|
||||
var filePath;
|
||||
var contentType;
|
||||
|
||||
var adminID = req.body.admin_id;
|
||||
var adminID;
|
||||
|
||||
form.on('file', function(field, file) {
|
||||
// rename the incoming file to the file's name
|
||||
@@ -289,6 +288,7 @@ exports.createRemoteIndex = function (req, res) {
|
||||
} else {
|
||||
logger.info("remote index form submitted successfully");
|
||||
remoteIndex = fields;
|
||||
adminID = remoteIndex.admin_id;
|
||||
filePath = files.remote_file.path;
|
||||
// set MIME to octet-stream as there might not be any contentType passed from the front-end form
|
||||
contentType = files.type || "application/octet-stream";
|
||||
@@ -430,7 +430,7 @@ exports.createProtocol = function (req, res) {
|
||||
var protocol;
|
||||
var filePath;
|
||||
var contentType;
|
||||
var adminID = req.body.admin_id;
|
||||
var adminID;
|
||||
|
||||
form.on('file', function(field, file) {
|
||||
fs.rename(file.path, form.uploadDir + "/" + file.name);
|
||||
@@ -450,6 +450,7 @@ exports.createProtocol = function (req, res) {
|
||||
} else {
|
||||
logger.info("protocol form submitted successfully");
|
||||
protocol = fields;
|
||||
adminID = protocol.admin_id;
|
||||
filePath = files.protocol_file.path;
|
||||
// set MIME to octet-stream as there might not be any contentType passed from the front-end form
|
||||
contentType = files.type || "application/octet-stream";
|
||||
|
||||
@@ -214,6 +214,7 @@
|
||||
<input type="file" class="form-control" name="remote_file" placeholder="Remote File" id="remote_file">
|
||||
</div>
|
||||
</div>
|
||||
<input type="hidden" name="admin_id" id="admin_id">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
@@ -454,6 +455,7 @@
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-primary" data-dismiss="modal" onclick="createProtocol();">确定添加</button>
|
||||
</div>
|
||||
<input type="hidden" id="protocol_admin_id" name="admin_id">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -122,14 +122,14 @@ function loadRemoteList(isSearch, remoteMap) {
|
||||
var url;
|
||||
|
||||
if (isSearch && remoteMap) {
|
||||
url = '/irext/int/search_remote_indexes?remote_map='+remoteMap+'&from=0&count=2000&id='+id+'&token='+token;
|
||||
url = '/irext/int/search_remote_indexes?remote_map='+remoteMap+'&from=0&count=2000&admin_id='+id+'&token='+token;
|
||||
} else {
|
||||
if(currentFilterCategory.id == 3) {
|
||||
url = '/irext/int/list_remote_indexes?category_id='+currentFilterCategory.id+'&city_code='+currentFilterCity.code+
|
||||
'&from=0&count=100&id='+id+'&token='+token;
|
||||
'&from=0&count=100&admin_id='+id+'&token='+token;
|
||||
} else {
|
||||
url = '/irext/int/list_remote_indexes?category_id='+currentFilterCategory.id+'&brand_id='+currentFilterBrand.id+
|
||||
'&from=0&count=100&id='+id+'&token='+token;
|
||||
'&from=0&count=100&admin_id='+id+'&token='+token;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -307,7 +307,7 @@ function createRemote() {
|
||||
', remoteName = ' +remoteName + ', remoteFile = ' + remoteFile + ', remoteNumber = ' + remoteNumber);
|
||||
|
||||
var form = $('#remote_upload_form');
|
||||
form.attr('action', '/irext/int/create_remote_index?id='+id+'&token='+token);
|
||||
form.attr('action', '/irext/int/create_remote_index');
|
||||
//form.attr('method', 'post');
|
||||
//form.attr('encoding', 'multipart/form-data');
|
||||
//form.attr('enctype', 'multipart/form-data');
|
||||
@@ -323,6 +323,7 @@ function createRemote() {
|
||||
$('#brand_name_tw').val(currentBrand.name_tw);
|
||||
$('#city_name_tw').val(currentCity.name_tw);
|
||||
$('#operator_name_tw').val(currentOperator.name_tw);
|
||||
$('#admin_id').val(id);
|
||||
|
||||
form.submit();
|
||||
$('#create_remote_dialog').modal('hide');
|
||||
@@ -641,6 +642,7 @@ function createProtocol() {
|
||||
//form.attr('method', 'post');
|
||||
//form.attr('encoding', 'multipart/form-data');
|
||||
//form.attr('enctype', 'multipart/form-data');
|
||||
$('#protocol_admin_id').val(id);
|
||||
|
||||
form.submit();
|
||||
$('#create_protocol_dialog').modal('hide');
|
||||
@@ -1453,7 +1455,7 @@ function downloadBin() {
|
||||
popUpHintDialog('请先选中一个索引');
|
||||
return;
|
||||
}
|
||||
downloadURL = '/irext/int/download_remote_index?remote_index_id='+selectedRemote.id+'&id='+id+'&token='+token;
|
||||
downloadURL = '/irext/int/download_remote_index?remote_index_id='+selectedRemote.id+'&admin_id='+id+'&token='+token;
|
||||
|
||||
if (null != client && client == 'console') {
|
||||
// directly download binary to remote via serial port
|
||||
@@ -1761,5 +1763,5 @@ function translateToTC(textID, targetTextID) {
|
||||
}
|
||||
|
||||
function gotoIndex() {
|
||||
window.location = '../index.html?id='+id+'&token='+token;
|
||||
window.location = '../index.html?admin_id='+id+'&token='+token;
|
||||
}
|
||||
@@ -40,23 +40,30 @@ exports.adminLoginWorkUnit = function (userName, password, callback) {
|
||||
var resp = JSON.parse(signInResponse);
|
||||
if (undefined != resp.entity) {
|
||||
var admin = resp.entity;
|
||||
var userID,
|
||||
token,
|
||||
var token,
|
||||
key,
|
||||
ttl = 24 * 60 * 60 * 14,
|
||||
timeStamp;
|
||||
timeStamp,
|
||||
name;
|
||||
timeStamp = new Date().getTime();
|
||||
token = MD5.MD5(password + timeStamp);
|
||||
token += "," + admin.permissions;
|
||||
key = "admin_" + admin.id;
|
||||
adminAuth.setAuthInfo(key, token, ttl, function(setAdminAuthErr) {
|
||||
admin.token = token;
|
||||
callback(setAdminAuthErr, admin);
|
||||
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) {
|
||||
admin.token = token;
|
||||
}
|
||||
callback(setAdminNameErr, admin);
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
callback(errorCode.FAILED, null);
|
||||
}
|
||||
|
||||
} else {
|
||||
logger.error("admin sign in failed");
|
||||
callback(errorCode.FAILED, null);
|
||||
|
||||
@@ -10,6 +10,7 @@ var crypto = require('crypto');
|
||||
// global inclusion
|
||||
require('../mini_poem/configuration/constants');
|
||||
var orm = require('orm');
|
||||
var AdminAuth = require('../authority/admin_auth.js');
|
||||
var PythonCaller = require('../mini_poem/external/python_caller');
|
||||
|
||||
var Category = require('../model/category_dao.js');
|
||||
@@ -31,6 +32,8 @@ var errorCode = new ErrorCode();
|
||||
|
||||
var async = require('async');
|
||||
|
||||
var adminAuth = new AdminAuth(REDIS_HOST, REDIS_PORT, REDIS_PASSWORD, null);
|
||||
|
||||
// relative XML file path
|
||||
var PROTOCOL_PATH = "protocol";
|
||||
|
||||
@@ -213,9 +216,10 @@ exports.createRemoteIndexWorkUnit = function(remoteIndex, filePath, contentType,
|
||||
userArgs = [];
|
||||
|
||||
// verify admin
|
||||
Admin.getAdminByID(adminID, function(getAdminErr, admin) {
|
||||
if (errorCode.SUCCESS.code == getAdminErr.code && null != admin) {
|
||||
contributor = admin.user_name;
|
||||
var key = "admin_name_" + adminID;
|
||||
adminAuth.getAuthInfo(key, function(getAdminAuthErr, result) {
|
||||
if (errorCode.SUCCESS.code == getAdminAuthErr.code && null != result) {
|
||||
contributor = result;
|
||||
|
||||
// begin creating remote index
|
||||
switch(parseInt(categoryID)) {
|
||||
@@ -536,14 +540,13 @@ exports.deleteRemoteIndexWorkUnit = function (remoteIndex, adminID, callback) {
|
||||
queryParams.put("app_key", REQUEST_APP_KEY);
|
||||
queryParams.put("app_token", REQUEST_APP_TOKEN);
|
||||
|
||||
Admin.getAdminByID(adminID, function(getAdminErr, admin) {
|
||||
if (errorCode.SUCCESS.code == getAdminErr.code && null != admin) {
|
||||
if (admin.admin_type == enums.ADMIN_TYPE_EXTERNAL) {
|
||||
if(remoteIndex.contributor.indexOf(admin.user_name) == -1) {
|
||||
logger.info("this admin " + admin.user_name + " could not change this remote index");
|
||||
callback(errorCode.FAILED);
|
||||
return;
|
||||
}
|
||||
var key = "admin_name_" + adminID;
|
||||
adminAuth.getAuthInfo(key, function(getAdminAuthErr, result) {
|
||||
if (errorCode.SUCCESS.code == getAdminAuthErr.code && null != result) {
|
||||
if(remoteIndex.contributor.indexOf(result) == -1) {
|
||||
logger.info("the admin " + result + " could not change this remote index");
|
||||
callback(errorCode.FAILED);
|
||||
return;
|
||||
}
|
||||
var requestSender =
|
||||
new RequestSender(PRIMARY_SERVER_ADDRESS,
|
||||
@@ -576,14 +579,13 @@ exports.deleteRemoteIndexWorkUnit = function (remoteIndex, adminID, callback) {
|
||||
};
|
||||
|
||||
exports.verifyRemoteIndexWorkUnit = function (remoteIndex, pass, adminID, callback) {
|
||||
Admin.getAdminByID(adminID, function(getAdminErr, admin) {
|
||||
if (errorCode.SUCCESS.code == getAdminErr.code && null != admin) {
|
||||
if (admin.admin_type == enums.ADMIN_TYPE_EXTERNAL) {
|
||||
if (remoteIndex.contributor.indexOf(admin.user_name) == -1) {
|
||||
logger.info("this admin " + admin.user_name + " could not change this remote index");
|
||||
callback(errorCode.FAILED);
|
||||
return;
|
||||
}
|
||||
var key = "admin_name_" + adminID;
|
||||
adminAuth.getAuthInfo(key, function(getAdminAuthErr, result) {
|
||||
if (errorCode.SUCCESS.code == getAdminAuthErr.code && null != result) {
|
||||
if(remoteIndex.contributor.indexOf(result) == -1) {
|
||||
logger.info("the admin " + result + " could not change this remote index");
|
||||
callback(errorCode.FAILED);
|
||||
return;
|
||||
}
|
||||
var status = 0 == pass ? enums.ITEM_PASS : enums.ITEM_FAILED;
|
||||
|
||||
@@ -597,18 +599,17 @@ exports.verifyRemoteIndexWorkUnit = function (remoteIndex, pass, adminID, callba
|
||||
};
|
||||
|
||||
exports.fallbackRemoteIndexWorkUnit = function (remoteIndex, adminID, callback) {
|
||||
Admin.getAdminByID(adminID, function(getAdminErr, admin) {
|
||||
if (errorCode.SUCCESS.code == getAdminErr.code && null != admin) {
|
||||
if (admin.admin_type == enums.ADMIN_TYPE_EXTERNAL) {
|
||||
if (remoteIndex.contributor.indexOf(admin.user_name) == -1) {
|
||||
logger.info("this admin " + admin.user_name + " could not change this remote index");
|
||||
callback(errorCode.FAILED);
|
||||
return;
|
||||
}
|
||||
var key = "admin_name_" + adminID;
|
||||
adminAuth.getAuthInfo(key, function(getAdminAuthErr, result) {
|
||||
if (errorCode.SUCCESS.code == getAdminAuthErr.code && null != result) {
|
||||
if (remoteIndex.contributor.indexOf(result) == -1) {
|
||||
logger.info("the admin " + result + " could not change this remote index");
|
||||
callback(errorCode.FAILED);
|
||||
return;
|
||||
}
|
||||
var status = enums.ITEM_VERIFY;
|
||||
|
||||
RemoteIndex.fallbackRemoteIndex(remoteIndex.id, status, function(updateRemoteIndexErr) {
|
||||
RemoteIndex.fallbackRemoteIndex(remoteIndex.id, status, function (updateRemoteIndexErr) {
|
||||
callback(updateRemoteIndexErr);
|
||||
});
|
||||
} else {
|
||||
@@ -751,15 +752,11 @@ exports.createBrandWorkUnit = function (brand, adminID, callback) {
|
||||
status: enums.ITEM_VERIFY
|
||||
};
|
||||
|
||||
Admin.getAdminByID(adminID, function(getAdminErr, admin) {
|
||||
if (errorCode.SUCCESS.code == getAdminErr.code && null != admin) {
|
||||
if (admin.admin_type == enums.ADMIN_TYPE_EXTERNAL) {
|
||||
logger.info("this admin " + admin.user_name + " could not change this remote index");
|
||||
callback(errorCode.FAILED);
|
||||
return;
|
||||
}
|
||||
|
||||
brand.contributor = admin.user_name;
|
||||
var key = "admin_name_" + adminID;
|
||||
adminAuth.getAuthInfo(key, function(getAdminAuthErr, result) {
|
||||
if (getAdminAuthErr.code == errorCode.SUCCESS.code &&
|
||||
null != result) {
|
||||
brand.contributor = result;
|
||||
Brand.findBrandByConditions(conditions, function(findBrandErr, brands) {
|
||||
if(errorCode.SUCCESS.code == findBrandErr.code && null != brands && brands.length > 0) {
|
||||
logger.info("brand already exists");
|
||||
@@ -771,7 +768,6 @@ exports.createBrandWorkUnit = function (brand, adminID, callback) {
|
||||
}
|
||||
});
|
||||
} else {
|
||||
logger.info("invalid admin ID, return directly");
|
||||
callback(errorCode.FAILED, null);
|
||||
}
|
||||
});
|
||||
@@ -837,26 +833,19 @@ exports.createProtocolWorkUnit = function(protocol, filePath, contentType, admin
|
||||
var pythonRuntimeDir = fileDir,
|
||||
pythonFile = "irda_tv_protocol.py",
|
||||
userArgs = [];
|
||||
|
||||
if (enums.PROTOCOL_TYPE_G2_QUATERNARY == protocolType) {
|
||||
pythonFile = "irda_tv_protocol.py";
|
||||
} else if (enums.PROTOCOL_TYPE_G2_HEXDECIMAL == protocolType) {
|
||||
pythonFile = "irda_tv_protocol_hex.py";
|
||||
}
|
||||
|
||||
Admin.getAdminByID(adminID, function(getAdminErr, admin) {
|
||||
if (errorCode.SUCCESS.code == getAdminErr.code && null != admin) {
|
||||
contributor = admin.user_name;
|
||||
|
||||
logger.info("get admin error code = " + JSON.stringify(getAdminErr) + ", admin = " + JSON.stringify(admin));
|
||||
|
||||
if (admin.admin_type == enums.ADMIN_TYPE_EXTERNAL) {
|
||||
logger.info("this admin " + admin.user_name + " could not create protocol");
|
||||
callback(errorCode.FAILED);
|
||||
return;
|
||||
/////////////////////////////////////
|
||||
// step 2, get admin name as contributor
|
||||
var key = "admin_name_" + adminID;
|
||||
adminAuth.getAuthInfo(key, function(getAdminAuthErr, result) {
|
||||
if (errorCode.SUCCESS.code == getAdminAuthErr.code && null != result) {
|
||||
contributor = result;
|
||||
if (enums.PROTOCOL_TYPE_G2_QUATERNARY == protocolType) {
|
||||
pythonFile = "irda_tv_protocol.py";
|
||||
} else if (enums.PROTOCOL_TYPE_G2_HEXDECIMAL == protocolType) {
|
||||
pythonFile = "irda_tv_protocol_hex.py";
|
||||
}
|
||||
//////////////////////////////////////
|
||||
// step 2, parse python run-time path, python file name and user arguments
|
||||
|
||||
logger.info("prepare to parse protocol");
|
||||
userArgs.length = 0;
|
||||
// python s_$category.py [remote_xml_file_abs_file] [remote_xml_file_name] [remote_xml_dir_abs_path]
|
||||
@@ -895,19 +884,19 @@ exports.createProtocolWorkUnit = function(protocol, filePath, contentType, admin
|
||||
logger.info("irda_tv_protocol.py called successfully, create protocol in DB");
|
||||
IRProtocol.findIRProtocolByConditions(conditions,
|
||||
function(findIRProtocolErr, IRProtocols) {
|
||||
if(errorCode.SUCCESS.code == findIRProtocolErr.code &&
|
||||
null != IRProtocols &&
|
||||
IRProtocols.length > 0) {
|
||||
logger.info("protocol " + protocolName + " already exists, " +
|
||||
"nothing to be updated");
|
||||
callback(errorCode.SUCCESS);
|
||||
} else {
|
||||
IRProtocol.createIRProtocol(newProtocol,
|
||||
function(createIRProtocolErr, createdIRProtocol) {
|
||||
callback(createIRProtocolErr);
|
||||
});
|
||||
}
|
||||
});
|
||||
if(errorCode.SUCCESS.code == findIRProtocolErr.code &&
|
||||
null != IRProtocols &&
|
||||
IRProtocols.length > 0) {
|
||||
logger.info("protocol " + protocolName + " already exists, " +
|
||||
"nothing to be updated");
|
||||
callback(errorCode.SUCCESS);
|
||||
} else {
|
||||
IRProtocol.createIRProtocol(newProtocol,
|
||||
function(createIRProtocolErr, createdIRProtocol) {
|
||||
callback(createIRProtocolErr);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
@@ -920,7 +909,6 @@ exports.createProtocolWorkUnit = function(protocol, filePath, contentType, admin
|
||||
callback(errorCode.FAILED);
|
||||
}
|
||||
} else {
|
||||
logger.error('failed to check admin type');
|
||||
callback(errorCode.FAILED);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user