mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-08-05 11:28:39 +00:00
Add comment logging, move comment submissions to POST request
Closes #185
This commit is contained in:
parent
61a1520695
commit
c8595f5522
4 changed files with 45 additions and 24 deletions
|
@ -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<IActionResult> PostComment([FromRoute] int id, [FromQuery] string? msg)
|
||||
[HttpPost("postComment")]
|
||||
public async Task<IActionResult> 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);
|
||||
}
|
||||
|
|
|
@ -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<IActionResult> 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<IActionResult> 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<IActionResult> PostComment([FromRoute] int id, [FromQuery] string? msg)
|
||||
[HttpPost("postComment")]
|
||||
public async Task<IActionResult> 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<IActionResult> 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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
||||
|
|
|
@ -30,12 +30,13 @@
|
|||
@if (Model.CommentsEnabled && Model.User != null)
|
||||
{
|
||||
<div class="ui divider"></div>
|
||||
<form class="ui reply form" action="@Url.RouteUrl(ViewContext.RouteData.Values)/postComment">
|
||||
<form class="ui reply form" action="@Url.RouteUrl(ViewContext.RouteData.Values)/postComment" method="post">
|
||||
<div class="field">
|
||||
<textarea style="min-height: 70px; height: 70px; max-height:120px" name="msg"></textarea>
|
||||
</div>
|
||||
<input type="submit" class="ui blue button">
|
||||
</form>
|
||||
<br>
|
||||
}
|
||||
|
||||
@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;
|
||||
|
||||
<div style="display: flex" id="@comment.CommentId">
|
||||
<div class="voting">
|
||||
<a href="@url/rateComment?commentId=@(comment.CommentId)&rating=@(comment.YourThumb == 1 ? 0 : 1)">
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue