mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 14:34:23 +01:00
Admins can approve registered users (#5647)
* Users list: Cleanups * Policies: Flip registration settings * Policies: Add RequireUserApproval setting * Add approval to user * Require approval on login and for API key * API handling * AccountController cleanups * Test fix * Apply suggestions from code review Co-authored-by: Nicolas Dorier <nicolas.dorier@gmail.com> * Add missing imports * Communicate login requirements to user on account creation * Add login requirements to basic auth handler * Cleanups and test fix * Encapsulate approval logic in user service and log approval changes * Send follow up "Account approved" email Closes #5656. * Add notification for admins * Fix creating a user via the admin view * Update list: Unify flags into status column, add approve action * Adjust "Resend email" wording * Incorporate feedback from code review * Remove duplicate test server policy reset --------- Co-authored-by: Nicolas Dorier <nicolas.dorier@gmail.com>
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
using BTCPayServer.Abstractions.Contracts;
|
||||
using BTCPayServer.Configuration;
|
||||
using BTCPayServer.Controllers;
|
||||
using BTCPayServer.Data;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
|
||||
namespace BTCPayServer.Services.Notifications.Blobs;
|
||||
|
||||
internal class NewUserRequiresApprovalNotification : BaseNotification
|
||||
{
|
||||
private const string TYPE = "newuserrequiresapproval";
|
||||
public string UserId { get; set; }
|
||||
public string UserEmail { get; set; }
|
||||
public override string Identifier => TYPE;
|
||||
public override string NotificationType => TYPE;
|
||||
|
||||
public NewUserRequiresApprovalNotification()
|
||||
{
|
||||
}
|
||||
|
||||
public NewUserRequiresApprovalNotification(ApplicationUser user)
|
||||
{
|
||||
UserId = user.Id;
|
||||
UserEmail = user.Email;
|
||||
}
|
||||
|
||||
internal class Handler : NotificationHandler<NewUserRequiresApprovalNotification>
|
||||
{
|
||||
private readonly LinkGenerator _linkGenerator;
|
||||
private readonly BTCPayServerOptions _options;
|
||||
|
||||
public Handler(LinkGenerator linkGenerator, BTCPayServerOptions options)
|
||||
{
|
||||
_linkGenerator = linkGenerator;
|
||||
_options = options;
|
||||
}
|
||||
|
||||
public override string NotificationType => TYPE;
|
||||
public override (string identifier, string name)[] Meta
|
||||
{
|
||||
get
|
||||
{
|
||||
return [(TYPE, "New user requires approval")];
|
||||
}
|
||||
}
|
||||
|
||||
protected override void FillViewModel(NewUserRequiresApprovalNotification notification, NotificationViewModel vm)
|
||||
{
|
||||
vm.Identifier = notification.Identifier;
|
||||
vm.Type = notification.NotificationType;
|
||||
vm.Body = $"New user {notification.UserEmail} requires approval.";
|
||||
vm.ActionLink = _linkGenerator.GetPathByAction(nameof(UIServerController.User),
|
||||
"UIServer",
|
||||
new { userId = notification.UserId }, _options.RootPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user