mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-08-17 07:50:20 +00:00
Add case generator for bans, allow mods to ban
This commit is contained in:
parent
1eede416d4
commit
cdcc03fdc1
8 changed files with 85 additions and 47 deletions
|
@ -24,7 +24,7 @@ public class AdminUserController : ControllerBase
|
|||
public async Task<IActionResult> UnbanUser([FromRoute] int id)
|
||||
{
|
||||
User? user = this.database.UserFromWebRequest(this.Request);
|
||||
if (user == null || !user.IsAdmin) return this.NotFound();
|
||||
if (user == null || !user.IsModerator) return this.NotFound();
|
||||
|
||||
User? targetedUser = await this.database.Users.FirstOrDefaultAsync(u => u.UserId == id);
|
||||
if (targetedUser == null) return this.NotFound();
|
||||
|
@ -42,7 +42,7 @@ public class AdminUserController : ControllerBase
|
|||
[HttpGet("wipePlanets")]
|
||||
public async Task<IActionResult> WipePlanets([FromRoute] int id) {
|
||||
User? user = this.database.UserFromWebRequest(this.Request);
|
||||
if (user == null || !user.IsAdmin) return this.NotFound();
|
||||
if (user == null || !user.IsModerator) return this.NotFound();
|
||||
|
||||
User? targetedUser = await this.database.Users.FirstOrDefaultAsync(u => u.UserId == id);
|
||||
if (targetedUser == null) return this.NotFound();
|
||||
|
@ -118,7 +118,7 @@ public class AdminUserController : ControllerBase
|
|||
}
|
||||
else
|
||||
{
|
||||
return this.Redirect($"/admin/user/{id}/ban");
|
||||
return this.Redirect($"/moderation/user/{id}/ban");
|
||||
}
|
||||
|
||||
return this.Redirect("/admin/users");
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
@page "/admin/user/{id:int}/ban"
|
||||
@model LBPUnion.ProjectLighthouse.Servers.Website.Pages.Admin.AdminBanUserPage
|
||||
|
||||
@{
|
||||
Layout = "Layouts/BaseLayout";
|
||||
Model.Title = "Ban " + Model.TargetedUser!.Username + "?";
|
||||
}
|
||||
|
||||
<p>Are you sure you want to ban this user?</p>
|
||||
|
||||
<form method="post">
|
||||
@Html.AntiForgeryToken()
|
||||
|
||||
<div class="ui left labeled input">
|
||||
<label for="text" class="ui blue label">Reason: </label>
|
||||
<input type="text" name="reason" id="text">
|
||||
</div><br><br>
|
||||
|
||||
<input type="submit" value="Yes, ban @Model.TargetedUser.Username!" id="submit" class="ui red button"><br>
|
||||
</form>
|
|
@ -0,0 +1,25 @@
|
|||
@page "/moderation/user/{id:int}/ban"
|
||||
@model LBPUnion.ProjectLighthouse.Servers.Website.Pages.Admin.ModeratorBanUserPage
|
||||
|
||||
@{
|
||||
Layout = "Layouts/BaseLayout";
|
||||
Model.Title = "Ban " + Model.TargetedUser!.Username + "?";
|
||||
}
|
||||
|
||||
<p>Are you sure you want to ban this user?</p>
|
||||
|
||||
<form method="post">
|
||||
@Html.AntiForgeryToken()
|
||||
|
||||
<div class="ui left labeled input">
|
||||
<label for="text" class="ui blue label">Reason: </label>
|
||||
<input type="text" name="reason" id="text">
|
||||
</div><br>
|
||||
|
||||
<div class="ui left labeled input">
|
||||
<label for="caseExpires" class="ui blue label">Expires on: </label>
|
||||
<input type="datetime-local" name="caseExpires" id="caseExpires">
|
||||
</div><br>
|
||||
|
||||
<br><input type="submit" value="Yes, ban @Model.TargetedUser.Username!" id="submit" class="ui red button"><br>
|
||||
</form>
|
|
@ -8,17 +8,17 @@ using Microsoft.EntityFrameworkCore;
|
|||
|
||||
namespace LBPUnion.ProjectLighthouse.Servers.Website.Pages.Admin;
|
||||
|
||||
public class AdminBanUserPage : BaseLayout
|
||||
public class ModeratorBanUserPage : BaseLayout
|
||||
{
|
||||
|
||||
public User? TargetedUser;
|
||||
public AdminBanUserPage(Database database) : base(database)
|
||||
public ModeratorBanUserPage(Database database) : base(database)
|
||||
{}
|
||||
|
||||
public async Task<IActionResult> OnGet([FromRoute] int id)
|
||||
{
|
||||
User? user = this.Database.UserFromWebRequest(this.Request);
|
||||
if (user == null || !user.IsAdmin) return this.NotFound();
|
||||
if (user == null || !user.IsModerator) return this.NotFound();
|
||||
|
||||
this.TargetedUser = await this.Database.Users.FirstOrDefaultAsync(u => u.UserId == id);
|
||||
if (this.TargetedUser == null) return this.NotFound();
|
||||
|
@ -26,10 +26,10 @@ public class AdminBanUserPage : BaseLayout
|
|||
return this.Page();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPost([FromRoute] int id, string reason)
|
||||
public async Task<IActionResult> OnPost([FromRoute] int id, string reason, DateTime caseExpires)
|
||||
{
|
||||
User? user = this.Database.UserFromWebRequest(this.Request);
|
||||
if (user == null || !user.IsAdmin) return this.NotFound();
|
||||
if (user == null || !user.IsModerator) return this.NotFound();
|
||||
|
||||
this.TargetedUser = await this.Database.Users.FirstOrDefaultAsync(u => u.UserId == id);
|
||||
if (this.TargetedUser == null) return this.NotFound();
|
||||
|
@ -42,6 +42,9 @@ public class AdminBanUserPage : BaseLayout
|
|||
|
||||
// invalidate all currently active webtokens
|
||||
this.Database.WebTokens.RemoveRange(this.Database.WebTokens.Where(t => t.UserId == this.TargetedUser.UserId));
|
||||
|
||||
// generate & add moderation case
|
||||
this.Database.Add(ModerationCase.NewBanCase(user.UserId, this.TargetedUser.UserId, reason, caseExpires));
|
||||
|
||||
await this.Database.SaveChangesAsync();
|
||||
return this.Redirect($"/user/{this.TargetedUser.UserId}");
|
|
@ -126,7 +126,7 @@
|
|||
@if (!Model.ProfileUser.IsBanned)
|
||||
{
|
||||
<div>
|
||||
<a class="ui red button" href="/admin/user/@Model.ProfileUser.UserId/ban">
|
||||
<a class="ui red button" href="/moderation/user/@Model.ProfileUser.UserId/ban">
|
||||
<i class="ban icon"></i>
|
||||
<span>Ban User</span>
|
||||
</a>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue