mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-05 18:48:41 +00:00
refactor: organize dtos by domain; verification providers use verification context; move ip parsing into http context extensions chore: clean code
31 lines
971 B
C#
31 lines
971 B
C#
using SharpbinV3.Server.Services.Verification.Providers;
|
|
|
|
namespace SharpbinV3.Server.Services.Verification
|
|
{
|
|
public sealed class VerificationService(IEnumerable<IVerificationProvider> providers)
|
|
{
|
|
private readonly IReadOnlyList<IVerificationProvider> _providers = [.. providers];
|
|
|
|
private IVerificationProvider? GetActiveProvider()
|
|
{
|
|
return _providers
|
|
.Where(p => p.IsConfigured)
|
|
.OrderByDescending(p => p.Priority)
|
|
.FirstOrDefault();
|
|
}
|
|
|
|
public async Task<bool> VerifyAsync(VerificationContext context, IVerificationProvider? provider = null)
|
|
{
|
|
var activeProvider = provider ?? GetActiveProvider();
|
|
|
|
if (activeProvider is null)
|
|
return true;
|
|
|
|
if (string.IsNullOrWhiteSpace(context.Token))
|
|
return false;
|
|
|
|
return await activeProvider.VerifyAsync(context);
|
|
}
|
|
}
|
|
}
|