Created
August 22, 2014 20:40
-
-
Save campbellwmorgan/ee48e39dab5359a4d6c1 to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* 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