Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kristofsajdak/62d7abbebe97794f6c4f to your computer and use it in GitHub Desktop.
Save kristofsajdak/62d7abbebe97794f6c4f to your computer and use it in GitHub Desktop.
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);
}
}
@raymcdermott
Copy link

Yup, tested and that works. My previous attempts were obviously filled with weak code SNAFUs.

Thanks for the push to tidy it up!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment