-
-
Save kristofsajdak/62d7abbebe97794f6c4f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'), | |
reqpromise = require('request-promise'); | |
function register(req, res, next) { | |
var user = {}; | |
user.username = req.body.username; | |
user.password = req.body.password; | |
user.firstName = req.body.firstName; | |
user.lastName = req.body.lastName; | |
user.email = req.body.username; | |
getAdminToken(next) | |
.then(registerWithTaas) | |
.then(registerWithCustomerPortal) | |
.then(sendResponse) | |
.catch(next); | |
function registerWithTaas(adminToken) { | |
var url = config.taasUrl + config.register, | |
options = { | |
json: { | |
'username': user.username, | |
'password': user.password, | |
'groups': [], | |
'active': true, | |
'adminToken': adminToken | |
} | |
}; | |
return reqpromise.post(url, options).then(function (registeredUser) { | |
user.uuid = registeredUser.uuid; | |
}); | |
} | |
function registerWithCustomerPortal() { | |
var url = config.customerDomain + config.customerRegister, | |
options = { | |
json: { | |
'uuid': user.uuid, | |
'username': user.username, | |
'email': user.email, | |
'firstName': user.firstName, | |
'lastName': user.lastName | |
} | |
}; | |
return reqpromise.post(url, options).then(function (registeredUser) { | |
return registeredUser; | |
}); | |
} | |
function sendResponse(data) { | |
res.status(200).send(data); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yup, tested and that works. My previous attempts were obviously filled with weak code SNAFUs.
Thanks for the push to tidy it up!