mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 14:34:23 +01:00
[Greenfield] Allow passing email instead of user id in API (#4732)
This commit is contained in:
19
BTCPayServer/UserManagerExtensions.cs
Normal file
19
BTCPayServer/UserManagerExtensions.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
#nullable enable
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
|
||||
namespace BTCPayServer
|
||||
{
|
||||
public static class UserManagerExtensions
|
||||
{
|
||||
public async static Task<TUser?> FindByIdOrEmail<TUser>(this UserManager<TUser> userManager, string? idOrEmail) where TUser : class
|
||||
{
|
||||
if (string.IsNullOrEmpty(idOrEmail))
|
||||
return null;
|
||||
if (idOrEmail.Contains('@'))
|
||||
return await userManager.FindByEmailAsync(idOrEmail);
|
||||
else
|
||||
return await userManager.FindByIdAsync(idOrEmail);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user