Merge pull request #1 from alexandre-spieser/master
Pull latest changes
This commit is contained in:
@@ -11,6 +11,11 @@ Available as a Nuget package : https://www.nuget.org/packages/AspNetCore.Identit
|
|||||||
|
|
||||||
Install-Package AspNetCore.Identity.MongoDbCore
|
Install-Package AspNetCore.Identity.MongoDbCore
|
||||||
|
|
||||||
|
# Support This Project
|
||||||
|
|
||||||
|
If you have found this project helpful, either as a library that you use or as a learning tool, please consider buying Alex a coffee: <a href="https://www.buymeacoffee.com/zeitquest" target="_blank"><img height="40px" src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" style="max-height: 51px;width: 150px !important;" ></a>
|
||||||
|
|
||||||
|
|
||||||
# User and Role Entities
|
# User and Role Entities
|
||||||
Your user and role entities must inherit from `MongoIdentityUser<TKey>` and `MongoIdentityRole<TKey>` in a way similar to the `IdentityUser<TKey>` and the `IdentityRole<TKey>` in `Microsoft.AspNetCore.Identity`, where `TKey` is the type of the primary key of your document.
|
Your user and role entities must inherit from `MongoIdentityUser<TKey>` and `MongoIdentityRole<TKey>` in a way similar to the `IdentityUser<TKey>` and the `IdentityRole<TKey>` in `Microsoft.AspNetCore.Identity`, where `TKey` is the type of the primary key of your document.
|
||||||
|
|
||||||
|
|||||||
@@ -1,36 +0,0 @@
|
|||||||
{
|
|
||||||
// Use IntelliSense to find out which attributes exist for C# debugging
|
|
||||||
// Use hover for the description of the existing attributes
|
|
||||||
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
|
|
||||||
"version": "0.2.0",
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": ".NET Core Launch (web)",
|
|
||||||
"type": "coreclr",
|
|
||||||
"request": "launch",
|
|
||||||
"preLaunchTask": "build",
|
|
||||||
// If you have changed target frameworks, make sure to update the program path.
|
|
||||||
"program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/MongoIdentitySample.Mvc.dll",
|
|
||||||
"args": [],
|
|
||||||
"cwd": "${workspaceFolder}",
|
|
||||||
"stopAtEntry": false,
|
|
||||||
// Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
|
|
||||||
"serverReadyAction": {
|
|
||||||
"action": "openExternally",
|
|
||||||
"pattern": "^\\s*Now listening on:\\s+(https?://\\S+)"
|
|
||||||
},
|
|
||||||
"env": {
|
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
|
||||||
},
|
|
||||||
"sourceFileMap": {
|
|
||||||
"/Views": "${workspaceFolder}/Views"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": ".NET Core Attach",
|
|
||||||
"type": "coreclr",
|
|
||||||
"request": "attach",
|
|
||||||
"processId": "${command:pickProcess}"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
{
|
|
||||||
"version": "2.0.0",
|
|
||||||
"tasks": [
|
|
||||||
{
|
|
||||||
"label": "build",
|
|
||||||
"command": "dotnet",
|
|
||||||
"type": "process",
|
|
||||||
"args": [
|
|
||||||
"build",
|
|
||||||
"${workspaceFolder}/MongoIdentitySample.Mvc.csproj",
|
|
||||||
"/property:GenerateFullPaths=true",
|
|
||||||
"/consoleloggerparameters:NoSummary"
|
|
||||||
],
|
|
||||||
"problemMatcher": "$msCompile"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"label": "publish",
|
|
||||||
"command": "dotnet",
|
|
||||||
"type": "process",
|
|
||||||
"args": [
|
|
||||||
"publish",
|
|
||||||
"${workspaceFolder}/MongoIdentitySample.Mvc.csproj",
|
|
||||||
"/property:GenerateFullPaths=true",
|
|
||||||
"/consoleloggerparameters:NoSummary"
|
|
||||||
],
|
|
||||||
"problemMatcher": "$msCompile"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"label": "watch",
|
|
||||||
"command": "dotnet",
|
|
||||||
"type": "process",
|
|
||||||
"args": [
|
|
||||||
"watch",
|
|
||||||
"run",
|
|
||||||
"${workspaceFolder}/MongoIdentitySample.Mvc.csproj",
|
|
||||||
"/property:GenerateFullPaths=true",
|
|
||||||
"/consoleloggerparameters:NoSummary"
|
|
||||||
],
|
|
||||||
"problemMatcher": "$msCompile"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="AspNetCore.Identity.MongoDbCore" Version="2.1.1" />
|
||||||
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.13.0-beta1" />
|
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.13.0-beta1" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.1" />
|
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.1" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.1" />
|
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.1" />
|
||||||
@@ -29,10 +30,6 @@
|
|||||||
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.1" />
|
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\..\src\AspNetCore.Identity.MongoDbCore.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Update="appsettings.json">
|
<Content Update="appsettings.json">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
|||||||
@@ -15,8 +15,8 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.2.0" />
|
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.2.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="3.1.1" />
|
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="3.1.1" />
|
||||||
<PackageReference Include="MongoDB.Driver" Version="2.10.1" />
|
<PackageReference Include="MongoDB.Driver" Version="2.9.3" />
|
||||||
<PackageReference Include="MongoDbGenericRepository" Version="1.4.1" />
|
<PackageReference Include="MongoDbGenericRepository" Version="1.4.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -2,29 +2,29 @@
|
|||||||
<package >
|
<package >
|
||||||
<metadata>
|
<metadata>
|
||||||
<id>AspNetCore.Identity.MongoDbCore</id>
|
<id>AspNetCore.Identity.MongoDbCore</id>
|
||||||
<version>2.1.0</version>
|
<version>2.1.1</version>
|
||||||
<title>AspNetCore.Identity.MongoDbCore</title>
|
<title>AspNetCore.Identity.MongoDbCore</title>
|
||||||
<authors>Alexandre Spieser</authors>
|
<authors>Alexandre Spieser</authors>
|
||||||
<owners>Alexandre Spieser</owners>
|
<owners>Alexandre Spieser</owners>
|
||||||
<license type="expression">MIT</license>
|
<license type="expression">MIT</license>
|
||||||
<projectUrl>https://github.com/alexandre-spieser/AspNetCore.Identity.MongoDbCore</projectUrl>
|
<projectUrl>https://github.com/alexandre-spieser/AspNetCore.Identity.MongoDbCore</projectUrl>
|
||||||
<requireLicenseAcceptance>false</requireLicenseAcceptance>
|
<requireLicenseAcceptance>false</requireLicenseAcceptance>
|
||||||
<description>A MongoDb UserStore and RoleStore adapter for Microsoft.AspNetCore.Identity 2.0.</description>
|
<description>A MongoDb UserStore and RoleStore adapter for Microsoft.AspNetCore.Identity 2.2.</description>
|
||||||
<releaseNotes>Release notes are at https://github.com/alexandre-spieser/AspNetCore.Identity.MongoDbCore/releases</releaseNotes>
|
<releaseNotes>Release notes are at https://github.com/alexandre-spieser/AspNetCore.Identity.MongoDbCore/releases</releaseNotes>
|
||||||
<copyright>Copyright 2018 (c) Alexandre Spieser. All rights reserved.</copyright>
|
<copyright>Copyright 2020 (c) Alexandre Spieser. All rights reserved.</copyright>
|
||||||
<tags>aspnetcore mongo mongodb identity membership</tags>
|
<tags>aspnetcore mongo mongodb identity membership</tags>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<group targetFramework="netstandard2.1">
|
<group targetFramework="netstandard2.1">
|
||||||
<dependency id="Microsoft.AspNetCore.Identity" version="[2.2,3)" />
|
<dependency id="Microsoft.AspNetCore.Identity" version="2.2.0" />
|
||||||
<dependency id="Microsoft.Extensions.Identity.Stores" version="[3.1,4)" />
|
<dependency id="Microsoft.Extensions.Identity.Stores" version="3.1.1" />
|
||||||
<dependency id="MongoDB.Driver" version="[2.10,3)" />
|
<dependency id="MongoDB.Driver" version="2.9.3" />
|
||||||
<dependency id="MongoDbGenericRepository" version="[1.4,2)" />
|
<dependency id="MongoDbGenericRepository" version="1.4.1" />
|
||||||
</group>
|
</group>
|
||||||
<group targetFramework="netcoreapp3.1">
|
<group targetFramework="netcoreapp3.1">
|
||||||
<dependency id="Microsoft.AspNetCore.Identity" version="[2.2,3)" />
|
<dependency id="Microsoft.AspNetCore.Identity" version="2.2" />
|
||||||
<dependency id="Microsoft.Extensions.Identity.Stores" version="[3.1,4)" />
|
<dependency id="Microsoft.Extensions.Identity.Stores" version="3.1.1" />
|
||||||
<dependency id="MongoDB.Driver" version="[2.10,3)" />
|
<dependency id="MongoDB.Driver" version="2.9.3" />
|
||||||
<dependency id="MongoDbGenericRepository" version="[1.4,2)" />
|
<dependency id="MongoDbGenericRepository" version="1.4.3" />
|
||||||
</group>
|
</group>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</metadata>
|
</metadata>
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using AspNetCore.Identity.MongoDbCore.Extensions;
|
using AspNetCore.Identity.MongoDbCore.Interfaces;
|
||||||
using AspNetCore.Identity.MongoDbCore.Interfaces;
|
|
||||||
using Microsoft.AspNetCore.Identity;
|
using Microsoft.AspNetCore.Identity;
|
||||||
using MongoDbGenericRepository.Models;
|
using MongoDbGenericRepository.Models;
|
||||||
using MongoDbGenericRepository.Utils;
|
using MongoDbGenericRepository.Utils;
|
||||||
@@ -94,7 +93,7 @@ namespace AspNetCore.Identity.MongoDbCore.Models
|
|||||||
{
|
{
|
||||||
InitializeFields();
|
InitializeFields();
|
||||||
Id = key;
|
Id = key;
|
||||||
Name = Name;
|
Name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using MongoDbGenericRepository.Models;
|
|
||||||
using System.Linq;
|
|
||||||
using MongoDB.Driver;
|
|
||||||
using AspNetCore.Identity.MongoDbCore.Interfaces;
|
using AspNetCore.Identity.MongoDbCore.Interfaces;
|
||||||
using Microsoft.AspNetCore.Identity;
|
using Microsoft.AspNetCore.Identity;
|
||||||
using AspNetCore.Identity.MongoDbCore.Extensions;
|
using MongoDB.Driver;
|
||||||
|
using MongoDbGenericRepository.Models;
|
||||||
using MongoDbGenericRepository.Utils;
|
using MongoDbGenericRepository.Utils;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace AspNetCore.Identity.MongoDbCore.Models
|
namespace AspNetCore.Identity.MongoDbCore.Models
|
||||||
{
|
{
|
||||||
@@ -157,7 +156,7 @@ namespace AspNetCore.Identity.MongoDbCore.Models
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public virtual MongoIdentityUser<TKey> SetVersion(int version)
|
public virtual MongoIdentityUser<TKey> SetVersion(int version)
|
||||||
{
|
{
|
||||||
Version = 1;
|
Version = version;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+915
-655
File diff suppressed because it is too large
Load Diff
BIN
Binary file not shown.
+968
-452
File diff suppressed because it is too large
Load Diff
BIN
Binary file not shown.
File diff suppressed because it is too large
Load Diff
+3
-6
@@ -1,4 +1,4 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="AspNetCore.Identity.MongoDbCore" Version="2.1.1" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Authentication" Version="2.2.0" />
|
<PackageReference Include="Microsoft.AspNetCore.Authentication" Version="2.2.0" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.2.7" />
|
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.2.7" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
|
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
|
||||||
@@ -20,7 +21,7 @@
|
|||||||
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="3.1.1" />
|
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="3.1.1" />
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
|
||||||
<PackageReference Include="MongoDB.Driver" Version="2.10.1" />
|
<PackageReference Include="MongoDB.Driver" Version="2.10.1" />
|
||||||
<PackageReference Include="MongoDbGenericRepository" Version="1.4.1" />
|
<PackageReference Include="MongoDbGenericRepository" Version="1.4.3" />
|
||||||
<PackageReference Include="Moq" Version="4.13.1" />
|
<PackageReference Include="Moq" Version="4.13.1" />
|
||||||
<PackageReference Include="xunit" Version="2.4.1" />
|
<PackageReference Include="xunit" Version="2.4.1" />
|
||||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
|
||||||
@@ -29,10 +30,6 @@
|
|||||||
</PackageReference>
|
</PackageReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\..\src\AspNetCore.Identity.MongoDbCore.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="appsettings*.json">
|
<Content Include="appsettings*.json">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
|||||||
+38
@@ -303,6 +303,44 @@ namespace AspNetCore.Identity.MongoDbCore.Test
|
|||||||
IdentityResultAssert.IsFailure(await manager2.DeleteAsync(role2), new IdentityErrorDescriber().ConcurrencyFailure());
|
IdentityResultAssert.IsFailure(await manager2.DeleteAsync(role2), new IdentityErrorDescriber().ConcurrencyFailure());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task CorrectlyUpdatesUser()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
const string originalEmail = "original@email.com";
|
||||||
|
const string newEmail1 = "new1@email.com";
|
||||||
|
const string newEmail2 = "new2@email.com";
|
||||||
|
var user = CreateTestUser();
|
||||||
|
user.Email = originalEmail;
|
||||||
|
var manager = CreateManager();
|
||||||
|
IdentityResultAssert.IsSuccess(await manager.CreateAsync(user));
|
||||||
|
var userToUpdate = await manager.FindByIdAsync(user.Id);
|
||||||
|
Assert.NotNull(user);
|
||||||
|
Assert.Equal(originalEmail, userToUpdate.Email);
|
||||||
|
|
||||||
|
// Act & Assert
|
||||||
|
// change the email to the new value newEmail1
|
||||||
|
userToUpdate.Email = newEmail1;
|
||||||
|
userToUpdate.UserName = newEmail1;
|
||||||
|
var updateResult1 = await manager.UpdateAsync(userToUpdate);
|
||||||
|
Assert.True(updateResult1.Succeeded);
|
||||||
|
var updatedUser1 = await manager.FindByIdAsync(user.Id);
|
||||||
|
Assert.NotNull(updatedUser1);
|
||||||
|
Assert.Equal(newEmail1, updatedUser1.Email);
|
||||||
|
Assert.Equal(newEmail1, updatedUser1.UserName);
|
||||||
|
|
||||||
|
// change the email to the new value newEmail2
|
||||||
|
userToUpdate.Email = newEmail2;
|
||||||
|
userToUpdate.UserName = newEmail2;
|
||||||
|
var updateResult2 = await manager.UpdateAsync(userToUpdate);
|
||||||
|
Assert.True(updateResult2.Succeeded);
|
||||||
|
|
||||||
|
var updatedUser2 = await manager.FindByIdAsync(user.Id);
|
||||||
|
Assert.NotNull(updatedUser2);
|
||||||
|
Assert.Equal(newEmail2, updatedUser2.Email);
|
||||||
|
Assert.Equal(newEmail2, updatedUser2.UserName);
|
||||||
|
}
|
||||||
|
|
||||||
protected override MongoDbIdentityUser CreateTestUser(string namePrefix = "", string email = "", string phoneNumber = "",
|
protected override MongoDbIdentityUser CreateTestUser(string namePrefix = "", string email = "", string phoneNumber = "",
|
||||||
bool lockoutEnabled = false, DateTimeOffset? lockoutEnd = default(DateTimeOffset?), bool useNamePrefixAsUserName = false)
|
bool lockoutEnabled = false, DateTimeOffset? lockoutEnd = default(DateTimeOffset?), bool useNamePrefixAsUserName = false)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user