2020-10-27 11:27:17 +01:00
|
|
|
'use strict';
|
|
|
|
|
2018-12-06 18:03:56 +01:00
|
|
|
module.exports = async (ctx, next) => {
|
2021-09-13 12:03:12 +02:00
|
|
|
const pluginStore = strapi.store({ type: 'plugin', name: 'documentation' });
|
|
|
|
|
2018-12-06 18:03:56 +01:00
|
|
|
const config = await pluginStore.get({ key: 'config' });
|
|
|
|
|
|
|
|
if (!config.restrictedAccess) {
|
2021-09-13 12:03:12 +02:00
|
|
|
return next();
|
2018-12-06 18:03:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!ctx.session.documentation) {
|
|
|
|
const querystring = ctx.querystring ? `?${ctx.querystring}` : '';
|
|
|
|
|
2020-05-08 13:50:00 +02:00
|
|
|
return ctx.redirect(
|
2021-07-20 12:12:30 +02:00
|
|
|
`${strapi.config.server.url}${
|
2021-08-06 18:09:49 +02:00
|
|
|
strapi.config.get('plugin.documentation.x-strapi-config').path
|
2021-07-20 12:12:30 +02:00
|
|
|
}/login${querystring}`
|
2020-05-08 13:50:00 +02:00
|
|
|
);
|
2018-12-06 18:03:56 +01:00
|
|
|
}
|
2020-09-01 20:33:37 +05:30
|
|
|
const isValid = await strapi.plugins['users-permissions'].services.user.validatePassword(
|
2020-05-08 13:50:00 +02:00
|
|
|
ctx.session.documentation,
|
|
|
|
config.password
|
|
|
|
);
|
2018-12-06 18:03:56 +01:00
|
|
|
|
|
|
|
if (!isValid) {
|
|
|
|
ctx.session.documentation = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Execute the action.
|
|
|
|
await next();
|
|
|
|
};
|