From: Laurence Maultsby Date: Thu, 9 Mar 2017 20:57:49 +0000 (-0500) Subject: User Management: Change password initial support for user admin X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=c637db2bc817cb1cd1a4a20655bf7e01b1c490bd;p=osm%2FUI.git User Management: Change password initial support for user admin Signed-off-by: Laurence Maultsby --- 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; diff --git a/skyquake/framework/core/modules/routes/userManagement.js b/skyquake/framework/core/modules/routes/userManagement.js index 359d9855c..055222909 100644 --- a/skyquake/framework/core/modules/routes/userManagement.js +++ b/skyquake/framework/core/modules/routes/userManagement.js @@ -50,6 +50,13 @@ Router.post('/user', cors(), function(req, res) { utils.sendErrorResponse(error, res); }); }); +Router.put('/user', cors(), function(req, res) { + UserManagementAPI.update(req).then(function(response) { + utils.sendSuccessResponse(response, res); + }, function(error) { + utils.sendErrorResponse(error, res); + }); +}); Router.delete('/user/:username/:domain', cors(), function(req, res) { UserManagementAPI.delete(req).then(function(response) { utils.sendSuccessResponse(response, res); diff --git a/skyquake/plugins/user-management/src/dashboard/dashboard.jsx b/skyquake/plugins/user-management/src/dashboard/dashboard.jsx index df28d2178..c997e15bc 100644 --- a/skyquake/plugins/user-management/src/dashboard/dashboard.jsx +++ b/skyquake/plugins/user-management/src/dashboard/dashboard.jsx @@ -81,12 +81,12 @@ class UserManagementDashboard extends React.Component { closePanel = () => { this.actions.handleCloseUserPanel(); } - updateUser = (e) => { - e.preventDefault(); - e.stopPropagation(); + // updateUser = (e) => { + // e.preventDefault(); + // e.stopPropagation(); - this.Store.updateUser(); - } + // this.Store.updateUser(); + // } deleteUser = (e) => { e.preventDefault(); e.stopPropagation(); @@ -108,6 +108,41 @@ class UserManagementDashboard extends React.Component { // 'confirm-password': this.state['confirm-password'] }); } + } + updateUser = (e) => { + let self = this; + e.preventDefault(); + e.stopPropagation(); + let validatedPasswords = validatePasswordFields(this.state); + if(validatedPasswords) { + this.Store.updateUser(_.merge({ + 'user-name': this.state['user-name'], + 'user-domain': this.state['user-domain'], + 'password': this.state['new-password'] + })); + } + function validatePasswordFields(state) { + let oldOne = state['old-password']; + let newOne = state['new-password']; + let confirmOne = state['confirm-password']; + if(true) { + if(oldOne == newOne) { + self.props.actions.showNotification('Your new password must not match your old one'); + return false; + } + if(newOne != confirmOne) { + self.props.actions.showNotification('Passwords do not match'); + return false; + } + return { + // 'old-password': oldOne, + 'new-password': newOne, + 'confirm-password': confirmOne + } + } else { + return {}; + } + } } evaluateSubmit = (e) => { if (e.keyCode == 13) { @@ -149,7 +184,6 @@ class UserManagementDashboard extends React.Component { passwordSectionHTML = ( this.state.isEdit ? ( - diff --git a/skyquake/plugins/user-management/src/dashboard/userMgmtSource.js b/skyquake/plugins/user-management/src/dashboard/userMgmtSource.js index 18cb83d48..2f922a995 100644 --- a/skyquake/plugins/user-management/src/dashboard/userMgmtSource.js +++ b/skyquake/plugins/user-management/src/dashboard/userMgmtSource.js @@ -47,9 +47,18 @@ module.exports = function(Alt) { updateUser: { remote: function(state, user) { return new Promise(function(resolve, reject) { - setTimeout(function() { - resolve(true); - }, 1000) + $.ajax({ + url: `/user?api_server=${API_SERVER}`, + type: 'PUT', + data: user, + beforeSend: Utils.addAuthorizationStub, + success: function(data, textStatus, jqXHR) { + resolve(data); + } + }).fail(function(xhr){ + //Authentication and the handling of fail states should be wrapped up into a connection class. + Utils.checkAuthentication(xhr.status); + }); }); }, interceptResponse: interceptResponse({ diff --git a/skyquake/plugins/user-management/src/dashboard/userMgmtStore.js b/skyquake/plugins/user-management/src/dashboard/userMgmtStore.js index 58839957f..19952fba6 100644 --- a/skyquake/plugins/user-management/src/dashboard/userMgmtStore.js +++ b/skyquake/plugins/user-management/src/dashboard/userMgmtStore.js @@ -187,7 +187,11 @@ export default class UserManagementStore { disabled: this.disabled, projectRoles: this.projectRoles } - this.setState({users}) + this.setState({ + users, + isEdit: true, + isReadOnly: true + }) } deleteUserSuccess() { this.alt.actions.global.hideScreenLoader.defer();