Created
May 12, 2017 13:49
-
-
Save matheusdavidson/79e273abbb01e84ca52ae0781bf27e23 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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": "Dragon", | |
"lastName": "Food", | |
"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