mirror of https://github.com/abpframework/abp.git
39 changed files with 1756 additions and 16 deletions
@ -0,0 +1,23 @@ |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
using Volo.Abp.Identity.EntityFrameworkCore; |
|||
|
|||
namespace Volo.Abp.Identity |
|||
{ |
|||
//TODO: Register for all repositories!
|
|||
public class EfCoreIdentityRoleRepository : EfCoreRepository<IdentityDbContext, IdentityRole>, IIdentityRoleRepository |
|||
{ |
|||
public EfCoreIdentityRoleRepository(IDbContextProvider<IdentityDbContext> dbContextProvider) |
|||
: base(dbContextProvider) |
|||
{ |
|||
} |
|||
|
|||
public Task<IdentityRole> FindByNormalizedNameAsync(string normalizedRoleName, CancellationToken cancellationToken) |
|||
{ |
|||
return DbSet.FirstOrDefaultAsync(r => r.NormalizedName == normalizedRoleName, cancellationToken); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,84 @@ |
|||
using System.Collections.Generic; |
|||
using System.Threading; |
|||
using System.Linq; |
|||
using System.Security.Claims; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
using Volo.Abp.Identity.EntityFrameworkCore; |
|||
|
|||
namespace Volo.Abp.Identity |
|||
{ |
|||
//TODO: Register for;
|
|||
//- IIdentityUserRepository
|
|||
//- IRepository<IdentityUser>
|
|||
//- IRepository<IdentityUser, string>
|
|||
//- IQueryableRepository<IdentityUser>
|
|||
//- IQueryableRepository<IdentityUser, string>
|
|||
public class EfCoreIdentityUserRepository : EfCoreRepository<IdentityDbContext, IdentityUser>, IIdentityUserRepository |
|||
{ |
|||
public EfCoreIdentityUserRepository(IDbContextProvider<IdentityDbContext> dbContextProvider) |
|||
: base(dbContextProvider) |
|||
{ |
|||
} |
|||
|
|||
public Task<IdentityUser> FindByNormalizedUserNameAsync(string normalizedUserName, CancellationToken cancellationToken) |
|||
{ |
|||
return DbSet.FirstOrDefaultAsync(u => u.NormalizedUserName == normalizedUserName, cancellationToken); |
|||
} |
|||
|
|||
public Task<List<string>> GetRoleNamesAsync(string userId) |
|||
{ |
|||
var query = from userRole in DbContext.UserRoles |
|||
join role in DbContext.Roles on userRole.RoleId equals role.Id |
|||
where userRole.UserId.Equals(userId) |
|||
select role.Name; |
|||
|
|||
return query.ToListAsync(); |
|||
} |
|||
|
|||
public async Task<IdentityUser> FindByLoginAsync(string loginProvider, string providerKey, CancellationToken cancellationToken) |
|||
{ |
|||
var userLogin = await DbContext.UserLogins.FindAsync(new object[] { loginProvider, providerKey }, cancellationToken); |
|||
if (userLogin == null) |
|||
{ |
|||
return null; |
|||
} |
|||
|
|||
return await DbSet.FindAsync(new object[] { userLogin.UserId }, cancellationToken); |
|||
} |
|||
|
|||
public Task<IdentityUser> FindByNormalizedEmailAsync(string normalizedEmail, CancellationToken cancellationToken) |
|||
{ |
|||
return DbSet.FirstOrDefaultAsync(u => u.NormalizedEmail == normalizedEmail, cancellationToken); |
|||
} |
|||
|
|||
public async Task<IList<IdentityUser>> GetListByClaimAsync(Claim claim, CancellationToken cancellationToken) |
|||
{ |
|||
var query = from userclaims in DbContext.UserClaims |
|||
join user in DbContext.Users on userclaims.UserId equals user.Id |
|||
where userclaims.ClaimValue == claim.Value && userclaims.ClaimType == claim.Type |
|||
select user; |
|||
|
|||
return await query.ToListAsync(cancellationToken); |
|||
} |
|||
|
|||
public async Task<IList<IdentityUser>> GetListByNormalizedRoleNameAsync(string normalizedRoleName, CancellationToken cancellationToken) |
|||
{ |
|||
var role = await DbContext.Roles.Where(x => x.NormalizedName == normalizedRoleName).FirstOrDefaultAsync(cancellationToken); |
|||
|
|||
if (role == null) |
|||
{ |
|||
return new List<IdentityUser>(); |
|||
} |
|||
|
|||
var query = from userrole in DbContext.UserRoles |
|||
join user in DbContext.Users on userrole.UserId equals user.Id |
|||
where userrole.RoleId.Equals(role.Id) |
|||
select user; |
|||
|
|||
return await query.ToListAsync(cancellationToken); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Domain.Repositories; |
|||
|
|||
namespace Volo.Abp.Identity |
|||
{ |
|||
public interface IIdentityRoleRepository : IRepository<IdentityRole> |
|||
{ |
|||
Task<IdentityRole> FindByNormalizedNameAsync(string normalizedRoleName, CancellationToken cancellationToken); |
|||
} |
|||
} |
|||
@ -0,0 +1,24 @@ |
|||
using System.Collections.Generic; |
|||
using System.Security.Claims; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using JetBrains.Annotations; |
|||
using Volo.Abp.Domain.Repositories; |
|||
|
|||
namespace Volo.Abp.Identity |
|||
{ |
|||
public interface IIdentityUserRepository : IRepository<IdentityUser> |
|||
{ |
|||
Task<IdentityUser> FindByNormalizedUserNameAsync([NotNull] string normalizedUserName, CancellationToken cancellationToken); |
|||
|
|||
Task<List<string>> GetRoleNamesAsync([NotNull] string userId); |
|||
|
|||
Task<IdentityUser> FindByLoginAsync([NotNull] string loginProvider, [NotNull] string providerKey, CancellationToken cancellationToken); |
|||
|
|||
Task<IdentityUser> FindByNormalizedEmailAsync([NotNull] string normalizedEmail, CancellationToken cancellationToken); |
|||
|
|||
Task<IList<IdentityUser>> GetListByClaimAsync(Claim claim, CancellationToken cancellationToken); |
|||
|
|||
Task<IList<IdentityUser>> GetListByNormalizedRoleNameAsync(string normalizedRoleName, CancellationToken cancellationToken); |
|||
} |
|||
} |
|||
File diff suppressed because it is too large
@ -0,0 +1,8 @@ |
|||
namespace Volo.Abp.Domain.Entities |
|||
{ |
|||
//TODO: Think a better naming?
|
|||
public interface IHasConcurrencyStamp |
|||
{ |
|||
string ConcurrencyStamp { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.Linq |
|||
{ |
|||
//TODO: DefaultAsyncQueryableExecuter should be able to work with multiple Executer, each will try to execute it!
|
|||
//TODO: Implement with EF Core as first executer implementation!
|
|||
public class DefaultAsyncQueryableExecuter : IAsyncQueryableExecuter, ITransientDependency |
|||
{ |
|||
public Task<int> CountAsync<T>(IQueryable<T> queryable) |
|||
{ |
|||
return Task.FromResult(queryable.Count()); |
|||
} |
|||
|
|||
public Task<List<T>> ToListAsync<T>(IQueryable<T> queryable) |
|||
{ |
|||
return Task.FromResult(queryable.ToList()); |
|||
} |
|||
|
|||
public Task<T> FirstOrDefaultAsync<T>(IQueryable<T> queryable) |
|||
{ |
|||
return Task.FromResult(queryable.FirstOrDefault()); |
|||
} |
|||
|
|||
public Task<T> FirstOrDefaultAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken) |
|||
{ |
|||
return Task.FromResult(queryable.FirstOrDefault()); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,21 @@ |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Volo.Abp.Linq |
|||
{ |
|||
/// <summary>
|
|||
/// This interface is intended to be used by ABP.
|
|||
/// </summary>
|
|||
public interface IAsyncQueryableExecuter |
|||
{ |
|||
Task<int> CountAsync<T>(IQueryable<T> queryable); |
|||
|
|||
Task<List<T>> ToListAsync<T>(IQueryable<T> queryable); |
|||
|
|||
Task<T> FirstOrDefaultAsync<T>(IQueryable<T> queryable); |
|||
|
|||
Task<T> FirstOrDefaultAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken); |
|||
} |
|||
} |
|||
@ -0,0 +1,36 @@ |
|||
using System; |
|||
|
|||
namespace Volo.Abp.Uow |
|||
{ |
|||
public class AbpDbConcurrencyException : AbpException |
|||
{ |
|||
/// <summary>
|
|||
/// Creates a new <see cref="AbpDbConcurrencyException"/> object.
|
|||
/// </summary>
|
|||
public AbpDbConcurrencyException() |
|||
{ |
|||
|
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Creates a new <see cref="AbpDbConcurrencyException"/> object.
|
|||
/// </summary>
|
|||
/// <param name="message">Exception message</param>
|
|||
public AbpDbConcurrencyException(string message) |
|||
: base(message) |
|||
{ |
|||
|
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Creates a new <see cref="AbpDbConcurrencyException"/> object.
|
|||
/// </summary>
|
|||
/// <param name="message">Exception message</param>
|
|||
/// <param name="innerException">Inner exception</param>
|
|||
public AbpDbConcurrencyException(string message, Exception innerException) |
|||
: base(message, innerException) |
|||
{ |
|||
|
|||
} |
|||
} |
|||
} |
|||
@ -1,9 +1,13 @@ |
|||
namespace Volo.Abp.Uow |
|||
using JetBrains.Annotations; |
|||
|
|||
namespace Volo.Abp.Uow |
|||
{ |
|||
public interface IUnitOfWorkManager |
|||
{ |
|||
[CanBeNull] |
|||
IUnitOfWork Current { get; } |
|||
|
|||
[NotNull] |
|||
IUnitOfWork Begin(); |
|||
} |
|||
} |
|||
@ -0,0 +1,19 @@ |
|||
using System.Reflection; |
|||
using System.Runtime.CompilerServices; |
|||
using System.Runtime.InteropServices; |
|||
|
|||
// General Information about an assembly is controlled through the following
|
|||
// set of attributes. Change these attribute values to modify the information
|
|||
// associated with an assembly.
|
|||
[assembly: AssemblyConfiguration("")] |
|||
[assembly: AssemblyCompany("")] |
|||
[assembly: AssemblyProduct("Volo.Abp.Identity.Tests")] |
|||
[assembly: AssemblyTrademark("")] |
|||
|
|||
// Setting ComVisible to false makes the types in this assembly not visible
|
|||
// to COM components. If you need to access a type in this assembly from
|
|||
// COM, set the ComVisible attribute to true on that type.
|
|||
[assembly: ComVisible(false)] |
|||
|
|||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
|||
[assembly: Guid("4ab91077-82dc-4335-9274-bce017bd9c8b")] |
|||
@ -0,0 +1,23 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|||
<PropertyGroup> |
|||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion> |
|||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> |
|||
</PropertyGroup> |
|||
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" /> |
|||
<PropertyGroup Label="Globals"> |
|||
<ProjectGuid>4ab91077-82dc-4335-9274-bce017bd9c8b</ProjectGuid> |
|||
<RootNamespace> |
|||
</RootNamespace> |
|||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath> |
|||
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath> |
|||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion> |
|||
</PropertyGroup> |
|||
<PropertyGroup> |
|||
<SchemaVersion>2.0</SchemaVersion> |
|||
</PropertyGroup> |
|||
<ItemGroup> |
|||
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" /> |
|||
</ItemGroup> |
|||
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" /> |
|||
</Project> |
|||
@ -0,0 +1,31 @@ |
|||
using System; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace Volo.Abp.Identity |
|||
{ |
|||
[DependsOn(typeof(AbpIdentityModule))] |
|||
public class AbpIdentityTestModule : AbpModule |
|||
{ |
|||
public override void ConfigureServices(IServiceCollection services) |
|||
{ |
|||
services.AddEntityFrameworkInMemoryDatabase(); |
|||
|
|||
services.Configure<DbConnectionOptions>(options => |
|||
{ |
|||
options.ConnectionStrings.Default = Guid.NewGuid().ToString(); |
|||
}); |
|||
|
|||
services.Configure<AbpDbContextOptions>(options => |
|||
{ |
|||
options.Configure(context => |
|||
{ |
|||
context.DbContextOptions.UseInMemoryDatabase(context.ConnectionString); |
|||
}); |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,15 @@ |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp.TestBase; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.Identity |
|||
{ |
|||
public class Initialize_Tests : AbpIntegratedTest<AbpIdentityTestModule> |
|||
{ |
|||
[Fact] |
|||
public void Should_Initialize_Identity_Module() |
|||
{ |
|||
var userManager = ServiceProvider.GetRequiredService<IdentityUserManager>(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,23 @@ |
|||
{ |
|||
"version": "1.0.0-*", |
|||
|
|||
"testRunner": "xunit", |
|||
|
|||
"dependencies": { |
|||
"AbpTestBase": "1.0.0-*", |
|||
"Microsoft.EntityFrameworkCore.InMemory": "1.1.0", |
|||
"Volo.Abp.Identity": "1.0.0-*", |
|||
"Volo.Abp.Identity.EntityFrameworkCore": "1.0.0-*" |
|||
}, |
|||
|
|||
"frameworks": { |
|||
"netcoreapp1.1": { |
|||
"dependencies": { |
|||
"Microsoft.NETCore.App": { |
|||
"type": "platform", |
|||
"version": "1.1.0" |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue