mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-04-19 19:14:51 +00:00
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:
parent
262ada37ae
commit
643cb8e816
2 changed files with 34 additions and 0 deletions
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Add table
Reference in a new issue