added mongodb mvc sample
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
<package >
|
||||
<metadata>
|
||||
<id>AspNetCore.Identity.MongoDbCore</id>
|
||||
<version>1.0.5</version>
|
||||
<version>1.0.6</version>
|
||||
<title>AspNetCore.Identity.MongoDbCore</title>
|
||||
<authors>Alexandre Spieser</authors>
|
||||
<owners>Alexandre Spieser</owners>
|
||||
@@ -13,6 +13,12 @@
|
||||
<releaseNotes>Added .AddMongoDbStores IdentityBuilder extensions.</releaseNotes>
|
||||
<copyright>Copyright 2017 (c) Alexandre Spieser. All rights reserved.</copyright>
|
||||
<tags>aspnetcore mongo mongodb identity membership</tags>
|
||||
<dependencies>
|
||||
<dependency id="Microsoft.AspNetCore.Identity" version="2.0.0" />
|
||||
<dependency id="Microsoft.Extensions.Identity.Stores" version="2.0.0" />
|
||||
<dependency id="MongoDB.Driver" version="2.4.4" />
|
||||
<dependency id="MongoDbGenericRepository" version="1.3.0" />
|
||||
</dependencies>
|
||||
</metadata>
|
||||
<files>
|
||||
<file src="lib\**" target="lib" />
|
||||
|
||||
@@ -91,12 +91,12 @@ namespace Microsoft.Extensions.DependencyInjection
|
||||
|
||||
builder.Services.TryAddSingleton<IMongoDbContext>(mongoDbContext);
|
||||
builder.Services.TryAddSingleton<IMongoRepository>(new MongoRepository(mongoDbContext));
|
||||
builder.Services.TryAddScoped<IUserStore<TUser>>(provider =>
|
||||
builder.Services.TryAddSingleton<IUserStore<TUser>>(provider =>
|
||||
{
|
||||
return new MongoUserStore<TUser, TRole, IMongoDbContext, TKey>(provider.GetService<IMongoDbContext>());
|
||||
});
|
||||
|
||||
builder.Services.TryAddScoped<IRoleStore<TRole>>(provider =>
|
||||
builder.Services.TryAddSingleton<IRoleStore<TRole>>(provider =>
|
||||
{
|
||||
return new MongoRoleStore<TRole, IMongoDbContext, TKey>(provider.GetService<IMongoDbContext>());
|
||||
});
|
||||
|
||||
+46
-45
@@ -171,7 +171,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
public async override Task<IdentityResult> CreateAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
ThrowIfDisposed();
|
||||
//ThrowIfDisposed();
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
@@ -190,7 +190,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
public async override Task<IdentityResult> UpdateAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
ThrowIfDisposed();
|
||||
//ThrowIfDisposed();
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
@@ -217,7 +217,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
public async override Task<IdentityResult> DeleteAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
ThrowIfDisposed();
|
||||
//ThrowIfDisposed();
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
@@ -249,7 +249,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
public override Task<TUser> FindByIdAsync(string userId, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
ThrowIfDisposed();
|
||||
//ThrowIfDisposed();
|
||||
var id = ConvertIdFromString(userId);
|
||||
return MongoRepository.GetByIdAsync<TUser, TKey>(id);
|
||||
}
|
||||
@@ -265,7 +265,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
public override Task<TUser> FindByNameAsync(string normalizedUserName, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
ThrowIfDisposed();
|
||||
//ThrowIfDisposed();
|
||||
return MongoRepository.GetOneAsync<TUser, TKey>(u => u.NormalizedUserName == normalizedUserName);
|
||||
}
|
||||
|
||||
@@ -367,7 +367,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
public async override Task AddToRoleAsync(TUser user, string normalizedRoleName, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
ThrowIfDisposed();
|
||||
//ThrowIfDisposed();
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
@@ -393,12 +393,6 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
}
|
||||
}
|
||||
|
||||
//private async Task<IdentityResult> UserAlreadyInRoleError(TUser user, string role)
|
||||
//{
|
||||
// Logger.LogWarning(5, "User {userId} is already in role {role}.", await GetUserIdAsync(user), role);
|
||||
// return IdentityResult.Failed(ErrorDescriber.UserAlreadyInRole(role));
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// Removes the given <paramref name="normalizedRoleName"/> from the specified <paramref name="user"/>.
|
||||
/// </summary>
|
||||
@@ -409,7 +403,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
public async override Task RemoveFromRoleAsync(TUser user, string normalizedRoleName, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
ThrowIfDisposed();
|
||||
//ThrowIfDisposed();
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
@@ -435,7 +429,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
public override async Task<IList<string>> GetRolesAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
ThrowIfDisposed();
|
||||
//ThrowIfDisposed();
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
@@ -458,7 +452,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
public override async Task<bool> IsInRoleAsync(TUser user, string normalizedRoleName, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
ThrowIfDisposed();
|
||||
//ThrowIfDisposed();
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
@@ -485,7 +479,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
public async override Task<IList<Claim>> GetClaimsAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken))
|
||||
#pragma warning restore CS1998 // Cette méthode async n'a pas d'opérateur 'await' et elle s'exécutera de façon synchrone
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
//ThrowIfDisposed();
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
@@ -502,7 +496,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
/// <returns>The <see cref="Task"/> that represents the asynchronous operation.</returns>
|
||||
public override Task AddClaimsAsync(TUser user, IEnumerable<Claim> claims, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
//ThrowIfDisposed();
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
@@ -540,7 +534,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
/// <returns>The <see cref="Task"/> that represents the asynchronous operation.</returns>
|
||||
public async override Task ReplaceClaimAsync(TUser user, Claim claim, Claim newClaim, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
//ThrowIfDisposed();
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
@@ -569,7 +563,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
/// <returns>The <see cref="Task"/> that represents the asynchronous operation.</returns>
|
||||
public async override Task RemoveClaimsAsync(TUser user, IEnumerable<Claim> claims, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
//ThrowIfDisposed();
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
@@ -595,7 +589,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
ThrowIfDisposed();
|
||||
//ThrowIfDisposed();
|
||||
|
||||
if (user == null)
|
||||
{
|
||||
@@ -629,7 +623,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
ThrowIfDisposed();
|
||||
//ThrowIfDisposed();
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
@@ -654,7 +648,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
#pragma warning restore CS1998 // Cette méthode async n'a pas d'opérateur 'await' et elle s'exécutera de façon synchrone
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
ThrowIfDisposed();
|
||||
//ThrowIfDisposed();
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
@@ -675,7 +669,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
ThrowIfDisposed();
|
||||
//ThrowIfDisposed();
|
||||
var userLogin = await FindUserLoginAsync(loginProvider, providerKey, cancellationToken);
|
||||
if (userLogin != null)
|
||||
{
|
||||
@@ -695,7 +689,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
public override Task<TUser> FindByEmailAsync(string normalizedEmail, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
ThrowIfDisposed();
|
||||
//ThrowIfDisposed();
|
||||
return MongoRepository.GetOneAsync<TUser, TKey>(u => u.NormalizedEmail == normalizedEmail);
|
||||
}
|
||||
|
||||
@@ -710,7 +704,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
public async override Task<IList<TUser>> GetUsersForClaimAsync(Claim claim, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
ThrowIfDisposed();
|
||||
//ThrowIfDisposed();
|
||||
if (claim == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(claim));
|
||||
@@ -734,7 +728,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
public async override Task<IList<TUser>> GetUsersInRoleAsync(string normalizedRoleName, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
ThrowIfDisposed();
|
||||
//ThrowIfDisposed();
|
||||
if (string.IsNullOrEmpty(normalizedRoleName))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(normalizedRoleName));
|
||||
@@ -814,7 +808,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
public override Task SetUserNameAsync(TUser user, string userName, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
ThrowIfDisposed();
|
||||
//ThrowIfDisposed();
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
@@ -838,7 +832,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
public override Task SetNormalizedUserNameAsync(TUser user, string normalizedName, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
ThrowIfDisposed();
|
||||
//ThrowIfDisposed();
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
@@ -862,7 +856,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
public override Task SetPasswordHashAsync(TUser user, string passwordHash, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
ThrowIfDisposed();
|
||||
//ThrowIfDisposed();
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
@@ -886,7 +880,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
public override Task SetEmailConfirmedAsync(TUser user, bool confirmed, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
ThrowIfDisposed();
|
||||
//ThrowIfDisposed();
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
@@ -909,7 +903,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
public override Task SetEmailAsync(TUser user, string email, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
ThrowIfDisposed();
|
||||
//ThrowIfDisposed();
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
@@ -933,7 +927,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
public override Task SetNormalizedEmailAsync(TUser user, string normalizedEmail, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
ThrowIfDisposed();
|
||||
//ThrowIfDisposed();
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
@@ -958,7 +952,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
public override Task SetLockoutEndDateAsync(TUser user, DateTimeOffset? lockoutEnd, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
ThrowIfDisposed();
|
||||
//ThrowIfDisposed();
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
@@ -981,7 +975,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
public override Task<int> IncrementAccessFailedCountAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
ThrowIfDisposed();
|
||||
//ThrowIfDisposed();
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
@@ -1001,7 +995,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
public override Task ResetAccessFailedCountAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
ThrowIfDisposed();
|
||||
//ThrowIfDisposed();
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
@@ -1025,7 +1019,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
public override Task SetLockoutEnabledAsync(TUser user, bool enabled, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
ThrowIfDisposed();
|
||||
//ThrowIfDisposed();
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
@@ -1049,7 +1043,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
public override Task SetPhoneNumberAsync(TUser user, string phoneNumber, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
ThrowIfDisposed();
|
||||
//ThrowIfDisposed();
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
@@ -1072,7 +1066,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
public override Task SetPhoneNumberConfirmedAsync(TUser user, bool confirmed, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
ThrowIfDisposed();
|
||||
//ThrowIfDisposed();
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
@@ -1097,7 +1091,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
public override Task SetSecurityStampAsync(TUser user, string stamp, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
ThrowIfDisposed();
|
||||
//ThrowIfDisposed();
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
@@ -1126,7 +1120,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
public override Task SetTwoFactorEnabledAsync(TUser user, bool enabled, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
ThrowIfDisposed();
|
||||
//ThrowIfDisposed();
|
||||
if (user == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
@@ -1151,7 +1145,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
public override async Task SetTokenAsync(TUser user, string loginProvider, string name, string value, CancellationToken cancellationToken)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
ThrowIfDisposed();
|
||||
//ThrowIfDisposed();
|
||||
|
||||
if (user == null)
|
||||
{
|
||||
@@ -1187,7 +1181,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
public override async Task RemoveTokenAsync(TUser user, string loginProvider, string name, CancellationToken cancellationToken)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
ThrowIfDisposed();
|
||||
//ThrowIfDisposed();
|
||||
|
||||
if (user == null)
|
||||
{
|
||||
@@ -1214,7 +1208,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
public override async Task<string> GetTokenAsync(TUser user, string loginProvider, string name, CancellationToken cancellationToken)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
ThrowIfDisposed();
|
||||
//ThrowIfDisposed();
|
||||
|
||||
if (user == null)
|
||||
{
|
||||
@@ -1256,7 +1250,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
public override async Task<int> CountCodesAsync(TUser user, CancellationToken cancellationToken)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
ThrowIfDisposed();
|
||||
//ThrowIfDisposed();
|
||||
|
||||
if (user == null)
|
||||
{
|
||||
@@ -1294,7 +1288,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
public override async Task<bool> RedeemCodeAsync(TUser user, string code, CancellationToken cancellationToken)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
ThrowIfDisposed();
|
||||
//ThrowIfDisposed();
|
||||
|
||||
if (user == null)
|
||||
{
|
||||
@@ -1317,5 +1311,12 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Prevent the
|
||||
/// </summary>
|
||||
public new void Dispose()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user