Buchungskalender: Abschluss – S7 Buchungslink-Gueltigkeit (90 Tage nach Abreise, 30 Tage nach Absage), tokenHash beim Anonymisieren leeren
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
17400cac1f
commit
4f9fb6b109
6 files changed
+57
-12
No files matched your search
@@ -9,7 +9,7 @@ import { UkFehler } from '../services/unterkunft/fehler.js'
|
||||
import { unterkunftPerSiteKey } from '../services/unterkunft/kontext.js'
|
||||
import { ID_RE, belegungsStand, findeRechnung, ladeAnfrage, ladeRechnung, ladeUnterkunft, listeUnterkuenfte } from '../services/unterkunft/speicher.js'
|
||||
import { checkoutFuer, schliesseAbWennBezahlt } from '../services/unterkunft/zahlung.js'
|
||||
import { formToken, ipHashVon, pruefeFormToken, tokenPasst } from '../services/unterkunft/token.js'
|
||||
import { formToken, ipHashVon, linkGueltig, pruefeFormToken, tokenPasst } from '../services/unterkunft/token.js'
|
||||
import { darfAnfrage, darfAnfrageSite, darfBuchungsversuch, zaehle } from '../services/termine/limits.js'
|
||||
import { heute } from '../services/termine/zeit.js'
|
||||
|
||||
@@ -364,11 +364,11 @@ router.use((err, req, res, next) => {
|
||||
const BUCHUNG = { mindestdauer: true }
|
||||
const ART_RE = /^(rechnung|storno)$/
|
||||
|
||||
/** Die Anfrage zu Pfad-ID und Token: fuer unbekannte ID, fremde Funktion und falsches Token dieselbe 404-Antwort. */
|
||||
async function ladeMitToken(ctx, id, token) {
|
||||
/** Die Anfrage zu Pfad-ID und Token: fuer unbekannte ID, fremde Funktion, falsches Token und abgelaufenen Link (token.linkGueltig) dieselbe 404-Antwort. */
|
||||
async function ladeMitToken(ctx, id, token, now) {
|
||||
if (!ID_RE.test(id) || typeof token !== 'string' || token === '' || token.length > 200) throw nichtGefunden()
|
||||
const a = await ladeAnfrage(id)
|
||||
if (!a || a.featureId !== ctx.featureId || !tokenPasst(a.tokenHash, token)) throw nichtGefunden()
|
||||
if (!a || a.featureId !== ctx.featureId || !tokenPasst(a.tokenHash, token) || !linkGueltig(a, now)) throw nichtGefunden()
|
||||
return a
|
||||
}
|
||||
|
||||
@@ -431,7 +431,7 @@ router.get(
|
||||
route(
|
||||
async (req, now, cors) => {
|
||||
const ctx = await buchungsKontext(req, now, cors, { schreiben: false })
|
||||
let a = await ladeMitToken(ctx, req.params.id, req.query.t)
|
||||
let a = await ladeMitToken(ctx, req.params.id, req.query.t, now)
|
||||
// Rueckkehr von Stripe vor dem Webhook (oder Webhook verloren): einmal bei Stripe nachsehen
|
||||
a = await schliesseAbWennBezahlt(ctx, a, { now, erzwingen: req.query.wk_zahlung === 'ok' })
|
||||
return { body: await buchungAntwort(ctx, a) }
|
||||
@@ -445,7 +445,7 @@ router.post(
|
||||
route(
|
||||
async (req, now, cors) => {
|
||||
const ctx = await buchungsKontext(req, now, cors, { schreiben: true })
|
||||
const a = await ladeMitToken(ctx, req.params.id, req.query.t)
|
||||
const a = await ladeMitToken(ctx, req.params.id, req.query.t, now)
|
||||
const b = req.body
|
||||
if (!istObjekt(b)) throw ungueltig()
|
||||
const { anfrage, rechnung } = await bucheVerbindlich(ctx, a.$id, req.query.t, {
|
||||
@@ -473,7 +473,7 @@ router.post(
|
||||
route(
|
||||
async (req, now, cors) => {
|
||||
const ctx = await buchungsKontext(req, now, cors, { schreiben: true })
|
||||
let a = await ladeMitToken(ctx, req.params.id, req.query.t)
|
||||
let a = await ladeMitToken(ctx, req.params.id, req.query.t, now)
|
||||
a = await schliesseAbWennBezahlt(ctx, a, { now, erzwingen: true })
|
||||
if (a.status !== 'gebucht' || a.zahlart !== 'online') throw fehlerMit(409, 'status_ungueltig')
|
||||
try {
|
||||
@@ -492,7 +492,7 @@ router.get(
|
||||
route(
|
||||
async (req, now, cors) => {
|
||||
const ctx = await buchungsKontext(req, now, cors, { schreiben: false })
|
||||
const a = await ladeMitToken(ctx, req.params.id, req.query.t)
|
||||
const a = await ladeMitToken(ctx, req.params.id, req.query.t, now)
|
||||
const art = typeof req.query.art === 'string' ? req.query.art : 'rechnung'
|
||||
if (!ART_RE.test(art)) throw ungueltig({ art: 'Ungültig.' })
|
||||
const dok = await findeRechnung(a.$id, art)
|
||||
|
||||
Reference in new issue
Block a user