Skip to content

Instantly share code, notes, and snippets.

@rjp44
Last active April 7, 2016 15:51
Show Gist options
  • Save rjp44/13da9e76f0830a0f1b22472d794ad4c9 to your computer and use it in GitHub Desktop.
Save rjp44/13da9e76f0830a0f1b22472d794ad4c9 to your computer and use it in GitHub Desktop.
/**
* Create an ipcortex user, using the create REST call
* @param {string} username - Login username "fred"
* @param {string} name - Full name "Fred Smith"
* @param {string} password - New poassword, should be non empty complex string
* @param {string} host - host to make REST request on
* @param {string} apikey - API key with user create permissions
* @returns {Promise} - resolves or rejects when request completes
*/
function IPCAddUser(username, name, password, host, apikey) {
return new Promise(function(resolve, reject) {
$.ajax({
type: 'POST',
url: 'https://'+host+'/rest/ops/create',
data: JSON.stringify({
auth: {
type: "auth",
key: apikey
},
type: "user",
values: {
uname: username,
name: name,
password: password
}
}),
success: function(data) {
console.log('Data', data);
if (data.result === 'success')
resolve(data);
else {
reject(data);
}
},
contentType: "application/json",
dataType: 'json'
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment