Fix password proofs created for registration not working

This commit is contained in:
Alice Gaudon 2020-11-04 11:56:57 +01:00
parent e0b50ebda3
commit 01746913f8
1 changed files with 7 additions and 2 deletions

View File

@ -38,6 +38,7 @@ export class PasswordAuthProof implements AuthProof<User> {
public static createAuthorizedProofForRegistration(session: Express.Session): PasswordAuthProof {
const proofForSession = new PasswordAuthProof(session);
proofForSession.authorized = true;
proofForSession.forRegistration = true;
proofForSession.save();
return proofForSession;
}
@ -47,13 +48,15 @@ export class PasswordAuthProof implements AuthProof<User> {
}
private readonly session: Express.Session;
private userId: number | null;
private authorized: boolean;
private forRegistration: boolean = false;
private userId: number | null;
private userPassword: UserPasswordComponent | null = null;
private constructor(session: Express.Session) {
this.session = session;
this.authorized = session.auth_password_proof?.authorized || false;
this.forRegistration = session.auth_password_proof?.forRegistration || false;
this.userId = session.auth_password_proof?.userId || null;
}
@ -72,7 +75,8 @@ export class PasswordAuthProof implements AuthProof<User> {
}
public async isValid(): Promise<boolean> {
return Boolean(await this.getResource());
return (this.forRegistration || Boolean(await this.getResource())) &&
await this.isAuthorized();
}
public async revoke(): Promise<void> {
@ -98,6 +102,7 @@ export class PasswordAuthProof implements AuthProof<User> {
private save() {
this.session.auth_password_proof = {
authorized: this.authorized,
forRegistration: this.forRegistration,
userId: this.userId,
};
}