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 = {
|
|
|
|
|
facebook: {
|
|
|
|
|
key: '',
|
|
|
|
|
secret: '',
|
|
|
|
|
callback: '/auth/facebook/callback',
|
|
|
|
|
scope: ['email']
|
|
|
|
|
},
|
|
|
|
|
google: {
|
|
|
|
|
key: '',
|
|
|
|
|
secret: '',
|
|
|
|
|
callback: '/auth/google/callback',
|
|
|
|
|
scope: ['email']
|
|
|
|
|
},
|
|
|
|
|
github: {
|
|
|
|
|
key: '',
|
|
|
|
|
secret: '',
|
|
|
|
|
callback: '/auth/github/callback'
|
|
|
|
|
},
|
|
|
|
|
linkedin2: {
|
|
|
|
|
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: {
|
|
|
|
|
email: '',
|
|
|
|
|
name: ''
|
|
|
|
|
},
|
|
|
|
|
respond: '',
|
|
|
|
|
object: '',
|
|
|
|
|
message: ''
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
'reset_password': {
|
|
|
|
|
display: 'Email.template.reset_password',
|
|
|
|
|
icon: 'refresh',
|
|
|
|
|
options: {
|
|
|
|
|
from: {
|
|
|
|
|
email: '',
|
|
|
|
|
name: ''
|
|
|
|
|
},
|
|
|
|
|
respond: '',
|
2018-01-15 14:50:53 +01:00
|
|
|
|
object: 'Reset password 🔑 ',
|
|
|
|
|
message: `<p>We heard that you lost your password. Sorry about that!</p>
|
|
|
|
|
|
|
|
|
|
<p>But don’t 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: {
|
|
|
|
|
email: '',
|
|
|
|
|
name: ''
|
|
|
|
|
},
|
|
|
|
|
respond: '',
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-04 16:36:56 +01:00
|
|
|
|
strapi.plugins['users-permissions'].services.userspermissions.syncSchema(() => {
|
|
|
|
|
strapi.plugins['users-permissions'].services.userspermissions.updatePermissions(cb);
|
|
|
|
|
});
|
2017-11-17 11:17:20 +01:00
|
|
|
|
};
|