diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/MessageController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/MessageController.cs index 877d6be5..7a82deca 100644 --- a/ProjectLighthouse.Servers.GameServer/Controllers/MessageController.cs +++ b/ProjectLighthouse.Servers.GameServer/Controllers/MessageController.cs @@ -57,7 +57,7 @@ along with this program. If not, see ."; UserEntity? user = await this.database.UserFromGameToken(token); - StringBuilder announceText = new(ServerConfiguration.Instance.AnnounceText + "\n\n"); + StringBuilder announceText = new(ServerConfiguration.Instance.AnnounceText); announceText.Replace("%user", user.Username); announceText.Replace("%id", token.UserId.ToString()); @@ -69,7 +69,7 @@ along with this program. If not, see ."; if (EmailEnforcementConfiguration.Instance.EnableEmailEnforcement) { - announceText.Append(BaseLayoutStrings.EmailEnforcementWarnMain.Translate(LocalizationManager.DefaultLang) + "\n\n"); + announceText.Append("\n\n" + BaseLayoutStrings.EmailEnforcementWarnMain.Translate(LocalizationManager.DefaultLang) + "\n\n"); if (user.EmailAddress == null) { @@ -148,7 +148,7 @@ along with this program. If not, see ."; if (!SMTPHelper.IsValidEmail(this.database, email)) return this.BadRequest(); UserEntity? user = await this.database.UserFromGameToken(token); - if (user == null || user.EmailAddressVerified) return this.Ok(); + if (user == null || user.EmailAddressVerified) return this.BadRequest(); user.EmailAddress = email; await SMTPHelper.SendVerificationEmail(this.database, mailService, user); diff --git a/ProjectLighthouse.Servers.GameServer/Middlewares/EmailEnforcementMiddleware.cs b/ProjectLighthouse.Servers.GameServer/Middlewares/EmailEnforcementMiddleware.cs index 0fbce0be..b269c97a 100644 --- a/ProjectLighthouse.Servers.GameServer/Middlewares/EmailEnforcementMiddleware.cs +++ b/ProjectLighthouse.Servers.GameServer/Middlewares/EmailEnforcementMiddleware.cs @@ -15,12 +15,12 @@ public class EmailEnforcementMiddleware : MiddlewareDBContext public override async Task InvokeAsync(HttpContext context, DatabaseContext database) { - // Split path into segments - string[] pathSegments = context.Request.Path.ToString().Split("/", StringSplitOptions.RemoveEmptyEntries); + if (EmailEnforcementConfiguration.Instance.EnableEmailEnforcement) + { + // Split path into segments + string[] pathSegments = context.Request.Path.ToString().Split("/", StringSplitOptions.RemoveEmptyEntries); - if (pathSegments[0] == "LITTLEBIGPLANETPS3_XML") - { - if (EmailEnforcementConfiguration.Instance.EnableEmailEnforcement) + if (pathSegments[0] == "LITTLEBIGPLANETPS3_XML") { // Get user via GameToken GameTokenEntity? token = await database.GameTokenFromRequest(context.Request); @@ -35,7 +35,7 @@ public class EmailEnforcementMiddleware : MiddlewareDBContext if (user == null) { // Send bad request status - context.Response.StatusCode = StatusCodes.Status400BadRequest; + context.Response.StatusCode = StatusCodes.Status403Forbidden; await context.Response.WriteAsync("Not a valid user"); // Don't go to next in pipeline diff --git a/ProjectLighthouse.Tests.GameApiTests/Unit/Controllers/MessageControllerTests.cs b/ProjectLighthouse.Tests.GameApiTests/Unit/Controllers/MessageControllerTests.cs index a0b42a0a..acda5cbc 100644 --- a/ProjectLighthouse.Tests.GameApiTests/Unit/Controllers/MessageControllerTests.cs +++ b/ProjectLighthouse.Tests.GameApiTests/Unit/Controllers/MessageControllerTests.cs @@ -224,7 +224,7 @@ along with this program. If not, see ." + "\nuni IActionResult result = await messageController.Filter(mailMock.Object); - Assert.IsType(result); + Assert.IsType(result); mailMock.Verify(x => x.SendEmailAsync(It.IsAny(), It.IsAny(), It.IsAny()), Times.Never); } @@ -249,7 +249,7 @@ along with this program. If not, see ." + "\nuni IActionResult result = await messageController.Filter(mailMock.Object); - Assert.IsType(result); + Assert.IsType(result); mailMock.Verify(x => x.SendEmailAsync(It.IsAny(), It.IsAny(), It.IsAny()), Times.Never); } @@ -271,7 +271,7 @@ along with this program. If not, see ." + "\nuni IActionResult result = await messageController.Filter(mailMock.Object); - Assert.IsType(result); + Assert.IsType(result); mailMock.Verify(x => x.SendEmailAsync(It.IsAny(), It.IsAny(), It.IsAny()), Times.Never); } } \ No newline at end of file