Pierre Noël 57d7d876b7
Fix/#4513/ability to use a sub path behind a proxy (#5833)
* add possibility to use strapi on a non-root base url path

* fix documentation password form

* use server.url and admin.url in config

Signed-off-by: Pierre Noël <pierre.noel@strapi.io>

* update doc proxy

Signed-off-by: Pierre Noël <pierre.noel@strapi.io>

* move server.url location in config

Signed-off-by: Pierre Noël <pierre.noel@strapi.io>

* refacto

Signed-off-by: Pierre Noël <pierre.noel@strapi.io>

* add possibility to put relative urls

Signed-off-by: Pierre Noël <pierre.noel@strapi.io>

* allow '/' as an admin url + refacto

Signed-off-by: Pierre Noël <pierre.noel@strapi.io>

* update yarn.lock

Signed-off-by: Pierre Noël <petersg83@gmail.com>

* refacto

Signed-off-by: Pierre Noël <petersg83@gmail.com>

* Remove default proxy option

Signed-off-by: Alexandre Bodin <bodin.alex@gmail.com>

* fix github provider

Signed-off-by: Pierre Noël <petersg83@gmail.com>

* fix github login

Signed-off-by: Pierre Noël <petersg83@gmail.com>

* Remove files that should be here

Signed-off-by: Alexandre Bodin <bodin.alex@gmail.com>

Co-authored-by: Pierre Noël <pierre.noel@strapi.io>
Co-authored-by: Alexandre Bodin <bodin.alex@gmail.com>
2020-05-08 13:50:00 +02:00

177 lines
4.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'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.
*/
const _ = require('lodash');
const uuid = require('uuid/v4');
module.exports = async () => {
const pluginStore = strapi.store({
environment: '',
type: 'plugin',
name: 'users-permissions',
});
const grantConfig = {
email: {
enabled: true,
icon: 'envelope',
},
discord: {
enabled: false,
icon: 'discord',
key: '',
secret: '',
callback: `${strapi.config.server.url}/auth/discord/callback`,
scope: ['identify', 'email'],
},
facebook: {
enabled: false,
icon: 'facebook-square',
key: '',
secret: '',
callback: `${strapi.config.server.url}/auth/facebook/callback`,
scope: ['email'],
},
google: {
enabled: false,
icon: 'google',
key: '',
secret: '',
callback: `${strapi.config.server.url}/auth/google/callback`,
scope: ['email'],
},
github: {
enabled: false,
icon: 'github',
key: '',
secret: '',
callback: `${strapi.config.server.url}/auth/github/callback`,
scope: ['user', 'user:email'],
},
microsoft: {
enabled: false,
icon: 'windows',
key: '',
secret: '',
callback: `${strapi.config.server.url}/auth/microsoft/callback`,
scope: ['user.read'],
},
twitter: {
enabled: false,
icon: 'twitter',
key: '',
secret: '',
callback: `${strapi.config.server.url}/auth/twitter/callback`,
},
instagram: {
enabled: false,
icon: 'instagram',
key: '',
secret: '',
callback: `${strapi.config.server.url}/auth/instagram/callback`,
},
vk: {
enabled: false,
icon: 'vk',
key: '',
secret: '',
callback: `${strapi.config.server.url}/auth/vk/callback`,
scope: ['email'],
},
};
const prevGrantConfig = (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 (!prevGrantConfig || !_.isEqual(_.keys(prevGrantConfig), _.keys(grantConfig))) {
// merge with the previous provider config.
_.keys(grantConfig).forEach(key => {
if (key in prevGrantConfig) {
grantConfig[key] = _.merge(grantConfig[key], prevGrantConfig[key]);
}
});
await pluginStore.set({ key: 'grant', value: grantConfig });
}
if (!(await pluginStore.get({ key: 'email' }))) {
const value = {
reset_password: {
display: 'Email.template.reset_password',
icon: 'sync',
options: {
from: {
name: 'Administration Panel',
email: 'no-reply@strapi.io',
},
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>`,
},
},
email_confirmation: {
display: 'Email.template.email_confirmation',
icon: 'check-square',
options: {
from: {
name: 'Administration Panel',
email: 'no-reply@strapi.io',
},
response_email: '',
object: 'Account confirmation',
message: `<p>Thank you for registering!</p>
<p>You have to confirm your email address. Please click on the link below.</p>
<p><%= URL %>?confirmation=<%= CODE %></p>
<p>Thanks.</p>`,
},
},
};
await pluginStore.set({ key: 'email', value });
}
if (!(await pluginStore.get({ key: 'advanced' }))) {
const value = {
unique_email: true,
allow_register: true,
email_confirmation: false,
email_confirmation_redirection: `${strapi.config.admin.url}/admin`,
email_reset_password: `${strapi.config.admin.url}/admin`,
default_role: 'authenticated',
};
await pluginStore.set({ key: 'advanced', value });
}
await strapi.plugins['users-permissions'].services.userspermissions.initialize();
if (!_.get(strapi.plugins['users-permissions'], 'config.jwtSecret')) {
const jwtSecret = uuid();
_.set(strapi.plugins['users-permissions'], 'config.jwtSecret', jwtSecret);
strapi.reload.isWatching = false;
await strapi.fs.writePluginFile(
'users-permissions',
'config/jwt.js',
`module.exports = {\n jwtSecret: process.env.JWT_SECRET || '${jwtSecret}'\n};`
);
strapi.reload.isWatching = true;
}
};