Tied consent warning to session.

This commit is contained in:
DebaucheryLibrarian
2020-12-19 23:01:17 +01:00
parent be4d025505
commit bd77d4347d
10 changed files with 121 additions and 11 deletions

8
src/web/consent.js Normal file
View File

@@ -0,0 +1,8 @@
'use strict';
function setConsent(req, res) {
req.session.consent = !!req.body;
res.status(204).send();
}
module.exports = setConsent;

View File

@@ -6,12 +6,15 @@ const express = require('express');
const { postgraphile } = require('postgraphile');
const Router = require('express-promise-router');
const bodyParser = require('body-parser');
const session = require('express-session');
const KnexSessionStore = require('connect-session-knex')(session);
const PgConnectionFilterPlugin = require('postgraphile-plugin-connection-filter');
const PgSimplifyInflectorPlugin = require('@graphile-contrib/pg-simplify-inflector');
const PgOrderByRelatedPlugin = require('@graphile-contrib/pg-order-by-related');
const logger = require('../logger')(__filename);
const knex = require('../knex');
const { ActorPlugins, SitePlugins, ReleasePlugins } = require('./plugins/plugins');
const {
@@ -35,9 +38,12 @@ const {
fetchTags,
} = require('./tags');
const setConsent = require('./consent');
async function initServer() {
const app = express();
const router = Router();
const store = new KnexSessionStore({ knex });
const connectionString = `postgres://${config.database.user}:${config.database.password}@${config.database.host}:5432/${config.database.database}`;
@@ -77,6 +83,7 @@ async function initServer() {
});
router.use(bodyParser.json({ strict: false }));
router.use(session({ ...config.web.session, store }));
router.get('/api/scenes', fetchScenes);
router.get('/api/scenes/:releaseId', fetchScene);
@@ -103,10 +110,13 @@ async function initServer() {
router.get('/api/tags', fetchTags);
router.get('/api/tags/:tagId', fetchTag);
router.post('/api/consent', setConsent);
router.get('*', (req, res) => {
res.render(path.join(__dirname, '../../assets/index.ejs'), {
env: JSON.stringify({
sfw: !!req.headers.sfw || Object.prototype.hasOwnProperty.call(req.query, 'sfw'),
consent: !!req.session.consent,
}),
});
});