module.exports.registerUser = function (enrollment_ID, callback) {
console.log(TAG, 'registerUser() called');
if (!chain) {
cb(new Error('Cannot register a user before setup() is called.'));
return;
}
chain.getMember(enrollment_ID, function (err, usr) {
if (!usr.isRegistered()) {
console.log(TAG, 'Sending registration request for:', enrollment_ID);
var registrationRequest = {
enrollmentID: enrollment_ID,
affiliation: 'group1'
};
usr.register(registrationRequest, function (err, enrollSecret) {
if (err) {
callback(err);
} else {
var credential = {
id: enrollID,
secret: enrollSecret
};
console.log(TAG, 'Registration request completed >successfully!');
callback(null, credential);
}
});
} else {
callback(new Error('Cannot register an existing user'));
}
});
};