Skip to content

Commit

Permalink
Stores now not abstract
Browse files Browse the repository at this point in the history
version 1.2.0
  • Loading branch information
ili committed Jul 6, 2017
1 parent 66373fb commit 805064e
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 27 deletions.
5 changes: 3 additions & 2 deletions src/LinqToDB.Identity/LinqToDB.Identity.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@
<PackageId>linq2db.Identity</PackageId>
<PackageTags>aspnetcore;linq2db;identity;membership;LinqToDB</PackageTags>
<PackageIconUrl>http://www.gravatar.com/avatar/fc2e509b6ed116b9aa29a7988fdb8990?s=320</PackageIconUrl>
<PackageProjectUrl>https://github.com/ili/LinqToDB.Identity</PackageProjectUrl>
<PackageProjectUrl>https://github.com/linq2db/LinqToDB.Identity</PackageProjectUrl>
<PackageLicenseUrl>https://opensource.org/licenses/MIT</PackageLicenseUrl>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>git://github.com/ili/LinqToDB.Identity</RepositoryUrl>
<RepositoryUrl>git://github.com/linq2db/LinqToDB.Identity</RepositoryUrl>
<NetStandardImplicitPackageVersion>1.6.1</NetStandardImplicitPackageVersion>
<GenerateNeutralResourcesLanguageAttribute>false</GenerateNeutralResourcesLanguageAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<Version>1.2.0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/LinqToDB.Identity/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
[assembly: AssemblyMetadata("Serviceable", "True")]
[assembly: NeutralResourcesLanguage("en-us")]
[assembly: AssemblyCompany("blog.linq2db.com")]
[assembly: AssemblyCopyright("\xA9 2011-2016 blog.linq2db.com")]
[assembly: AssemblyCopyright("© 2011-2017 blog.linq2db.com")]
[assembly: AssemblyProduct("Linq to DB")]
23 changes: 8 additions & 15 deletions src/LinqToDB.Identity/RoleStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,6 @@ public RoleStore(IConnectionFactory factory, IdentityErrorDescriber describer =
{
}

/// <summary>
/// Creates a entity representing a role claim.
/// </summary>
/// <param name="role">The associated role.</param>
/// <param name="claim">The associated claim.</param>
/// <returns>The role claim entity.</returns>
protected override IdentityRoleClaim<TKey> CreateRoleClaim(TRole role, Claim claim)
{
var roleClaim = new IdentityRoleClaim<TKey> {RoleId = role.Id};
roleClaim.InitializeFromClaim(claim);
return roleClaim;
}
}

/// <summary>
Expand All @@ -75,12 +63,12 @@ protected override IdentityRoleClaim<TKey> CreateRoleClaim(TRole role, Claim cla
/// <typeparam name="TRole">The type of the class representing a role.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a role.</typeparam>
/// <typeparam name="TRoleClaim">The type of the class representing a role claim.</typeparam>
public abstract class RoleStore<TKey, TRole, TRoleClaim> :
public class RoleStore<TKey, TRole, TRoleClaim> :
IQueryableRoleStore<TRole>,
IRoleClaimStore<TRole>
where TRole : class, IIdentityRole<TKey>
where TKey : IEquatable<TKey>
where TRoleClaim : class, IIdentityRoleClaim<TKey>
where TRoleClaim : class, IIdentityRoleClaim<TKey>, new()
{
private readonly IConnectionFactory _factory;

Expand Down Expand Up @@ -509,6 +497,11 @@ protected void ThrowIfDisposed()
/// <param name="role">The associated role.</param>
/// <param name="claim">The associated claim.</param>
/// <returns>The role claim entity.</returns>
protected abstract TRoleClaim CreateRoleClaim(TRole role, Claim claim);
protected virtual TRoleClaim CreateRoleClaim(TRole role, Claim claim)
{
var roleClaim = new TRoleClaim(){ RoleId = role.Id };
roleClaim.InitializeFromClaim(claim);
return roleClaim;
}
}
}
48 changes: 39 additions & 9 deletions src/LinqToDB.Identity/UserStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ protected override IdentityUserToken<TKey> CreateUserToken(TUser user, string lo
/// <typeparam name="TUserRole">The type representing a user role.</typeparam>
/// <typeparam name="TUserLogin">The type representing a user external login.</typeparam>
/// <typeparam name="TUserToken">The type representing a user token.</typeparam>
public abstract class UserStore<TKey, TUser, TRole, TUserClaim, TUserRole, TUserLogin, TUserToken> :
public class UserStore<TKey, TUser, TRole, TUserClaim, TUserRole, TUserLogin, TUserToken> :
IUserLoginStore<TUser>,
IUserRoleStore<TUser>,
IUserClaimStore<TUser>,
Expand All @@ -174,10 +174,10 @@ public abstract class UserStore<TKey, TUser, TRole, TUserClaim, TUserRole, TUser
IUserAuthenticationTokenStore<TUser>
where TUser : class, IIdentityUser<TKey>
where TRole : class, IIdentityRole<TKey>
where TUserClaim : class, IIdentityUserClaim<TKey>
where TUserRole : class, IIdentityUserRole<TKey>
where TUserLogin : class, IIdentityUserLogin<TKey>
where TUserToken : class, IIdentityUserToken<TKey>
where TUserClaim : class, IIdentityUserClaim<TKey>, new()
where TUserRole : class, IIdentityUserRole<TKey>, new()
where TUserLogin : class, IIdentityUserLogin<TKey>, new()
where TUserToken : class, IIdentityUserToken<TKey>, new ()
where TKey : IEquatable<TKey>
{
private readonly IConnectionFactory _factory;
Expand Down Expand Up @@ -1754,23 +1754,44 @@ public virtual Task<bool> GetTwoFactorEnabledAsync(TUser user,
/// <param name="user"></param>
/// <param name="role"></param>
/// <returns></returns>
protected abstract TUserRole CreateUserRole(TUser user, TRole role);
protected virtual TUserRole CreateUserRole(TUser user, TRole role)
{
return new TUserRole()
{
UserId = user.Id,
RoleId = role.Id
};
}

/// <summary>
/// Create a new entity representing a user claim.
/// </summary>
/// <param name="user"></param>
/// <param name="claim"></param>
/// <returns></returns>
protected abstract TUserClaim CreateUserClaim(TUser user, Claim claim);
protected virtual TUserClaim CreateUserClaim(TUser user, Claim claim)
{
var res = new TUserClaim() {UserId = user.Id};
res.InitializeFromClaim(claim);
return res;
}

/// <summary>
/// Create a new entity representing a user login.
/// </summary>
/// <param name="user"></param>
/// <param name="login"></param>
/// <returns></returns>
protected abstract TUserLogin CreateUserLogin(TUser user, UserLoginInfo login);
protected virtual TUserLogin CreateUserLogin(TUser user, UserLoginInfo login)
{
return new TUserLogin()
{
UserId = user.Id,
LoginProvider = login.LoginProvider,
ProviderDisplayName = login.ProviderDisplayName,
ProviderKey = login.ProviderKey
};
}

/// <summary>
/// Create a new entity representing a user token.
Expand All @@ -1780,7 +1801,16 @@ public virtual Task<bool> GetTwoFactorEnabledAsync(TUser user,
/// <param name="name"></param>
/// <param name="value"></param>
/// <returns></returns>
protected abstract TUserToken CreateUserToken(TUser user, string loginProvider, string name, string value);
protected virtual TUserToken CreateUserToken(TUser user, string loginProvider, string name, string value)
{
return new TUserToken()
{
UserId = user.Id,
LoginProvider = loginProvider,
Name = name,
Value = value
};
}

/// <summary>
/// Converts the provided <paramref name="id" /> to a strongly typed key object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ public void AddLinqToDBStores0()
services
.AddIdentity<IdentityUser, IdentityRole>()
.AddLinqToDBStores(new DefaultConnectionFactory());

var sp = services.BuildServiceProvider();

Assert.NotNull(sp.GetService<IUserStore<IdentityUser>>());
Assert.NotNull(sp.GetService<IRoleStore<IdentityRole>>());
}

[Fact]
Expand All @@ -23,6 +28,11 @@ public void AddLinqToDBStores1()
services
.AddIdentity<IdentityUser<long>, IdentityRole<long>>()
.AddLinqToDBStores<long>(new DefaultConnectionFactory());

var sp = services.BuildServiceProvider();

Assert.NotNull(sp.GetService<IUserStore<IdentityUser<long>>>());
Assert.NotNull(sp.GetService<IRoleStore<IdentityRole<long>>>());
}

[Fact]
Expand All @@ -38,6 +48,11 @@ public void AddLinqToDBStores6()
IdentityUserLogin<decimal>,
IdentityUserToken<decimal>,
IdentityRoleClaim<decimal>>(new DefaultConnectionFactory());

var sp = services.BuildServiceProvider();

Assert.NotNull(sp.GetService<IUserStore<IdentityUser<decimal>>>());
Assert.NotNull(sp.GetService<IRoleStore<IdentityRole<decimal>>>());
}

}
Expand Down

0 comments on commit 805064e

Please sign in to comment.