* @param {Function} res - a handle to the express response function
*/
var sendErrorResponse = function(error, res) {
+ if (!error.statusCode) {
+ console.error('Status Code has not been set in error object: ', error);
+ }
res.status(error.statusCode);
res.send(error);
}
var api_server = req.query['api_server'] || (req.protocol + '://' + configurationAPI.globalConfiguration.get().api_server);
var upload_server = req.protocol + '://' + (configurationAPI.globalConfiguration.get().upload_server || req.hostname);
console.log(mesg);
- res.redirect('login.html?api_server=' + api_server + '&upload_server=' + upload_server + '&referer=' + req.headers.referer);
+ res.redirect('login.html?api_server=' + api_server + '&upload_server=' + upload_server + '&referer=' + encodeURIComponent(req.headers.referer));
res.end();
}
username: username,
// project: req.session.projectId
};
+ req.session.redirect = true;
var successMsg = 'User => ' + username + ' successfully logged in.';
successMsg += req.session.projectId ? 'Project => ' + req.session.projectId + ' set as default.' : '';
var api_server = req.query['api_server'];
return new Promise(function(resolve, reject) {
var response = {};
- var userId = req.session.userdata.username
- response['data'] = {
- userId: userId,
- projectId: req.session.projectId
- };
- UserManagement.getUserInfo(req, userId).then(function(result) {
- response.statusCode = constants.HTTP_RESPONSE_CODES.SUCCESS.OK;
- response.data.data =result.data
- resolve(response);
- }, function(error) {
- console.log('Error retrieving getUserInfo');
+ try {
+ var userId = req.session.userdata.username
+ response['data'] = {
+ userId: userId,
+ projectId: req.session.projectId
+ };
+ UserManagement.getUserInfo(req, userId).then(function(result) {
+ response.statusCode = constants.HTTP_RESPONSE_CODES.SUCCESS.OK;
+ response.data.data = result.data
+ resolve(response);
+ }, function(error) {
+ console.log('Error retrieving getUserInfo');
+ response.statusCode = constants.HTTP_RESPONSE_CODES.ERROR.INTERNAL_SERVER_ERROR;
+ reject(response);
+ })
+ } catch (e) {
+ response.data.data = e;
response.statusCode = constants.HTTP_RESPONSE_CODES.ERROR.INTERNAL_SERVER_ERROR;
reject(response);
- })
-
+ reject()
+ }
});
};
UserManagement.getUserInfo = function(req, userId, domain) {
res.end();
});
-Router.get('/', cors(), function(req, res) {
+Router.use(/^\/(?!session).*/, function(req, res, next) {
var api_server = req.query['api_server'] || (req.protocol + '://' + configurationAPI.globalConfiguration.get().api_server);
if (req.session && req.session.loggedIn) {
- console.log('Logged in. Redirect to launchpad');
- if(req.params.referer) {
- res.redirect(req.params.referer);
+ next();
+ } else {
+ console.log('Redirect to login.html');
+ res.redirect('/login.html?api_server=' + api_server + '&upload_server=' + req.protocol + '://' + (configurationAPI.globalConfiguration.get().upload_server || req.hostname) + '&referer=' + encodeURIComponent(req.headers.referer));
+ }
+});
+
+Router.use(function(req, res, next) {
+ var api_server = req.query['api_server'] || (req.protocol + '://' + configurationAPI.globalConfiguration.get().api_server);
+ if (req.session.redirect) {
+ req.session.redirect = false;
+ req.session.save(function(err) {
+ if (err) {
+ console.log('Error saving session to store', err);
+ }
+ });
+ if(req.query.referer && (req.query.referer != "undefined")) {
+ res.redirect(decodeURIComponent(req.query.referer));
} else {
if(req.session.isLCM) {
res.redirect('/launchpad/?api_server=' + api_server + '&upload_server=' + req.protocol + '://' + (configurationAPI.globalConfiguration.get().upload_server || req.hostname));
}
}
} else {
- console.log('Redirect to login.html');
- res.redirect('login.html?api_server=' + api_server + '&upload_server=' + req.protocol + '://' + (configurationAPI.globalConfiguration.get().upload_server || req.hostname) + '&referer=' + req.headers.referer);
+ next();
}
});
var username;
var pass;
var api_server = getSearchParams(window.location).api_server;
+ var referer = getSearchParams(window.location).referer;
$('#submit').click(function() {
username=$('#username').val();
pass=$('#password').val();
password: pass
},
success: function(data) {
- window.location.href='/?api_server=' + api_server;
+ window.location.href='/?api_server=' + api_server + '&referer=' + referer;
}
});
});