Skip to content

Instantly share code, notes, and snippets.

@campbellwmorgan
Created August 22, 2014 20:40
Show Gist options
  • Save campbellwmorgan/ee48e39dab5359a4d6c1 to your computer and use it in GitHub Desktop.
Save campbellwmorgan/ee48e39dab5359a4d6c1 to your computer and use it in GitHub Desktop.
/**
* This goes in the api/hooks folder
* and uses the so-far unstable sails events
* works in sails 0.10.x
*/
var generator = require('password-generator');
module.exports = function(sails) {
return {
configure: function() {
return sails.after('hook:orm:loaded', function() {
return User.findByName('setup_user', function(err, user) {
var password;
if (err || user.length) {
return console.log("setup_user already exists");
}
password = generator(12, false);
return User.create({
name: 'setup_user',
password: password,
isAdmin: true
}, function(err, user) {
if (err) {
console.log("Could not set password for setup user");
}
return console.log("The setup_user password is '" + password + "'");
});
});
});
}
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment