Add button and controller to remove user avatar (#1057)
Some checks failed
Upload Translations to Crowdin / crowdin-sync (push) Has been cancelled
Continuous Integration / Build & Test (map[database:true fullName:ubuntu-latest prettyName:Linux webTest:true]) (push) Has been cancelled
Build Docker Image / Build and Publish (push) Has been cancelled

* 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>
This commit is contained in:
FeTetra 2024-09-02 17:27:27 -04:00 committed by GitHub
parent 0af064ad1e
commit 917cccb3b0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 28 additions and 1 deletions

View file

@ -143,7 +143,29 @@ public class AdminUserController : ControllerBase
}
/// <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)

View file

@ -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">