Skip to content

Commit

Permalink
allow banned IPs to call the GET version of Account/Login, only preve…
Browse files Browse the repository at this point in the history
…nt POST, avoid unnecessary db hit on GET Account/Login for user check
  • Loading branch information
adelikat committed Nov 2, 2024
1 parent 4427a1c commit 7dcebd3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 1 addition & 2 deletions TASVideos/Pages/Account/Login.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ public class LoginModel(SignInManager signInManager, IHostEnvironment env) : Bas

public async Task<IActionResult> OnGet()
{
var user = await signInManager.UserManager.GetUserAsync(User);
if (user is not null)
if (User.Identity?.IsAuthenticated ?? false)
{
return BaseReturnUrlRedirect();
}
Expand Down
6 changes: 6 additions & 0 deletions TASVideos/Pages/IpBanCheckAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ public class IpBanCheckAttribute : Attribute, IAsyncPageFilter
{
public async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
{
if (context.HttpContext.Request.Method == "GET")
{
await next.Invoke();
return;
}

var banService = context.HttpContext.RequestServices.GetRequiredService<IIpBanService>();

var ip = context.HttpContext.ActualIpAddress();
Expand Down

0 comments on commit 7dcebd3

Please sign in to comment.