Implement the ability to forcibly verify a user's email (#1022)

* Implement the ability to forcibly verify a user's email

* Apply suggestions from code review
This commit is contained in:
sudokoko 2024-05-31 18:10:05 -04:00 committed by GitHub
parent 262ada37ae
commit 643cb8e816
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 34 additions and 0 deletions

View file

@ -3,6 +3,7 @@ using LBPUnion.ProjectLighthouse.Database;
using LBPUnion.ProjectLighthouse.Files;
using LBPUnion.ProjectLighthouse.Logging;
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
using LBPUnion.ProjectLighthouse.Types.Entities.Token;
using LBPUnion.ProjectLighthouse.Types.Logging;
using LBPUnion.ProjectLighthouse.Types.Moderation.Cases;
using LBPUnion.ProjectLighthouse.Types.Users;
@ -91,6 +92,31 @@ public class AdminUserController : ControllerBase
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)
{
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();
if (user.EmailAddressVerified) return this.NotFound();
List<EmailVerificationTokenEntity> tokens = await this.database.EmailVerificationTokens
.Where(t => t.UserId == targetedUser.UserId)
.ToListAsync();
this.database.EmailVerificationTokens.RemoveRange(tokens);
targetedUser.EmailAddressVerified = true;
await this.database.SaveChangesAsync();
return this.Redirect($"/user/{targetedUser.UserId}");
}
[HttpPost("/admin/user/{id:int}/setPermissionLevel")]
public async Task<IActionResult> SetUserPermissionLevel([FromRoute] int id, [FromForm] PermissionLevel role)
{

View file

@ -333,6 +333,14 @@ else
</a>
}
@if (!Model.ProfileUser.EmailAddressVerified)
{
<a class="ui green button" href="/moderation/user/@Model.ProfileUser.UserId/forceVerifyEmail">
<i class="check icon"></i>
<span>Force Verify Email</span>
</a>
}
@if (Model.User.IsAdmin)
{
<div class="ui divider"></div>