Advertisement
Guest User

Untitled

a guest
Apr 29th, 2017
625
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement