From 0ed47f0499087770b26dc472c5b4d6a19d541318 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ale=C5=A1=20Smodi=C5=A1?= Date: Mon, 2 Nov 2015 22:13:07 +0100 Subject: Add support for upgrade an existing account to the SAML-type account in the node web server. --- web/main.js | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'web') diff --git a/web/main.js b/web/main.js index 858408c..c0896b8 100644 --- a/web/main.js +++ b/web/main.js @@ -179,18 +179,29 @@ var guiHandlers = { }, 'saml_login': function samlLogin(session, message) { - var samlData = null; - performSamlAction('WaitLogin', {'sid': session.sid}) - .then(function (jsonObj) { - if (jsonObj.code !== 0) return jsonObj; - samlData = jsonObj.data; - if (!samlData) return {'tid': message.tid, 'sid': message.sid, 'code': -2, 'message': 'IdP proxy did not return any SAML data'}; - if (!samlData.userData) return {'tid': message.tid, 'sid': message.sid, 'code': -3, 'message': 'IdP proxy did not return any SAML user data'}; - message.saml_data = samlData.userData; // add the data from SAML authentication, and forward everything to Python - return sendDataToPython(message); - }) - .then(function (jsonObj) { - if (jsonObj.code === 0) session.samlData = samlData; // we need the SAML data to be able to perform global logout (saml_logout action) + var samlData = session.samlData, + p; + if (samlData && ('upgrade_account' in message)) { + message.saml_data = samlData.userData; + p = sendDataToPython(message); + } + else { + p = performSamlAction('WaitLogin', {'sid': session.sid}) + .then(function (jsonObj) { + if (jsonObj.code !== 0) return jsonObj; + samlData = jsonObj.data; + if (!samlData) return {'tid': message.tid, 'sid': message.sid, 'code': -2, 'message': 'IdP proxy did not return any SAML data'}; + if (!samlData.userData) return {'tid': message.tid, 'sid': message.sid, 'code': -3, 'message': 'IdP proxy did not return any SAML user data'}; + message.saml_data = samlData.userData; // add the data from SAML authentication, and forward everything to Python + return sendDataToPython(message); + }); + } + + p.then(function (jsonObj) { + if ((jsonObj.code === 0) || (jsonObj.code === 1)) { + // we need the SAML data to be able to perform global logout (saml_logout action) + session.samlData = samlData; + } session.send(jsonObj); }) .catch(function (e) { @@ -216,6 +227,8 @@ var guiHandlers = { if (key !== 'userData') sd[key] = samlData[key]; } + delete session.samlData; + performSamlAction('WaitLogout', {'sid': session.sid, 'saml': JSON.stringify(sd)}) .then(function (jsonObj) { if (jsonObj.code !== 0) return jsonObj; -- cgit v1.2.1