Rewrite captcha system (#754)

Rewrite captcha and remove many unused directives
This commit is contained in:
Josh 2023-04-28 23:32:42 -05:00 committed by GitHub
commit 3aa9033b67
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
36 changed files with 101 additions and 111 deletions

View file

@ -3,10 +3,10 @@ using System.Web;
using JetBrains.Annotations;
using LBPUnion.ProjectLighthouse.Configuration;
using LBPUnion.ProjectLighthouse.Database;
using LBPUnion.ProjectLighthouse.Extensions;
using LBPUnion.ProjectLighthouse.Helpers;
using LBPUnion.ProjectLighthouse.Localization.StringLists;
using LBPUnion.ProjectLighthouse.Logging;
using LBPUnion.ProjectLighthouse.Servers.Website.Captcha;
using LBPUnion.ProjectLighthouse.Servers.Website.Pages.Layouts;
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
using LBPUnion.ProjectLighthouse.Types.Entities.Token;
@ -18,8 +18,12 @@ namespace LBPUnion.ProjectLighthouse.Servers.Website.Pages.Login;
public class LoginForm : BaseLayout
{
public LoginForm(DatabaseContext database) : base(database)
{}
private readonly ICaptchaService captchaService;
public LoginForm(DatabaseContext database, ICaptchaService captchaService) : base(database)
{
this.captchaService = captchaService;
}
public string? Error { get; private set; }
@ -38,7 +42,7 @@ public class LoginForm : BaseLayout
return this.Page();
}
if (!await this.Request.CheckCaptchaValidity())
if (!await this.captchaService.VerifyCaptcha(this.Request))
{
this.Error = this.Translate(ErrorStrings.CaptchaFailed);
return this.Page();

View file

@ -2,9 +2,9 @@ using System.Diagnostics.CodeAnalysis;
using JetBrains.Annotations;
using LBPUnion.ProjectLighthouse.Configuration;
using LBPUnion.ProjectLighthouse.Database;
using LBPUnion.ProjectLighthouse.Extensions;
using LBPUnion.ProjectLighthouse.Helpers;
using LBPUnion.ProjectLighthouse.Localization.StringLists;
using LBPUnion.ProjectLighthouse.Servers.Website.Captcha;
using LBPUnion.ProjectLighthouse.Servers.Website.Pages.Layouts;
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
using LBPUnion.ProjectLighthouse.Types.Entities.Token;
@ -15,8 +15,12 @@ namespace LBPUnion.ProjectLighthouse.Servers.Website.Pages.Login;
public class RegisterForm : BaseLayout
{
public RegisterForm(DatabaseContext database) : base(database)
{ }
private readonly ICaptchaService captchaService;
public RegisterForm(DatabaseContext database, ICaptchaService captchaService) : base(database)
{
this.captchaService = captchaService;
}
public string? Error { get; private set; }
@ -68,7 +72,7 @@ public class RegisterForm : BaseLayout
return this.Page();
}
if (!await this.Request.CheckCaptchaValidity())
if (!await this.captchaService.VerifyCaptcha(this.Request))
{
this.Error = this.Translate(ErrorStrings.CaptchaFailed);
return this.Page();