158 lines
4.3 KiB
JavaScript
Raw Normal View History

2017-11-17 11:17:20 +01:00
'use strict';
/**
* An asynchronous bootstrap function that runs before
* your application gets started.
*
* This gives you an opportunity to set up your data model,
* run jobs, or perform some special logic.
*/
2017-12-04 16:43:24 +01:00
const path = require('path');
const _ = require('lodash');
const fs = require('fs');
const uuid = require('uuid/v4');
2017-11-17 11:17:20 +01:00
module.exports = cb => {
2017-12-04 16:43:24 +01:00
if (!_.get(strapi.plugins['users-permissions'], 'config.jwtSecret')) {
try {
2017-12-12 15:13:27 +01:00
const jwtSecret = uuid();
2017-12-04 16:43:24 +01:00
fs.writeFileSync(path.join(strapi.config.appPath, 'plugins', 'users-permissions', 'config', 'jwt.json'), JSON.stringify({
2017-12-12 15:13:27 +01:00
jwtSecret
2017-12-04 16:43:24 +01:00
}, null, 2), 'utf8');
2017-12-12 15:13:27 +01:00
2018-01-15 11:29:38 +01:00
_.set(strapi.plugins['users-permissions'], 'config.jwtSecret', jwtSecret);
2017-12-04 16:43:24 +01:00
} catch(err) {
strapi.log.error(err);
}
}
2018-01-12 15:20:13 +01:00
if (!_.get(strapi.plugins['users-permissions'], 'config.grant')) {
try {
2018-01-12 16:07:21 +01:00
const grant = {
2018-01-18 15:45:02 +01:00
local: {
enabled: true
},
2018-01-12 16:07:21 +01:00
facebook: {
2018-01-18 15:45:02 +01:00
enabled: false,
2018-01-12 16:07:21 +01:00
key: '',
secret: '',
callback: '/auth/facebook/callback',
scope: ['email']
},
google: {
2018-01-18 15:45:02 +01:00
enabled: false,
2018-01-12 16:07:21 +01:00
key: '',
secret: '',
callback: '/auth/google/callback',
scope: ['email']
},
github: {
2018-01-18 15:45:02 +01:00
enabled: false,
2018-01-12 16:07:21 +01:00
key: '',
secret: '',
callback: '/auth/github/callback'
},
linkedin2: {
2018-01-18 15:45:02 +01:00
enabled: false,
2018-01-12 16:07:21 +01:00
key: '',
secret: '',
callback: '/auth/linkedin2/callback',
custom_params: {
'state': ''
2018-01-12 15:20:13 +01:00
}
}
2018-01-12 16:07:21 +01:00
};
fs.writeFileSync(path.join(strapi.config.appPath, 'plugins', 'users-permissions', 'config', 'grant.json'), JSON.stringify({
grant
2018-01-12 15:20:13 +01:00
}, null, 2), 'utf8');
_.set(strapi.plugins['users-permissions'], 'config.grant', grant);
} catch(err) {
strapi.log.error(err);
}
}
2018-01-15 11:29:38 +01:00
if (!_.get(strapi.plugins['users-permissions'], 'config.email')) {
try {
const email = {
'validation_email': {
display: 'Email.template.validation_email',
icon: 'envelope',
options: {
from: {
2018-01-19 13:34:55 +01:00
name: 'Administration Panel',
email: 'no-reply@strapi.io'
2018-01-15 11:29:38 +01:00
},
2018-01-19 13:34:55 +01:00
response_email: '',
2018-01-15 11:29:38 +01:00
object: '',
message: ''
}
},
'reset_password': {
display: 'Email.template.reset_password',
icon: 'refresh',
options: {
from: {
2018-01-19 13:34:55 +01:00
name: 'Administration Panel',
email: 'no-reply@strapi.io'
2018-01-15 11:29:38 +01:00
},
2018-01-19 13:34:55 +01:00
response_email: '',
object: '­Reset password 🔑 ',
message: `<p>We heard that you lost your password. Sorry about that!</p>
<p>But dont worry! You can use the following link to reset your password:</p>
<p><%= url %>?code=<%= token %></p>
<p>Thanks.</p>`
2018-01-15 11:29:38 +01:00
}
},
'success_register': {
display: 'Email.template.success_register',
icon: 'check',
options: {
from: {
2018-01-19 13:34:55 +01:00
name: 'Administration Panel',
email: 'no-reply@strapi.io'
2018-01-15 11:29:38 +01:00
},
2018-01-19 13:34:55 +01:00
response_email: '',
2018-01-15 11:29:38 +01:00
object: '',
message: ''
}
}
};
fs.writeFileSync(path.join(strapi.config.appPath, 'plugins', 'users-permissions', 'config', 'email.json'), JSON.stringify({
email
}, null, 2), 'utf8');
_.set(strapi.plugins['users-permissions'], 'config.email', email);
} catch(err) {
strapi.log.error(err);
}
}
2018-01-15 15:01:21 +01:00
if (!_.get(strapi.plugins['users-permissions'], 'config.advanced')) {
try {
const advanced = {
unique_email: true,
allow_register: true
};
fs.writeFileSync(path.join(strapi.config.appPath, 'plugins', 'users-permissions', 'config', 'advanced.json'), JSON.stringify({
advanced
}, null, 2), 'utf8');
_.set(strapi.plugins['users-permissions'], 'config.advanced', advanced);
} catch(err) {
strapi.log.error(err);
}
}
strapi.plugins['users-permissions'].services.userspermissions.syncSchema(() => {
strapi.plugins['users-permissions'].services.userspermissions.updatePermissions(cb);
});
2017-11-17 11:17:20 +01:00
};