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');
|
|
|
|
|
|
2018-02-01 18:12:38 +01:00
|
|
|
|
module.exports = async 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();
|
2018-01-17 18:50:12 +01:00
|
|
|
|
|
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-02-06 13:10:43 +01:00
|
|
|
|
const pluginStore = strapi.store({
|
2018-02-13 15:04:21 +01:00
|
|
|
|
environment: '',
|
2018-02-06 13:10:43 +01:00
|
|
|
|
type: 'plugin',
|
|
|
|
|
name: 'users-permissions'
|
|
|
|
|
});
|
|
|
|
|
|
2018-04-21 12:29:00 +08:00
|
|
|
|
const grantValue = {
|
|
|
|
|
email: {
|
|
|
|
|
enabled: true,
|
|
|
|
|
icon: 'envelope'
|
|
|
|
|
},
|
|
|
|
|
facebook: {
|
|
|
|
|
enabled: false,
|
|
|
|
|
icon: 'facebook-official',
|
|
|
|
|
key: '',
|
|
|
|
|
secret: '',
|
|
|
|
|
callback: '/auth/facebook/callback',
|
|
|
|
|
scope: ['email']
|
|
|
|
|
},
|
|
|
|
|
google: {
|
|
|
|
|
enabled: false,
|
|
|
|
|
icon: 'google',
|
|
|
|
|
key: '',
|
|
|
|
|
secret: '',
|
|
|
|
|
callback: '/auth/google/callback',
|
|
|
|
|
scope: ['email']
|
|
|
|
|
},
|
|
|
|
|
github: {
|
|
|
|
|
enabled: false,
|
|
|
|
|
icon: 'github',
|
|
|
|
|
key: '',
|
|
|
|
|
secret: '',
|
|
|
|
|
redirect_uri: '/auth/github/callback',
|
|
|
|
|
scope: [
|
|
|
|
|
'user',
|
|
|
|
|
'user:email'
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
twitter: {
|
|
|
|
|
enabled: false,
|
|
|
|
|
icon: 'twitter',
|
|
|
|
|
key: '',
|
|
|
|
|
secret: '',
|
|
|
|
|
callback: '/auth/twitter/callback'
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
const prevGrantValue = await pluginStore.get({key: 'grant'})
|
|
|
|
|
// store grant auth config to db
|
|
|
|
|
// when plugin_users-permissions_grant is not existed in db
|
|
|
|
|
// or we have added/deleted provider here.
|
|
|
|
|
if (!prevGrantValue || !_.isEqual(_.keys(prevGrantValue), _.keys(grantValue))) {
|
|
|
|
|
await pluginStore.set({key: 'grant', value: grantValue});
|
2018-01-12 15:20:13 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-06 13:10:43 +01:00
|
|
|
|
if (!await pluginStore.get({key: 'email'})) {
|
|
|
|
|
const value = {
|
2018-02-01 18:12:38 +01:00
|
|
|
|
'reset_password': {
|
|
|
|
|
display: 'Email.template.reset_password',
|
|
|
|
|
icon: 'refresh',
|
|
|
|
|
options: {
|
|
|
|
|
from: {
|
|
|
|
|
name: 'Administration Panel',
|
|
|
|
|
email: 'no-reply@strapi.io'
|
|
|
|
|
},
|
|
|
|
|
response_email: '',
|
2018-04-16 09:48:43 +02:00
|
|
|
|
object: 'Reset password',
|
2018-02-01 18:12:38 +01:00
|
|
|
|
message: `<p>We heard that you lost your password. Sorry about that!</p>
|
2018-01-15 14:50:53 +01:00
|
|
|
|
|
2018-01-26 17:31:52 +01:00
|
|
|
|
<p>But don’t worry! You can use the following link to reset your password:</p>
|
2018-01-15 14:50:53 +01:00
|
|
|
|
|
2018-01-26 17:37:01 +01:00
|
|
|
|
<p><%= URL %>?code=<%= TOKEN %></p>
|
2018-01-15 14:50:53 +01:00
|
|
|
|
|
2018-01-26 17:31:52 +01:00
|
|
|
|
<p>Thanks.</p>`
|
2018-01-15 11:29:38 +01:00
|
|
|
|
}
|
2018-02-01 18:12:38 +01:00
|
|
|
|
}
|
|
|
|
|
};
|
2018-01-15 11:29:38 +01:00
|
|
|
|
|
2018-02-06 13:10:43 +01:00
|
|
|
|
await pluginStore.set({key: 'email', value});
|
2018-01-15 11:29:38 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-06 13:10:43 +01:00
|
|
|
|
if (!await pluginStore.get({key: 'advanced'})) {
|
|
|
|
|
const value = {
|
2018-02-01 18:12:38 +01:00
|
|
|
|
unique_email: true,
|
2018-03-12 15:56:25 +01:00
|
|
|
|
allow_register: true,
|
2018-03-14 16:56:12 +01:00
|
|
|
|
default_role: 'authenticated'
|
2018-02-01 18:12:38 +01:00
|
|
|
|
};
|
2018-01-15 15:01:21 +01:00
|
|
|
|
|
2018-02-06 13:10:43 +01:00
|
|
|
|
await pluginStore.set({key: 'advanced', value});
|
2018-01-15 15:01:21 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-04 16:36:56 +01:00
|
|
|
|
strapi.plugins['users-permissions'].services.userspermissions.syncSchema(() => {
|
2018-01-17 18:50:12 +01:00
|
|
|
|
strapi.plugins['users-permissions'].services.userspermissions.initialize(cb);
|
2018-01-04 16:36:56 +01:00
|
|
|
|
});
|
2017-11-17 11:17:20 +01:00
|
|
|
|
};
|