From c28a1b68744a1f330d94449c52392089d1c40af3 Mon Sep 17 00:00:00 2001 From: Gianfranco Manganiello Date: Wed, 17 Jan 2018 16:51:46 -0400 Subject: [PATCH] feat(GlpiRestClient): register user --- src/restclient.js | 59 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/src/restclient.js b/src/restclient.js index b0428e5..fa1f969 100644 --- a/src/restclient.js +++ b/src/restclient.js @@ -253,6 +253,65 @@ class GlpiRestClient { }) } + registerUser (userToken, userData) { + return new Promise((resolve, reject) => { + try { + if (Array.isArray(userData)) { + userData.forEach(element => { + if (!element.name) { + reject('missing name in a user') + } + if (!element.realname) { + reject('missing realname in a user') + } + if (!element.password) { + reject('missing password in a user') + } + if (!element.password2) { + reject('missing password2 in a user') + } + }) + } else { + + if (!userData.name) { + reject('missing name') + } + if (!userData.realname) { + reject('missing realname') + } + if (!userData.password) { + reject('missing password') + } + if (!userData.password2) { + reject('missing password2') + } + } + this.initSessionByUserToken(userToken) + .then(res1 => { + this.addItem(ITEMTYPE.User, userData) + .then(res2 => { + this.killSession() + .then(res3 => { + resolve ( res2 ) + }) + .catch(err3 => { + reject(err3) + }) + }) + .catch (err2 => { + reject(err2) + }) + }) + .catch(err1 => { + reject(err1) + }) + } + catch (err) { + reject(err) + } + }) + } + } export default GlpiRestClient