diff --git a/ProjectLighthouse/Controllers/Website/SlotPageController.cs b/ProjectLighthouse/Controllers/Website/SlotPageController.cs index 92edbb3e..24968595 100644 --- a/ProjectLighthouse/Controllers/Website/SlotPageController.cs +++ b/ProjectLighthouse/Controllers/Website/SlotPageController.cs @@ -1,5 +1,7 @@ #nullable enable using System.Threading.Tasks; +using Kettu; +using LBPUnion.ProjectLighthouse.Logging; using LBPUnion.ProjectLighthouse.Types; using LBPUnion.ProjectLighthouse.Types.Levels; using Microsoft.AspNetCore.Mvc; @@ -34,15 +36,20 @@ public class SlotPageController : ControllerBase return this.Redirect($"~/slot/{id}#{commentId}"); } - [HttpGet("postComment")] - public async Task PostComment([FromRoute] int id, [FromQuery] string? msg) + [HttpPost("postComment")] + public async Task PostComment([FromRoute] int id, [FromForm] string? msg) { User? user = this.database.UserFromWebRequest(this.Request); if (user == null) return this.Redirect("~/login"); - if (msg == null) return this.Redirect("~/slot/" + id); + if (msg == null) + { + Logger.Log($"Refusing to post comment from {user.UserId} on user {id}, {nameof(msg)} is null", LoggerLevelComments.Instance); + return this.Redirect("~/slot/" + id); + } await this.database.PostComment(user, id, CommentType.Level, msg); + Logger.Log($"Posted comment from {user.UserId}: \"{msg}\" on user {id}", LoggerLevelComments.Instance); return this.Redirect("~/slot/" + id); } diff --git a/ProjectLighthouse/Controllers/Website/UserPageController.cs b/ProjectLighthouse/Controllers/Website/UserPageController.cs index c22e1623..627ff511 100644 --- a/ProjectLighthouse/Controllers/Website/UserPageController.cs +++ b/ProjectLighthouse/Controllers/Website/UserPageController.cs @@ -1,10 +1,9 @@ #nullable enable -using System; using System.Threading.Tasks; +using Kettu; +using LBPUnion.ProjectLighthouse.Logging; using LBPUnion.ProjectLighthouse.Types; -using LBPUnion.ProjectLighthouse.Types.Profiles; using Microsoft.AspNetCore.Mvc; -using Microsoft.CodeAnalysis; using Microsoft.EntityFrameworkCore; namespace LBPUnion.ProjectLighthouse.Controllers.Website; @@ -20,20 +19,6 @@ public class UserPageController : ControllerBase this.database = database; } - [HttpGet("heart")] - public async Task HeartUser([FromRoute] int id) - { - User? user = this.database.UserFromWebRequest(this.Request); - if (user == null) return this.Redirect("~/login"); - - User? heartedUser = await this.database.Users.FirstOrDefaultAsync(u => u.UserId == id); - if (heartedUser == null) return this.NotFound(); - - await this.database.HeartUser(user, heartedUser); - - return this.Redirect("~/user/" + id); - } - [HttpGet("rateComment")] public async Task RateComment([FromRoute] int id, [FromQuery] int? commentId, [FromQuery] int? rating) { @@ -45,15 +30,34 @@ public class UserPageController : ControllerBase return this.Redirect($"~/user/{id}#{commentId}"); } - [HttpGet("postComment")] - public async Task PostComment([FromRoute] int id, [FromQuery] string? msg) + [HttpPost("postComment")] + public async Task PostComment([FromRoute] int id, [FromForm] string? msg) { User? user = this.database.UserFromWebRequest(this.Request); if (user == null) return this.Redirect("~/login"); - if (msg == null) return this.Redirect("~/user/" + id); + if (msg == null) + { + Logger.Log($"Refusing to post comment from {user.UserId} on user {id}, {nameof(msg)} is null", LoggerLevelComments.Instance); + return this.Redirect("~/user/" + id); + } await this.database.PostComment(user, id, CommentType.Profile, msg); + Logger.Log($"Posted comment from {user.UserId}: \"{msg}\" on user {id}", LoggerLevelComments.Instance); + + return this.Redirect("~/user/" + id); + } + + [HttpGet("heart")] + public async Task HeartUser([FromRoute] int id) + { + User? user = this.database.UserFromWebRequest(this.Request); + if (user == null) return this.Redirect("~/login"); + + User? heartedUser = await this.database.Users.FirstOrDefaultAsync(u => u.UserId == id); + if (heartedUser == null) return this.NotFound(); + + await this.database.HeartUser(user, heartedUser); return this.Redirect("~/user/" + id); } diff --git a/ProjectLighthouse/Logging/LoggerLevels.cs b/ProjectLighthouse/Logging/LoggerLevels.cs index e7175fc3..303dda97 100644 --- a/ProjectLighthouse/Logging/LoggerLevels.cs +++ b/ProjectLighthouse/Logging/LoggerLevels.cs @@ -63,6 +63,12 @@ public class LoggerLevelInflux : LoggerLevel public override string Name => "Influx"; } +public class LoggerLevelComments : LoggerLevel +{ + public static readonly LoggerLevelComments Instance = new(); + public override string Name => "Comments"; +} + public class LoggerLevelAspNet : LoggerLevel { diff --git a/ProjectLighthouse/Pages/Partials/CommentsPartial.cshtml b/ProjectLighthouse/Pages/Partials/CommentsPartial.cshtml index a4a50ec2..c6114822 100644 --- a/ProjectLighthouse/Pages/Partials/CommentsPartial.cshtml +++ b/ProjectLighthouse/Pages/Partials/CommentsPartial.cshtml @@ -30,12 +30,13 @@ @if (Model.CommentsEnabled && Model.User != null) {
-
+
+
} @for(int i = 0; i < Model.Comments.Count; i++) @@ -44,9 +45,12 @@ DateTimeOffset timestamp = DateTimeOffset.FromUnixTimeSeconds(comment.Timestamp / 1000); StringWriter messageWriter = new(); HttpUtility.HtmlDecode(comment.getComment(), messageWriter); + string decodedMessage = messageWriter.ToString(); string url = Url.RouteUrl(ViewContext.RouteData.Values); + int rating = comment.ThumbsUp - comment.ThumbsDown; +