2020-10-27 11:27:17 +01:00
|
|
|
'use strict';
|
|
|
|
|
2018-12-06 18:03:56 +01:00
|
|
|
module.exports = async (ctx, next) => {
|
|
|
|
const pluginStore = strapi.store({
|
|
|
|
environment: '',
|
|
|
|
type: 'plugin',
|
|
|
|
name: 'documentation',
|
|
|
|
});
|
|
|
|
const config = await pluginStore.get({ key: 'config' });
|
|
|
|
|
|
|
|
if (!config.restrictedAccess) {
|
|
|
|
return await next();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ctx.session.documentation) {
|
|
|
|
const querystring = ctx.querystring ? `?${ctx.querystring}` : '';
|
|
|
|
|
2020-05-08 13:50:00 +02:00
|
|
|
return ctx.redirect(
|
|
|
|
`${strapi.config.server.url}${strapi.plugins.documentation.config['x-strapi-config'].path}/login${querystring}`
|
|
|
|
);
|
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();
|
|
|
|
};
|