juice-shop
33 строки · 1.0 Кб
1/*
2* Copyright (c) 2014-2024 Bjoern Kimminich & the OWASP Juice Shop contributors.
3* SPDX-License-Identifier: MIT
4*/
5
6import { type Request, type Response, type NextFunction } from 'express'7import { SecurityAnswerModel } from '../models/securityAnswer'8import { UserModel } from '../models/user'9import { SecurityQuestionModel } from '../models/securityQuestion'10
11module.exports = function securityQuestion () {12return ({ query }: Request, res: Response, next: NextFunction) => {13const email = query.email14SecurityAnswerModel.findOne({15include: [{16model: UserModel,17where: { email: email?.toString() }18}]19}).then((answer: SecurityAnswerModel | null) => {20if (answer != null) {21SecurityQuestionModel.findByPk(answer.SecurityQuestionId).then((question: SecurityQuestionModel | null) => {22res.json({ question })23}).catch((error: Error) => {24next(error)25})26} else {27res.json({})28}29}).catch((error: unknown) => {30next(error)31})32}33}
34