From 683fe7262be6c33439732054a4dca8c4294d0875 Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Sun, 15 Nov 2020 14:14:56 +0100 Subject: [PATCH] MagicLinkAuthMethod: do not allow register for already existing email --- src/auth/magic_link/MagicLinkAuthMethod.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/auth/magic_link/MagicLinkAuthMethod.ts b/src/auth/magic_link/MagicLinkAuthMethod.ts index f58156e..52eba91 100644 --- a/src/auth/magic_link/MagicLinkAuthMethod.ts +++ b/src/auth/magic_link/MagicLinkAuthMethod.ts @@ -11,6 +11,7 @@ import RedirectBackComponent from "../../components/RedirectBackComponent"; import Application from "../../Application"; import {MailTemplate} from "../../mail/Mail"; import AuthMagicLinkActionType from "./AuthMagicLinkActionType"; +import Validator from "../../db/Validator"; export default class MagicLinkAuthMethod implements AuthMethod { public constructor( @@ -75,6 +76,12 @@ export default class MagicLinkAuthMethod implements AuthMethod { const geo = geoip.lookup(req.ip); const actionType = isRegistration ? AuthMagicLinkActionType.REGISTER : AuthMagicLinkActionType.LOGIN; + if (isRegistration) { + await Validator.validate({ + email: new Validator().defined().unique(UserEmail, 'email'), + }, {email: email}); + } + await MagicLinkController.sendMagicLink( this.app, req.getSession().id,