Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module.exports = (sails) => {
- return {
- defaults: {
- autoAdmin: {
- enabled: false,
- user: {
- username: 'admin',
- password: 'password',
- firstName: 'Gordon',
- lastName: 'Freeman',
- emailAddress: 'admin@demo.com',
- groups: ['users', 'admins']
- },
- groups: [
- {
- name: 'Users',
- accessLevel: 1
- },
- {
- name: 'Admins',
- accessLevel: 2
- }
- ]
- }
- },
- initialize: (cb) => {
- const config = sails.config.autoAdmin
- if (!config.enabled) {
- sails.log.verbose('autoAdmin hook skipped. Set sails.config.autoAdmin.enable to true to enable it in config/autoAdmin.')
- return cb()
- }
- sails.log.verbose('Loading hook: autoAdmin')
- sails.after('hook:orm:loaded', () => {
- User
- .findOrCreate({
- username: sails.config.autoAdmin.user.username
- }, sails.config.autoAdmin.user)
- .then((user) => {
- sails.log.verbose('hooks: autoAdmin initialized.')
- sails.log('--------------------------------------------------------'.grey);
- sails.log(':: AutoAdmin Information'.grey);
- sails.log('--------------------------------------------------------'.grey);
- sails.log('Username : ' + user.username); // 12 - 8 = 4 spaces
- sails.log('Password : ' + config.user.password);
- sails.log('First Name : ' + user.firstName);
- sails.log('Last Name : ' + user.lastName);
- sails.log('Email : ' + user.emailAddress);
- cb();
- })
- .catch((err) => {
- sails.log.error('hooks: autoAdmin - Error bootstrapping the default admin account');
- return cb(err);
- });
- });
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement