mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-08-04 19:08:42 +00:00
Reject web logins when banned
This commit is contained in:
parent
0f6a7432ac
commit
2ca80bf8fd
2 changed files with 12 additions and 1 deletions
|
@ -24,7 +24,7 @@
|
||||||
<div class="header">
|
<div class="header">
|
||||||
Uh oh!
|
Uh oh!
|
||||||
</div>
|
</div>
|
||||||
<p>@Model.Error</p>
|
<p style="white-space: pre-line">@Model.Error</p>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
#nullable enable
|
#nullable enable
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
|
using Kettu;
|
||||||
using LBPUnion.ProjectLighthouse.Helpers;
|
using LBPUnion.ProjectLighthouse.Helpers;
|
||||||
|
using LBPUnion.ProjectLighthouse.Logging;
|
||||||
using LBPUnion.ProjectLighthouse.Pages.Layouts;
|
using LBPUnion.ProjectLighthouse.Pages.Layouts;
|
||||||
using LBPUnion.ProjectLighthouse.Types;
|
using LBPUnion.ProjectLighthouse.Types;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
@ -36,16 +38,25 @@ namespace LBPUnion.ProjectLighthouse.Pages
|
||||||
User? user = await this.Database.Users.FirstOrDefaultAsync(u => u.Username == username);
|
User? user = await this.Database.Users.FirstOrDefaultAsync(u => u.Username == username);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
|
Logger.Log($"User {username} failed to login on web due to invalid username", LoggerLevelLogin.Instance);
|
||||||
this.Error = "The username or password you entered is invalid.";
|
this.Error = "The username or password you entered is invalid.";
|
||||||
return this.Page();
|
return this.Page();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!BCrypt.Net.BCrypt.Verify(password, user.Password))
|
if (!BCrypt.Net.BCrypt.Verify(password, user.Password))
|
||||||
{
|
{
|
||||||
|
Logger.Log($"User {user.Username} (id: {user.UserId}) failed to login on web due to invalid password", LoggerLevelLogin.Instance);
|
||||||
this.Error = "The username or password you entered is invalid.";
|
this.Error = "The username or password you entered is invalid.";
|
||||||
return this.Page();
|
return this.Page();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (user.Banned)
|
||||||
|
{
|
||||||
|
Logger.Log($"User {user.Username} (id: {user.UserId}) failed to login on web due to being banned", LoggerLevelLogin.Instance);
|
||||||
|
this.Error = "You have been banned. Please contact an administrator for more information.\nReason: " + user.BannedReason;
|
||||||
|
return this.Page();
|
||||||
|
}
|
||||||
|
|
||||||
WebToken webToken = new()
|
WebToken webToken = new()
|
||||||
{
|
{
|
||||||
UserId = user.UserId,
|
UserId = user.UserId,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue