Improvement of logout. Added Sacrital Service. Added website link for event places and direct link to other websites in worship overview

This commit is contained in:
Torsten Schulz
2024-09-06 16:34:17 +02:00
parent a869f2d16a
commit 5c6cfa41ab
14 changed files with 139 additions and 32 deletions

View File

@@ -1,14 +1,40 @@
const { Worship, EventPlace, Sequelize } = require('../models');
const { Op, fn, literal } = require('sequelize'); // Importieren Sie die Operatoren von Sequelize
const { Worship, EventPlace, Sequelize, sequelize } = require('../models');
const { Op, fn, literal } = require('sequelize');
const jwt = require('jsonwebtoken');
const { isTokenBlacklisted, addTokenToBlacklist } = require('../utils/blacklist');
function isAuthorized(req) {
const authHeader = req.header('Authorization');
if (!authHeader) {
return false;
}
const token = authHeader.replace('Bearer ', '');
if (isTokenBlacklisted(token)) {
console.log('Token is blacklisted');
return false;
}
try {
const decoded = jwt.verify(token, 'zTxVgptmPl9!_dr%xxx9999(dd)');
req.user = decoded;
return true;
} catch (err) {
console.log('Token verification failed, adding to blacklist:', err.message);
addTokenToBlacklist(token);
return false;
}
}
exports.getAllWorships = async (req, res) => {
try {
const authorized = isAuthorized(req);
const worships = await Worship.findAll({
where: {
date: {
[Op.gt]: literal("DATE_SUB(NOW(), INTERVAL 4 WEEK)")
},
},
attributes: authorized ? undefined : { exclude: ['sacristanService'] },
order: [
['date', 'DESC']
],
@@ -69,14 +95,15 @@ exports.getFilteredWorships = async (req, res) => {
[Sequelize.Op.in]: locations
}
}
where.date = {
[Op.gte]: fn('CURDATE'),
};
try {
const authorized = isAuthorized(req);
console.log(authorized);
const worships = await Worship.findAll({
where,
attributes: authorized ? undefined : { exclude: ['sacristanService'] },
include: {
model: EventPlace,
as: 'eventPlace',