SHARE
TWEET

Untitled

a guest Apr 29th, 2017 583 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module.exports = (sails) => {
  2.   return {
  3.     defaults: {
  4.       autoAdmin: {
  5.         enabled: false,
  6.         user: {
  7.           username: 'admin',
  8.           password: 'password',
  9.           firstName: 'Gordon',
  10.           lastName: 'Freeman',
  11.           emailAddress: 'admin@demo.com',
  12.           groups: ['users', 'admins']
  13.         },
  14.         groups: [
  15.           {
  16.             name: 'Users',
  17.             accessLevel: 1
  18.           },
  19.           {
  20.             name: 'Admins',
  21.             accessLevel: 2
  22.           }
  23.         ]
  24.       }
  25.     },
  26.     initialize: (cb) => {
  27.       const config = sails.config.autoAdmin
  28.       if (!config.enabled) {
  29.         sails.log.verbose('autoAdmin hook skipped. Set sails.config.autoAdmin.enable to true to enable it in config/autoAdmin.')
  30.         return cb()
  31.       }
  32.  
  33.       sails.log.verbose('Loading hook: autoAdmin')
  34.       sails.after('hook:orm:loaded', () => {
  35.         User
  36.           .findOrCreate({
  37.             username: sails.config.autoAdmin.user.username
  38.           }, sails.config.autoAdmin.user)
  39.           .then((user) => {
  40.             sails.log.verbose('hooks: autoAdmin initialized.')
  41.             sails.log('--------------------------------------------------------'.grey);
  42.             sails.log(':: AutoAdmin Information'.grey);
  43.             sails.log('--------------------------------------------------------'.grey);
  44.             sails.log('Username    : ' + user.username); // 12 - 8 = 4 spaces
  45.             sails.log('Password    : ' + config.user.password);
  46.             sails.log('First Name  : ' + user.firstName);
  47.             sails.log('Last Name   : ' + user.lastName);
  48.             sails.log('Email       : ' + user.emailAddress);
  49.             cb();
  50.           })
  51.           .catch((err) => {
  52.             sails.log.error('hooks: autoAdmin - Error bootstrapping the default admin account');
  53.             return cb(err);
  54.           });
  55.  
  56.       });
  57.     }
  58.   }
  59. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top