Skip to content

Commit

Permalink
Add button and controller to remove user avatar (#1057)
Browse files Browse the repository at this point in the history
* Add button and controller to remove user avatar

* Update ProjectLighthouse.Servers.Website/Controllers/Admin/AdminUserController.cs

Suggestion provided to add logging, a return, and sending a notification to the affected user

Co-authored-by: Josh <josh@slendy.pw>

* Update ProjectLighthouse.Servers.Website/Controllers/Admin/AdminUserController.cs

Co-authored-by: Josh <josh@slendy.pw>

---------

Co-authored-by: Josh <josh@slendy.pw>
  • Loading branch information
FeTetra and Slendy authored Sep 2, 2024
1 parent 0af064a commit 917cccb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,29 @@ public async Task<IActionResult> WipeScores([FromRoute] int id)
}

/// <summary>
/// Forces the email verification of a user.
/// Deletes the user's current avatar. Can prevent crashes in-game, or just be used to remove images that break guidelines.
/// </summary>
[HttpGet("wipeAvatar")]
public async Task<IActionResult> WipeAvatar([FromRoute] int id)
{
UserEntity? user = this.database.UserFromWebRequest(this.Request);
if (user == null || !user.IsModerator) return this.NotFound();

UserEntity? targetedUser = await this.database.Users.FirstOrDefaultAsync(u => u.UserId == id);
if (targetedUser == null) return this.NotFound();

targetedUser.IconHash = "";

await this.database.SaveChangesAsync();
Logger.Success($"Reset profile picture for {targetedUser.Username} (id:{targetedUser.UserId})", LogArea.Admin);

await this.database.SendNotification(targetedUser.UserId, "Your profile picture has been reset by a moderator.");

return this.Redirect($"/user/{targetedUser.UserId}");
}

/// <summary>
/// Forces the email verification of a user.
/// </summary>
[HttpGet("forceVerifyEmail")]
public async Task<IActionResult> ForceVerifyEmail([FromRoute] int id)
Expand Down
5 changes: 5 additions & 0 deletions ProjectLighthouse.Servers.Website/Pages/UserPage.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,11 @@ else
<span>Wipe User&apos;s Scores</span>
</a>

<a class="ui yellow button" href="/moderation/user/@Model.ProfileUser.UserId/wipeAvatar">
<i class="trash alternate icon"></i>
<span>Remove User Avatar</span>
</a>

@if (!Model.CommentsDisabledByModerator)
{
<a class="ui yellow button" href="/moderation/newCase?type=@((int)CaseType.UserDisableComments)&affectedId=@Model.ProfileUser.UserId">
Expand Down

0 comments on commit 917cccb

Please sign in to comment.