Added consent page.
This commit is contained in:
29
src/web/consent.js
Normal file
29
src/web/consent.js
Normal file
@@ -0,0 +1,29 @@
|
||||
export default function consentHandler(req, res, next) {
|
||||
if (Object.hasOwn(req.query, 'lgbt')) {
|
||||
const lgbtFilters = (req.tagFilter || []).filter((tag) => !['gay', 'bisexual', 'transsexual'].includes(tag));
|
||||
|
||||
req.tagFilter = lgbtFilters; // eslint-disable-line no-param-reassign
|
||||
res.cookie('tags', JSON.stringify(lgbtFilters));
|
||||
}
|
||||
|
||||
if (Object.hasOwn(req.query, 'straight')) {
|
||||
const straightFilters = Array.from(new Set([...(req.tagFilter || []), 'gay', 'bisexual', 'transsexual']));
|
||||
|
||||
req.tagFilter = straightFilters; // eslint-disable-line no-param-reassign
|
||||
res.cookie('tags', JSON.stringify(straightFilters));
|
||||
}
|
||||
|
||||
if (Object.hasOwn(req.query, 'consent')) {
|
||||
req.session.hasConsent = true; // eslint-disable-line no-param-reassign
|
||||
res.redirect(req.path);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!req.path.includes('/consent') && !req.session?.hasConsent) {
|
||||
res.redirect('/consent');
|
||||
return;
|
||||
}
|
||||
|
||||
next();
|
||||
}
|
||||
Reference in New Issue
Block a user