AuthController: use Validator system for unknown user on login

This commit is contained in:
Alice Gaudon 2020-11-15 15:18:57 +01:00
parent 6eacfdcffa
commit 6a65ec723d

View File

@ -6,6 +6,7 @@ import ModelFactory from "../db/ModelFactory";
import User from "./models/User"; import User from "./models/User";
import UserPasswordComponent from "./password/UserPasswordComponent"; import UserPasswordComponent from "./password/UserPasswordComponent";
import UserNameComponent from "./models/UserNameComponent"; import UserNameComponent from "./models/UserNameComponent";
import {UnknownRelationValidationError} from "../db/Validator";
export default class AuthController extends Controller { export default class AuthController extends Controller {
public getRoutesPrefix(): string { public getRoutesPrefix(): string {
@ -103,10 +104,9 @@ export default class AuthController extends Controller {
} }
protected async redirectToRegistration(req: Request, res: Response, identifier: string): Promise<void> { protected async redirectToRegistration(req: Request, res: Response, identifier: string): Promise<void> {
req.flash('register_identifier', identifier); const error = new UnknownRelationValidationError(User.table, 'identifier');
req.flash('info', `User with identifier "${identifier}" not found.`); error.thingName = 'identifier';
res.redirect(Controller.route('auth', undefined, { error.value = identifier;
redirect_uri: req.query.redirect_uri?.toString() || undefined, throw error;
}));
} }
} }