-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #95 from VictoriqueMoe/allow-login-errors
all login related errors now render IN the login page
- Loading branch information
Showing
16 changed files
with
84 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 0 additions & 14 deletions
14
src/engine/impl/HttpErrorRenderers/AbstractEjsHttpRenderEngine.ts
This file was deleted.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
src/engine/impl/HttpErrorRenderers/AuthenticationErrorRenderEngine.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { 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"; | ||
|
||
@Injectable({ | ||
scope: ProviderScope.SINGLETON, | ||
type: HTTP_RENDER_ENGINE, | ||
}) | ||
export class AuthenticationErrorRenderEngine implements IHttpErrorRenderEngine<string, AuthenticationError> { | ||
public supportsError(exception: Exception): boolean { | ||
return exception instanceof AuthenticationError; | ||
} | ||
|
||
public render(obj: HttpErrorRenderObj<AuthenticationError>, response: PlatformResponse): Promise<string> { | ||
return response.render("login.ejs", obj); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/engine/impl/HttpErrorRenderers/ReCAPTCHALoginExceptionRenderEngine.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import type { IHttpErrorRenderEngine } from "../../IHttpErrorRenderEngine.js"; | ||
import { ReCAPTCHAException } from "../../../model/exceptions/ReCAPTCHAException.js"; | ||
import { 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"; | ||
|
||
@Injectable({ | ||
scope: ProviderScope.SINGLETON, | ||
type: HTTP_RENDER_ENGINE, | ||
}) | ||
export class ReCAPTCHALoginExceptionRenderEngine implements IHttpErrorRenderEngine<string, ReCAPTCHAException> { | ||
@InjectContext() | ||
protected $ctx?: PlatformContext; | ||
|
||
public render(obj: HttpErrorRenderObj<ReCAPTCHAException>, response: PlatformResponse): Promise<string> { | ||
return response.render("login.ejs", obj); | ||
} | ||
|
||
public supportsError(exception: Exception): boolean { | ||
return this.$ctx?.url.includes("/login") ? exception instanceof ReCAPTCHAException : false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Unauthorized } from "@tsed/exceptions"; | ||
|
||
export class AuthenticationError extends Unauthorized { | ||
public constructor(message: string, origin?: Error | string) { | ||
if (message === "Unauthorized") { | ||
super("Incorrect email/password", origin); | ||
} else { | ||
super(message, origin); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { BadRequest } from "@tsed/exceptions"; | ||
|
||
export class ReCAPTCHAException extends BadRequest { | ||
public constructor(message: string, origin?: Error | string) { | ||
super(message, origin); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters