diff --git a/src/Controllers/Common/AuthenticationController.cs b/src/Controllers/Common/AuthenticationController.cs index 3ee0896..44b726b 100644 --- a/src/Controllers/Common/AuthenticationController.cs +++ b/src/Controllers/Common/AuthenticationController.cs @@ -6,6 +6,7 @@ using sodoff.Model; using sodoff.Schema; using sodoff.Util; using sodoff.Configuration; +using sodoff.Services; namespace sodoff.Controllers.Common; @@ -14,10 +15,12 @@ public class AuthenticationController : Controller { private readonly DBContext ctx; private readonly IOptions config; + private readonly ModerationService moderationService; - public AuthenticationController(DBContext ctx, IOptions config) { + public AuthenticationController(DBContext ctx, IOptions config, ModerationService moderationService) { this.ctx = ctx; this.config = config; + this.moderationService = moderationService; } [HttpPost] @@ -53,6 +56,14 @@ public class AuthenticationController : Controller { return Ok(new ParentLoginInfo { Status = MembershipUserStatus.InvalidPassword }); } + // check for recent bans, if recent ban is not up and is a complete suspension, disallow login + UserBan? userBan = moderationService.GetLatestBanFromUser(user); + + if(userBan is not null) { + if (userBan.BanType != UserBanType.IndefiniteSuspension && DateTime.UtcNow >= userBan.EndsAt) { moderationService.RemoveBanFromUser(user, userBan); userBan.EndsAt = DateTime.UtcNow; } // remove ban if its up and set retreived userban to have an end date of now + if (userBan.BanType == UserBanType.IndefiniteSuspension || (userBan.BanType == UserBanType.TemporarySuspension && DateTime.UtcNow < userBan.EndsAt)) return Ok(new ParentLoginInfo{ Status = MembershipUserStatus.UserIsBanned }); + } + // Create session Session session = new Session { User = user,