From f6b326f802c26aafff6215d734bad0b570fbb287 Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Sun, 6 Sep 2020 10:21:47 +0200 Subject: [PATCH] Move EMAIL_REGEXP to Validator --- src/auth/models/MagicLink.ts | 3 ++- src/auth/models/UserEmail.ts | 2 +- src/db/Model.ts | 2 -- src/db/Validator.ts | 2 ++ 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/auth/models/MagicLink.ts b/src/auth/models/MagicLink.ts index eceb51e..c82b382 100644 --- a/src/auth/models/MagicLink.ts +++ b/src/auth/models/MagicLink.ts @@ -1,12 +1,13 @@ import crypto from "crypto"; import config from "config"; -import Model, {EMAIL_REGEX} from "../../db/Model"; +import Model from "../../db/Model"; import AuthProof from "../AuthProof"; import User from "./User"; import argon2 from "argon2"; import {WhereTest} from "../../db/ModelQuery"; import UserEmail from "./UserEmail"; import ModelFactory from "../../db/ModelFactory"; +import {EMAIL_REGEX} from "../../db/Validator"; export default class MagicLink extends Model implements AuthProof { public static async bySessionID(sessionID: string, actionType?: string | string[]): Promise { diff --git a/src/auth/models/UserEmail.ts b/src/auth/models/UserEmail.ts index c42d671..9af530c 100644 --- a/src/auth/models/UserEmail.ts +++ b/src/auth/models/UserEmail.ts @@ -1,7 +1,7 @@ import User from "./User"; -import Model, {EMAIL_REGEX} from "../../db/Model"; import {OneModelRelation} from "../../db/ModelRelation"; import ModelFactory from "../../db/ModelFactory"; +import {EMAIL_REGEX} from "../../db/Validator"; export default class UserEmail extends Model { public readonly id?: number = undefined; diff --git a/src/db/Model.ts b/src/db/Model.ts index 8a24deb..3bec1a7 100644 --- a/src/db/Model.ts +++ b/src/db/Model.ts @@ -222,5 +222,3 @@ export default abstract class Model { }); } } - -export const EMAIL_REGEX = /^[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+$/; diff --git a/src/db/Validator.ts b/src/db/Validator.ts index b888c08..b926bf6 100644 --- a/src/db/Validator.ts +++ b/src/db/Validator.ts @@ -4,6 +4,8 @@ import {Connection} from "mysql"; import {Type} from "../Utils"; import {ServerError} from "../HttpError"; +export const EMAIL_REGEX = /^[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+$/; + export default class Validator { private readonly steps: ValidationStep[] = []; private readonly validationAttributes: string[] = [];