Move EMAIL_REGEXP to Validator

This commit is contained in:
Alice Gaudon 2020-09-06 10:21:47 +02:00
parent 27bd7400e2
commit f6b326f802
4 changed files with 5 additions and 4 deletions

View File

@ -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<User> {
public static async bySessionID(sessionID: string, actionType?: string | string[]): Promise<MagicLink | null> {

View File

@ -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;

View File

@ -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])?)+$/;

View File

@ -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<T> {
private readonly steps: ValidationStep<T>[] = [];
private readonly validationAttributes: string[] = [];