Skip to content

Commit

Permalink
feat(GlpiRestClient): register user
Browse files Browse the repository at this point in the history
  • Loading branch information
Gianfranco97 committed Jan 17, 2018
1 parent 05c6a88 commit c28a1b6
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions src/restclient.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c28a1b6

Please sign in to comment.