Skip to content

Commit

Permalink
Merge pull request #119 from waifuvault/fix-login
Browse files Browse the repository at this point in the history
fix issue with invalid password-causing exception
  • Loading branch information
VictoriqueMoe committed Mar 17, 2024
2 parents 6f6c8ad + cfd759b commit 36b0769
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
import { Injectable, ProviderScope } from "@tsed/di";
import { Inject, Injectable, ProviderScope } from "@tsed/di";
import { HTTP_RENDER_ENGINE } from "../../../model/di/tokens.js";
import type { IHttpErrorRenderEngine } from "../../IHttpErrorRenderEngine.js";
import { AuthenticationError } from "../../../model/exceptions/AuthenticationError.js";
import { Exception } from "@tsed/exceptions";
import { HttpErrorRenderObj } from "../../../utils/typeings.js";
import { PlatformResponse } from "@tsed/common";
import { CaptchaManager } from "../../../manager/CaptchaManager.js";

@Injectable({
scope: ProviderScope.SINGLETON,
type: HTTP_RENDER_ENGINE,
})
export class AuthenticationErrorRenderEngine implements IHttpErrorRenderEngine<string, AuthenticationError> {
public constructor(@Inject() private captchaManager: CaptchaManager) {}

public supportsError(exception: Exception): boolean {
return exception instanceof AuthenticationError;
}

public render(obj: HttpErrorRenderObj<AuthenticationError>, response: PlatformResponse): Promise<string> {
return response.render("login.ejs", obj);
const captchaType = this.captchaManager.engine?.type ?? null;
return response.render("login.ejs", {
captchaType,
...obj,
});
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
import type { IHttpErrorRenderEngine } from "../../IHttpErrorRenderEngine.js";
import { ReCAPTCHAException } from "../../../model/exceptions/ReCAPTCHAException.js";
import { Injectable, InjectContext, ProviderScope } from "@tsed/di";
import { Inject, Injectable, InjectContext, ProviderScope } from "@tsed/di";
import { HTTP_RENDER_ENGINE } from "../../../model/di/tokens.js";
import { HttpErrorRenderObj } from "../../../utils/typeings.js";
import { type PlatformContext, PlatformResponse } from "@tsed/common";
import { Exception } from "@tsed/exceptions";
import { CaptchaManager } from "../../../manager/CaptchaManager.js";

@Injectable({
scope: ProviderScope.SINGLETON,
type: HTTP_RENDER_ENGINE,
})
export class ReCAPTCHALoginExceptionRenderEngine implements IHttpErrorRenderEngine<string, ReCAPTCHAException> {
public constructor(@Inject() private captchaManager: CaptchaManager) {}

@InjectContext()
protected $ctx?: PlatformContext;

public render(obj: HttpErrorRenderObj<ReCAPTCHAException>, response: PlatformResponse): Promise<string> {
return response.render("login.ejs", obj);
const captchaType = this.captchaManager.engine?.type ?? null;
return response.render("login.ejs", {
captchaType,
...obj,
});
}

public supportsError(exception: Exception): boolean {
Expand Down

0 comments on commit 36b0769

Please sign in to comment.