X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=skyquake%2Fframework%2Fcore%2Fmodules%2Fapi%2FuserManagementAPI.js;h=3972122329301b7de08667f4f8b6cffb2f8b1d40;hb=0639632bc78cfc65b26624c20e6ce4cb81d8be8f;hp=cf33313ef7f8f1e7a8303c60a10c4f1d938e8308;hpb=ba19ffdfd442c7ebe66f482b90f6bc65a0e9b8be;p=osm%2FUI.git diff --git a/skyquake/framework/core/modules/api/userManagementAPI.js b/skyquake/framework/core/modules/api/userManagementAPI.js index cf33313ef..397212232 100644 --- a/skyquake/framework/core/modules/api/userManagementAPI.js +++ b/skyquake/framework/core/modules/api/userManagementAPI.js @@ -102,6 +102,71 @@ UserManagement.create = function(req) { }); }); }; +UserManagement.update = function(req) { + var self = this; + var api_server = req.query['api_server']; + var bodyData = req.body; + data = { + "users":[bodyData] + } + var updateTasks = []; + if(bodyData.hasOwnProperty('old-password')) { + var changePW = rp({ + uri: utils.confdPort(api_server) + '/api/operations/change-password', + method: 'POST', + headers: _.extend({}, constants.HTTP_HEADERS.accept.data, { + 'Authorization': req.get('Authorization') + }), + forever: constants.FOREVER_ON, + json: { + "input": { + 'user-name' : bodyData['user-name'], + 'user-domain' : bodyData['user-domain'], + 'old-password' : bodyData['old-password'], + 'new-password' : bodyData['new-password'], + 'confirm-password' : bodyData['confirm-password'], + } + }, + rejectUnauthorized: false, + resolveWithFullResponse: true + }); + updateTasks.push(changePW); + }; + var updateUser = rp({ + uri: utils.confdPort(api_server) + '/api/config/user-config', + method: 'PUT', + headers: _.extend({}, constants.HTTP_HEADERS.accept.data, { + 'Authorization': req.get('Authorization') + }), + forever: constants.FOREVER_ON, + json: data, + rejectUnauthorized: false, + resolveWithFullResponse: true + }); + updateTasks.push(updateUser) + return new Promise(function(resolve, reject) { + Promise.all([ + updateTasks + ]).then(function(result) { + var response = {}; + response['data'] = {}; + if (result[0].body) { + response['data'] = result[0].body; + } + response.statusCode = constants.HTTP_RESPONSE_CODES.SUCCESS.OK + + resolve(response); + }).catch(function(error) { + var response = {}; + console.log('Problem with UserManagement.passwordChange', error); + response.statusCode = error.statusCode || 500; + response.errorMessage = { + error: 'Failed to passwordChange user' + error + }; + reject(response); + }); + }); +}; UserManagement.delete = function(req) { var self = this;