MagicLinkAuthMethod: do not allow register for already existing email

This commit is contained in:
Alice Gaudon 2020-11-15 14:14:56 +01:00
parent c08d03c8fb
commit 683fe7262b

View File

@ -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<MagicLink> {
public constructor(
@ -75,6 +76,12 @@ export default class MagicLinkAuthMethod implements AuthMethod<MagicLink> {
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,