Skip to content

Instantly share code, notes, and snippets.

@matheusdavidson
Created May 12, 2017 13:48
Show Gist options
  • Save matheusdavidson/724a032d2a401a54316246b0dc94216a to your computer and use it in GitHub Desktop.
Save matheusdavidson/724a032d2a401a54316246b0dc94216a to your computer and use it in GitHub Desktop.
exports.createSuperAdmin = createSuperAdmin;
/**
* Create superadmin
*/
function createSuperAdmin(req, res) {
//
// Check if master user exists
Model.find({
email: '[email protected]'
}).exec(function (err, data) {
//
// Error
if (err) return handleError.index(res, err);
//
// Validate
if (data && data.length) return res.status(200).json({
exists: true
});
//
// Register super admin user
var model = {
"provider": "local",
"email": "[email protected]",
"password": "123456",
"profile": {
"firstName": "To",
"lastName": "Chegando",
"contact": {
"phone": "99999999999",
"mobile": "99999999999"
}
},
"role": "superadmin"
};
//
// Set account
req.account = model;
//
// Set model
User.model = model;
//
// Set res
User.res = res;
//
// Create record
User.create(req, function (err, data) {
//
// Error
if (err) return handleError.index(res, err);
//
// Add user to req
req.user = data.user;
//
// Set account in accounts
authService.setAccountInAccounts(req);
//
// Return
return res.status(200).json(data);
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment