AuthGuard: always provide a string to pending account mail username

This commit is contained in:
Alice Gaudon 2021-01-25 14:37:50 +01:00
parent b211845f57
commit 8a25f214ab

View File

@ -11,6 +11,7 @@ import Application from "../Application";
import NunjucksComponent from "../components/NunjucksComponent";
import AuthMethod from "./AuthMethod";
import {Session, SessionData} from "express-session";
import UserNameComponent from "./models/UserNameComponent";
export default class AuthGuard {
private readonly authMethods: AuthMethod<AuthProof<User>>[];
@ -140,7 +141,9 @@ export default class AuthGuard {
if (!user.isApproved()) {
await new Mail(this.app.as(NunjucksComponent).getEnvironment(), PENDING_ACCOUNT_REVIEW_MAIL_TEMPLATE, {
username: (await user.mainEmail.get())?.getOrFail('email'),
username: user.asOptional(UserNameComponent)?.name ||
(await user.mainEmail.get())?.getOrFail('email') ||
'Could not find an identifier',
link: config.get<string>('public_url') + Controller.route('accounts-approval'),
}).send(config.get<string>('app.contact_email'));
}