2022-12-09 12:09:04 +01:00
|
|
|
using Microsoft.AspNetCore.Identity;
|
2026-04-07 14:23:29 +02:00
|
|
|
using Finch.Identity;
|
2022-12-09 12:09:04 +01:00
|
|
|
|
2026-04-07 14:23:29 +02:00
|
|
|
namespace Finch.Identity;
|
2022-12-09 12:09:04 +01:00
|
|
|
|
2026-04-07 14:23:29 +02:00
|
|
|
public partial class FinchUserStore<TUser, TRole> : FinchUserStore<TUser>,
|
2022-12-09 12:09:04 +01:00
|
|
|
IUserRoleStore<TUser>
|
2026-04-07 14:23:29 +02:00
|
|
|
where TUser : FinchIdentityUser, new()
|
|
|
|
|
where TRole : FinchIdentityRole, new()
|
2022-12-09 12:09:04 +01:00
|
|
|
{
|
2026-04-07 14:23:29 +02:00
|
|
|
public FinchUserStore(IFinchIdentityStoreDbProvider db) : base(db) { }
|
2022-12-09 12:09:04 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public Task AddToRoleAsync(TUser user, string roleName, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
user.RoleIds.Add(roleName);
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public Task<IList<string>> GetRolesAsync(TUser user, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
return Task.FromResult((IList<string>)user.RoleIds.ToList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public async Task<IList<TUser>> GetUsersInRoleAsync(string roleName, CancellationToken cancellationToken)
|
|
|
|
|
{
|
2022-12-14 16:25:14 +01:00
|
|
|
return await Db.FindAll<TUser>(x => !x.IsDeleted && x.RoleIds.Contains(roleName), cancellationToken);
|
2022-12-09 12:09:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public Task<bool> IsInRoleAsync(TUser user, string roleName, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
return Task.FromResult(user.RoleIds.Contains(roleName, StringComparer.InvariantCultureIgnoreCase));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public Task RemoveFromRoleAsync(TUser user, string roleName, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
user.RoleIds.Remove(roleName);
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
}
|
|
|
|
|
}
|