});
});
};
+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;
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);
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();
// '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) {
passwordSectionHTML = ( this.state.isEdit ?
(
<FormSection title="PASSWORD CHANGE">
- <Input label="OLD PASSWORD" type="password" value={state['old-password']} onChange={this.updateInput.bind(null, 'old-password')} />
<Input label="NEW PASSWORD" type="password" value={state['new-password']} onChange={this.updateInput.bind(null, 'new-password')}/>
<Input label="REPEAT NEW PASSWORD" type="password" value={state['confirm-password']} onChange={this.updateInput.bind(null, 'confirm-password')}/>
</FormSection>
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({
disabled: this.disabled,
projectRoles: this.projectRoles
}
- this.setState({users})
+ this.setState({
+ users,
+ isEdit: true,
+ isReadOnly: true
+ })
}
deleteUserSuccess() {
this.alt.actions.global.hideScreenLoader.defer();