mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-05-14 05:42:27 +00:00
Refactor deserialization and authentication (#550)
* Refactor deserialization and more * Refactor authentication flow * Fix unit tests * Make deserialization better
This commit is contained in:
parent
505b5eb03b
commit
b3a00da554
48 changed files with 575 additions and 589 deletions
|
@ -1,16 +1,18 @@
|
|||
#nullable enable
|
||||
using System.Text.Json;
|
||||
using System.Xml.Serialization;
|
||||
using LBPUnion.ProjectLighthouse.Administration.Reports;
|
||||
using LBPUnion.ProjectLighthouse.Configuration;
|
||||
using LBPUnion.ProjectLighthouse.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Helpers;
|
||||
using LBPUnion.ProjectLighthouse.PlayerData;
|
||||
using LBPUnion.ProjectLighthouse.PlayerData.Profiles;
|
||||
using LBPUnion.ProjectLighthouse.Types;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
[Route("LITTLEBIGPLANETPS3_XML/")]
|
||||
[Produces("text/xml")]
|
||||
public class ReportController : ControllerBase
|
||||
|
@ -25,15 +27,11 @@ public class ReportController : ControllerBase
|
|||
[HttpPost("grief")]
|
||||
public async Task<IActionResult> Report()
|
||||
{
|
||||
User? user = await this.database.UserFromGameRequest(this.Request);
|
||||
if (user == null) return this.StatusCode(403, "");
|
||||
GameToken token = this.GetToken();
|
||||
|
||||
this.Request.Body.Position = 0;
|
||||
string bodyString = await new StreamReader(this.Request.Body).ReadToEndAsync();
|
||||
|
||||
XmlSerializer serializer = new(typeof(GriefReport));
|
||||
GriefReport? report = (GriefReport?)serializer.Deserialize(new StringReader(bodyString));
|
||||
string username = await this.database.UsernameFromGameToken(token);
|
||||
|
||||
GriefReport? report = await this.DeserializeBody<GriefReport>();
|
||||
if (report == null) return this.BadRequest();
|
||||
|
||||
SanitizationHelper.SanitizeStringsInClass(report);
|
||||
|
@ -41,14 +39,14 @@ public class ReportController : ControllerBase
|
|||
report.Bounds = JsonSerializer.Serialize(report.XmlBounds.Rect, typeof(Rectangle));
|
||||
report.Players = JsonSerializer.Serialize(report.XmlPlayers, typeof(ReportPlayer[]));
|
||||
report.Timestamp = TimeHelper.UnixTimeMilliseconds();
|
||||
report.ReportingPlayerId = user.UserId;
|
||||
report.ReportingPlayerId = token.UserId;
|
||||
|
||||
this.database.Reports.Add(report);
|
||||
await this.database.SaveChangesAsync();
|
||||
|
||||
await WebhookHelper.SendWebhook(
|
||||
title: "New grief report",
|
||||
description: $"Submitted by {user.Username}\n" +
|
||||
description: $"Submitted by {username}\n" +
|
||||
$"To view it, click [here]({ServerConfiguration.Instance.ExternalUrl}/moderation/report/{report.ReportId}).",
|
||||
dest: WebhookHelper.WebhookDestination.Moderation
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue