From: Laurence Maultsby Date: Fri, 14 Apr 2017 18:06:54 +0000 (-0400) Subject: login redirect to last page. if no last page redirect to launchpad if lcm role in... X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=695945f7ea689aa4b5753a87b1134b3efd7c686e;p=osm%2FUI.git login redirect to last page. if no last page redirect to launchpad if lcm role in project. otherise redirect to user profile page Signed-off-by: Laurence Maultsby --- diff --git a/skyquake/framework/core/modules/api/sessions.js b/skyquake/framework/core/modules/api/sessions.js index 9583241a4..9736f8803 100644 --- a/skyquake/framework/core/modules/api/sessions.js +++ b/skyquake/framework/core/modules/api/sessions.js @@ -46,7 +46,7 @@ function logAndRedirectToLogin(mesg, res, req) { 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); + res.redirect('login.html?api_server=' + api_server + '&upload_server=' + upload_server + '&referer=' + req.headers.referer); res.end(); } @@ -96,19 +96,26 @@ sessionsAPI.create = function(req, res) { } else { // go through projects and get list of projects that this user belongs to. // pick first one as default project? - + var isLCM = false; var projects = JSON.parse(results[1].body).collection['rw-project:project']; projects && projects.map(function(project) { project['project-config'] && project['project-config']['user'] && project['project-config']['user'].map(function(user) { if (user['user-name'] == username) { - project_list_for_user.push(project.name); + project_list_for_user.push(project); + user.role.map(function(role) { + if(role.role.indexOf('rw-project-mano:lcm') > -1) { + isLCM = true; + } + }) } }); }); - - req.session.projectId = (project_list_for_user.length > 0) && project_list_for_user.sort() && project_list_for_user[0]; + if (project_list_for_user.length > 0) { + req.session.projectId = project_list_for_user.sort() && project_list_for_user[0].name; + req.session.isLCM = isLCM; + } } req.session.authorization = authorization_header_string; @@ -175,6 +182,7 @@ sessionsAPI.delete = function(req, res) { var api_server = req.query["api_server"]; var uri = utils.confdPort(api_server); var url = uri + '/api/logout'; + req.returnTo = req.headers.referer; return new Promise(function(resolve, reject) { Promise.all([ rp({ diff --git a/skyquake/framework/core/modules/routes/navigation.js b/skyquake/framework/core/modules/routes/navigation.js index 16ff25af5..afffb20b8 100644 --- a/skyquake/framework/core/modules/routes/navigation.js +++ b/skyquake/framework/core/modules/routes/navigation.js @@ -45,11 +45,19 @@ Router.get('/login.html', cors(), function(req, res) { Router.get('/', cors(), function(req, res) { 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') - res.redirect('/launchpad/?api_server=' + api_server + '&upload_server=' + req.protocol + '://' + (configurationAPI.globalConfiguration.get().upload_server || req.hostname)); + console.log('Logged in. Redirect to launchpad'); + if(req.params.referer) { + res.redirect(req.params.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 { + res.redirect('/user_management/?api_server=' + api_server + '&upload_server=' + req.protocol + '://' + (configurationAPI.globalConfiguration.get().upload_server || req.hostname) + '#/user-profile'); + } + } } 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)); + res.redirect('login.html?api_server=' + api_server + '&upload_server=' + req.protocol + '://' + (configurationAPI.globalConfiguration.get().upload_server || req.hostname) + '&referer=' + req.headers.referer); } });