mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-30 00:38:38 +00:00
Move servers to LBPU.PL.Servers
This commit is contained in:
parent
545b5a0709
commit
b2ec7eae57
116 changed files with 173 additions and 162 deletions
|
@ -0,0 +1,16 @@
|
|||
#nullable enable
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Servers.Website.Controllers.Admin;
|
||||
|
||||
[ApiController]
|
||||
[Route("/admin")]
|
||||
public class AdminPanelController : ControllerBase
|
||||
{
|
||||
private readonly Database database;
|
||||
|
||||
public AdminPanelController(Database database)
|
||||
{
|
||||
this.database = database;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
#nullable enable
|
||||
using LBPUnion.ProjectLighthouse.Types;
|
||||
using LBPUnion.ProjectLighthouse.Types.Reports;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Servers.Website.Controllers.Admin;
|
||||
|
||||
[ApiController]
|
||||
[Route("admin/report/{id:int}")]
|
||||
public class AdminReportController : ControllerBase
|
||||
{
|
||||
private readonly Database database;
|
||||
|
||||
public AdminReportController(Database database)
|
||||
{
|
||||
this.database = database;
|
||||
}
|
||||
|
||||
[HttpGet("remove")]
|
||||
public async Task<IActionResult> DeleteReport([FromRoute] int id)
|
||||
{
|
||||
User? user = this.database.UserFromWebRequest(this.Request);
|
||||
if (user == null || !user.IsAdmin) return this.StatusCode(403, "");
|
||||
|
||||
GriefReport? report = await this.database.Reports.FirstOrDefaultAsync(r => r.ReportId == id);
|
||||
if (report == null) return this.NotFound();
|
||||
|
||||
List<string> hashes = new()
|
||||
{
|
||||
report.JpegHash,
|
||||
report.GriefStateHash,
|
||||
report.InitialStateHash,
|
||||
};
|
||||
foreach (string hash in hashes)
|
||||
{
|
||||
if (System.IO.File.Exists(Path.Combine("png", $"{hash}.png")))
|
||||
{
|
||||
System.IO.File.Delete(Path.Combine("png", $"{hash}.png"));
|
||||
}
|
||||
if (System.IO.File.Exists(Path.Combine("r", hash)))
|
||||
{
|
||||
System.IO.File.Delete(Path.Combine("r", hash));
|
||||
}
|
||||
}
|
||||
this.database.Reports.Remove(report);
|
||||
|
||||
await this.database.SaveChangesAsync();
|
||||
|
||||
return this.Redirect("~/admin/reports/0");
|
||||
}
|
||||
|
||||
[HttpGet("dismiss")]
|
||||
public async Task<IActionResult> DismissReport([FromRoute] int id)
|
||||
{
|
||||
User? user = this.database.UserFromWebRequest(this.Request);
|
||||
if (user == null || !user.IsAdmin) return this.StatusCode(403, "");
|
||||
|
||||
GriefReport? report = await this.database.Reports.FirstOrDefaultAsync(r => r.ReportId == id);
|
||||
if (report == null) return this.NotFound();
|
||||
|
||||
if (System.IO.File.Exists(Path.Combine("png", $"{report.JpegHash}.png")))
|
||||
{
|
||||
System.IO.File.Delete(Path.Combine("png", $"{report.JpegHash}.png"));
|
||||
}
|
||||
if (System.IO.File.Exists(Path.Combine("r", report.JpegHash)))
|
||||
{
|
||||
System.IO.File.Delete(Path.Combine("r", report.JpegHash));
|
||||
}
|
||||
|
||||
this.database.Reports.Remove(report);
|
||||
|
||||
await this.database.SaveChangesAsync();
|
||||
|
||||
return this.Redirect("~/admin/reports/0");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
#nullable enable
|
||||
using LBPUnion.ProjectLighthouse.Types;
|
||||
using LBPUnion.ProjectLighthouse.Types.Levels;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Servers.Website.Controllers.Admin;
|
||||
|
||||
[ApiController]
|
||||
[Route("admin/slot/{id:int}")]
|
||||
public class AdminSlotController : ControllerBase
|
||||
{
|
||||
private readonly Database database;
|
||||
|
||||
public AdminSlotController(Database database)
|
||||
{
|
||||
this.database = database;
|
||||
}
|
||||
|
||||
[HttpGet("teamPick")]
|
||||
public async Task<IActionResult> TeamPick([FromRoute] int id)
|
||||
{
|
||||
User? user = this.database.UserFromWebRequest(this.Request);
|
||||
if (user == null || !user.IsAdmin) return this.StatusCode(403, "");
|
||||
|
||||
Slot? slot = await this.database.Slots.FirstOrDefaultAsync(s => s.SlotId == id);
|
||||
if (slot == null) return this.NotFound();
|
||||
|
||||
slot.TeamPick = true;
|
||||
|
||||
await this.database.SaveChangesAsync();
|
||||
|
||||
return this.Ok();
|
||||
}
|
||||
|
||||
[HttpGet("removeTeamPick")]
|
||||
public async Task<IActionResult> RemoveTeamPick([FromRoute] int id)
|
||||
{
|
||||
User? user = this.database.UserFromWebRequest(this.Request);
|
||||
if (user == null || !user.IsAdmin) return this.StatusCode(403, "");
|
||||
|
||||
Slot? slot = await this.database.Slots.FirstOrDefaultAsync(s => s.SlotId == id);
|
||||
if (slot == null) return this.NotFound();
|
||||
|
||||
slot.TeamPick = false;
|
||||
|
||||
await this.database.SaveChangesAsync();
|
||||
|
||||
return this.Ok();
|
||||
}
|
||||
|
||||
[HttpGet("delete")]
|
||||
public async Task<IActionResult> DeleteLevel([FromRoute] int id)
|
||||
{
|
||||
User? user = this.database.UserFromWebRequest(this.Request);
|
||||
if (user == null || !user.IsAdmin) return this.StatusCode(403, "");
|
||||
|
||||
Slot? slot = await this.database.Slots.FirstOrDefaultAsync(s => s.SlotId == id);
|
||||
if (slot == null) return this.Ok();
|
||||
|
||||
await this.database.RemoveSlot(slot);
|
||||
|
||||
return this.Ok();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
#nullable enable
|
||||
using LBPUnion.ProjectLighthouse.Types;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Servers.Website.Controllers.Admin;
|
||||
|
||||
[ApiController]
|
||||
[Route("admin/user/{id:int}")]
|
||||
public class AdminUserController : ControllerBase
|
||||
{
|
||||
private readonly Database database;
|
||||
|
||||
public AdminUserController(Database database)
|
||||
{
|
||||
this.database = database;
|
||||
}
|
||||
|
||||
[HttpGet("unban")]
|
||||
public async Task<IActionResult> UnbanUser([FromRoute] int id)
|
||||
{
|
||||
User? user = this.database.UserFromWebRequest(this.Request);
|
||||
if (user == null || !user.IsAdmin) return this.NotFound();
|
||||
|
||||
User? targetedUser = await this.database.Users.FirstOrDefaultAsync(u => u.UserId == id);
|
||||
|
||||
if (targetedUser == null) return this.NotFound();
|
||||
|
||||
targetedUser.Banned = false;
|
||||
targetedUser.BannedReason = null;
|
||||
|
||||
await this.database.SaveChangesAsync();
|
||||
return this.Redirect($"/user/{targetedUser.UserId}");
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue