Skip to content

Commit 09ace3c

Browse files
author
MaxiomTech
authored
Merge pull request #35 from sitebro/UpdateToMongoDBDriver243
Update MongoDB.AspNet.Identity
2 parents a1d0a15 + 89470c0 commit 09ace3c

File tree

83 files changed

+29679
-133
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+29679
-133
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,8 @@ _UpgradeReport_Files/
107107
Backup*/
108108
UpgradeLog*.XML
109109
MongoDB.AspNet.Identity.csproj.GhostDoc.xml
110+
/.vs/config/applicationhost.config
111+
/Properties/PublishProfiles/MongoDbAspNetIdentity.pubxml
112+
/web.config
113+
/web.Debug.config
114+
/web.Release.config

IdentityUser.cs

+40-33
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Threading.Tasks;
24
using Microsoft.AspNet.Identity;
35
using MongoDB.Bson;
46
using MongoDB.Bson.Serialization.Attributes;
@@ -9,7 +11,7 @@ namespace MongoDB.AspNet.Identity
911
/// <summary>
1012
/// Class IdentityUser.
1113
/// </summary>
12-
public class IdentityUser : IUser
14+
public class IdentityUser : IUser<string>
1315
{
1416
/// <summary>
1517
/// Unique key for the user
@@ -50,10 +52,45 @@ public class IdentityUser : IUser
5052
/// <value>The logins.</value>
5153
public virtual List<UserLoginInfo> Logins { get; private set; }
5254

55+
/// <summary>
56+
/// Gets the phone number
57+
/// </summary>
58+
public virtual string PhoneNumber { get; set; }
59+
60+
/// <summary>
61+
/// Gets Email address
62+
/// </summary>
63+
public virtual string Email { get; set; }
64+
65+
/// <summary>
66+
///
67+
/// </summary>
68+
public virtual bool EmailConfirmed { get; set; }
69+
70+
/// <summary>
71+
///
72+
/// </summary>
73+
public DateTime? LockoutEndDateUtc { get; set; } = DateTime.Now.ToUniversalTime();
74+
75+
/// <summary>
76+
///
77+
/// </summary>
78+
public int AccessFailedCount { get; set; }
79+
80+
/// <summary>
81+
///
82+
/// </summary>
83+
public bool LockoutEnabled { get; set; }
84+
85+
/// <summary>
86+
///
87+
/// </summary>
88+
public bool TwoFactorEnabled { get; set; }
89+
5390
/// <summary>
5491
/// Initializes a new instance of the <see cref="IdentityUser"/> class.
5592
/// </summary>
56-
public IdentityUser()
93+
public IdentityUser()
5794
{
5895
this.Claims = new List<IdentityUserClaim>();
5996
this.Roles = new List<string>();
@@ -69,34 +106,4 @@ public IdentityUser(string userName) : this()
69106
this.UserName = userName;
70107
}
71108
}
72-
73-
/// <summary>
74-
/// Class IdentityUserClaim.
75-
/// </summary>
76-
public class IdentityUserClaim
77-
{
78-
/// <summary>
79-
/// Gets or sets the identifier.
80-
/// </summary>
81-
/// <value>The identifier.</value>
82-
[BsonId]
83-
[BsonRepresentation(BsonType.ObjectId)]
84-
public virtual string Id { get; set; }
85-
/// <summary>
86-
/// Gets or sets the user identifier.
87-
/// </summary>
88-
/// <value>The user identifier.</value>
89-
public virtual string UserId { get; set; }
90-
/// <summary>
91-
/// Gets or sets the type of the claim.
92-
/// </summary>
93-
/// <value>The type of the claim.</value>
94-
public virtual string ClaimType { get; set; }
95-
/// <summary>
96-
/// Gets or sets the claim value.
97-
/// </summary>
98-
/// <value>The claim value.</value>
99-
public virtual string ClaimValue { get; set; }
100-
101-
}
102109
}

IdentityUserClaim.cs

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using MongoDB.Bson;
2+
using MongoDB.Bson.Serialization.Attributes;
3+
4+
namespace MongoDB.AspNet.Identity
5+
{
6+
/// <summary>
7+
/// Class IdentityUserClaim.
8+
/// </summary>
9+
public class IdentityUserClaim
10+
{
11+
/// <summary>
12+
/// Gets or sets the identifier.
13+
/// </summary>
14+
/// <value>The identifier.</value>
15+
[BsonId]
16+
[BsonRepresentation(BsonType.ObjectId)]
17+
public virtual string Id { get; set; }
18+
/// <summary>
19+
/// Gets or sets the user identifier.
20+
/// </summary>
21+
/// <value>The user identifier.</value>
22+
public virtual string UserId { get; set; }
23+
/// <summary>
24+
/// Gets or sets the type of the claim.
25+
/// </summary>
26+
/// <value>The type of the claim.</value>
27+
public virtual string ClaimType { get; set; }
28+
/// <summary>
29+
/// Gets or sets the claim value.
30+
/// </summary>
31+
/// <value>The claim value.</value>
32+
public virtual string ClaimValue { get; set; }
33+
34+
}
35+
}

MongoDB.AspNet.Identity.csproj

+29-9
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<IISExpressWindowsAuthentication />
2121
<IISExpressUseClassicPipelineMode />
2222
<TargetFrameworkProfile />
23+
<UseGlobalApplicationHostFile />
2324
</PropertyGroup>
2425
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
2526
<DebugSymbols>true</DebugSymbols>
@@ -41,21 +42,34 @@
4142
<DocumentationFile>bin\MongoDB.AspNet.Identity.XML</DocumentationFile>
4243
</PropertyGroup>
4344
<ItemGroup>
44-
<Reference Include="Microsoft.AspNet.Identity.Core">
45-
<HintPath>packages\Microsoft.AspNet.Identity.Core.1.0.0\lib\net45\Microsoft.AspNet.Identity.Core.dll</HintPath>
45+
<Reference Include="Microsoft.AspNet.Identity.Core, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
46+
<HintPath>packages\Microsoft.AspNet.Identity.Core.2.2.1\lib\net45\Microsoft.AspNet.Identity.Core.dll</HintPath>
47+
<Private>True</Private>
4648
</Reference>
47-
<Reference Include="MongoDB.Bson, Version=1.8.3.9, Culture=neutral, PublicKeyToken=f686731cfb9cc103, processorArchitecture=MSIL">
48-
<SpecificVersion>False</SpecificVersion>
49-
<HintPath>packages\mongocsharpdriver.1.8.3\lib\net35\MongoDB.Bson.dll</HintPath>
49+
<Reference Include="MongoDB.Bson, Version=2.4.3.23, Culture=neutral, processorArchitecture=MSIL">
50+
<HintPath>packages\MongoDB.Bson.2.4.3\lib\net45\MongoDB.Bson.dll</HintPath>
51+
<Private>True</Private>
5052
</Reference>
51-
<Reference Include="MongoDB.Driver, Version=1.8.3.9, Culture=neutral, PublicKeyToken=f686731cfb9cc103, processorArchitecture=MSIL">
52-
<SpecificVersion>False</SpecificVersion>
53-
<HintPath>packages\mongocsharpdriver.1.8.3\lib\net35\MongoDB.Driver.dll</HintPath>
53+
<Reference Include="MongoDB.Driver, Version=2.4.3.23, Culture=neutral, processorArchitecture=MSIL">
54+
<HintPath>packages\MongoDB.Driver.2.4.3\lib\net45\MongoDB.Driver.dll</HintPath>
55+
<Private>True</Private>
56+
</Reference>
57+
<Reference Include="MongoDB.Driver.Core, Version=2.4.3.23, Culture=neutral, processorArchitecture=MSIL">
58+
<HintPath>packages\MongoDB.Driver.Core.2.4.3\lib\net45\MongoDB.Driver.Core.dll</HintPath>
59+
<Private>True</Private>
60+
</Reference>
61+
<Reference Include="MongoDB.Driver.Legacy, Version=2.4.3.23, Culture=neutral, processorArchitecture=MSIL">
62+
<HintPath>packages\mongocsharpdriver.2.4.3\lib\net45\MongoDB.Driver.Legacy.dll</HintPath>
63+
<Private>True</Private>
5464
</Reference>
5565
<Reference Include="System.ComponentModel.DataAnnotations" />
5666
<Reference Include="System" />
5767
<Reference Include="System.Data" />
5868
<Reference Include="System.Data.DataSetExtensions" />
69+
<Reference Include="System.Runtime.InteropServices.RuntimeInformation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
70+
<HintPath>packages\System.Runtime.InteropServices.RuntimeInformation.4.0.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath>
71+
<Private>True</Private>
72+
</Reference>
5973
<Reference Include="System.Web.ApplicationServices" />
6074
<Reference Include="System.Web.DynamicData" />
6175
<Reference Include="System.Web.Entity" />
@@ -65,12 +79,18 @@
6579
</ItemGroup>
6680
<ItemGroup>
6781
<Compile Include="IdentityUser.cs" />
82+
<Compile Include="IdentityUserClaim.cs" />
6883
<Compile Include="Properties\AssemblyInfo.cs" />
6984
<Compile Include="UserStore.cs" />
7085
<Compile Include="Utils.cs" />
7186
</ItemGroup>
7287
<ItemGroup>
73-
<Content Include="packages.config" />
88+
<Content Include="packages.config">
89+
<SubType>Designer</SubType>
90+
</Content>
91+
</ItemGroup>
92+
<ItemGroup>
93+
<None Include="Properties\PublishProfiles\MongoDbAspNetIdentity.pubxml" />
7494
</ItemGroup>
7595
<PropertyGroup>
7696
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>

MongoDB.AspNet.Identity.nuspec

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0"?>
2+
<package >
3+
<metadata>
4+
<id>MongoDB.AspNet.Identity</id>
5+
<version>1.0.7</version>
6+
<authors>jsheely, sitebro</authors>
7+
<owners>Jonathan Sheely</owners>
8+
<licenseUrl>https://raw.githubusercontent.com/InspectorIT/MongoDB.AspNet.Identity/master/LICENSE</licenseUrl>
9+
<projectUrl>https://github.com/InspectorIT/MongoDB.AspNet.Identity</projectUrl>
10+
<iconUrl>https://www.nuget.org/Content/Images/packageDefaultIcon-50x50.png</iconUrl>
11+
<requireLicenseAcceptance>true</requireLicenseAcceptance>
12+
<description>ASP.NET MVC 5 shipped with a new Identity system (in the Microsoft.AspNet.Identity.Core package) in order to support both local login and remote logins via OpenID/OAuth, but only ships with an Entity Framework provider (Microsoft.AspNet.Identity.EntityFramework).
13+
MongoDB.AspNet.Identity is a MongoDB backend provider that is a nearly in place replacement for the EF version. This library has been built to work with the mongocsharpdriver compatibility .NET driver provided by the MongoDB team.</description>
14+
<releaseNotes>
15+
Version 1.0.7
16+
- Added properties to IdentityUser required by the default UserManager bundled with the default ASP.NET MVC5 template
17+
- Implemented IUserStore, IUserEmailStore, IUserLockoutStore
18+
</releaseNotes>
19+
<copyright>Copyright 2017</copyright>
20+
<tags>mongodb mongocsharpdriver identity mvc5</tags>
21+
<dependencies>
22+
<dependency id="Microsoft.AspNet.Identity.Core" version="2.2.1" />
23+
<dependency id="mongocsharpdriver" version="2.4.3" />
24+
<dependency id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" />
25+
</dependencies>
26+
</metadata>
27+
</package>

MongoDB.AspNet.Identity.sln

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 2013
4-
VisualStudioVersion = 12.0.21005.1
3+
# Visual Studio 14
4+
VisualStudioVersion = 14.0.25420.1
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDB.AspNet.Identity", "MongoDB.AspNet.Identity.csproj", "{0FF87680-235F-4231-8302-9BF6FCAC7476}"
77
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestApplication", "TestApplication\TestApplication.csproj", "{4EF07067-48A5-4303-849A-9D800F482E31}"
9+
EndProject
810
Global
911
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1012
Debug|Any CPU = Debug|Any CPU
@@ -15,6 +17,10 @@ Global
1517
{0FF87680-235F-4231-8302-9BF6FCAC7476}.Debug|Any CPU.Build.0 = Debug|Any CPU
1618
{0FF87680-235F-4231-8302-9BF6FCAC7476}.Release|Any CPU.ActiveCfg = Release|Any CPU
1719
{0FF87680-235F-4231-8302-9BF6FCAC7476}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{4EF07067-48A5-4303-849A-9D800F482E31}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{4EF07067-48A5-4303-849A-9D800F482E31}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{4EF07067-48A5-4303-849A-9D800F482E31}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{4EF07067-48A5-4303-849A-9D800F482E31}.Release|Any CPU.Build.0 = Release|Any CPU
1824
EndGlobalSection
1925
GlobalSection(SolutionProperties) = preSolution
2026
HideSolutionNode = FALSE

Properties/AssemblyInfo.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
[assembly: AssemblyConfiguration("")]
1111
[assembly: AssemblyCompany("InspectorIT by Jonathan Sheely")]
1212
[assembly: AssemblyProduct("MongoDB.AspNet.Identity")]
13-
[assembly: AssemblyCopyright("Copyright © 2014")]
13+
[assembly: AssemblyCopyright("Copyright © 2017")]
1414
[assembly: AssemblyTrademark("")]
1515
[assembly: AssemblyCulture("")]
1616

@@ -31,5 +31,5 @@
3131
//
3232
// You can specify all the values or you can default the Revision and Build Numbers
3333
// by using the '*' as shown below:
34-
[assembly: AssemblyVersion("1.0.5.0")]
35-
[assembly: AssemblyFileVersion("1.0.5.0")]
34+
[assembly: AssemblyVersion("1.0.7.0")]
35+
[assembly: AssemblyFileVersion("1.0.7.0")]

README.md

+19-8
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ __02-11-2014__ - [http://blogs.msdn.com/b/webdev/archive/2014/02/11/announcing-p
2323
* IUserClaimStore<TUser>
2424
* IUserPasswordStore<TUser>
2525
* IUserSecurityStampStore<TUser>
26+
* IUserEmailStore<TUser> (1.0.7)
27+
* IUserLockoutStore<TUser, string> (1.0.7)
28+
* IUserTwoFactorStore<TUser, string> (1.0.7)
2629

2730
## Instructions ##
2831
These instructions assume you know how to set up MongoDB within an MVC application.
@@ -43,12 +46,20 @@ Install-Package MongoDB.AspNet.Identity
4346
4. In ~/Controllers/AccountController.cs
4447
* Remove the namespace: Microsoft.AspNet.Identity.EntityFramework
4548
* Add the connection string name to the constructor of the UserStore. Or empty constructor will use DefaultConnection
49+
5. In ~/App_Start/IdentityConfig.cs
50+
* Remove reference to ApplicationDbContext
51+
* Amend ApplicationUserManager to inherit UserManager<ApplicationUser, string>. Also amend parameter for ApplicationUser.GenerateUserIdentityAsync
52+
6. In ~/App_Start/Startup.Auth.cs
53+
* Remove app.CreatePerOwinContext<ApplicationDbContext>(ApplicationDbContext.Create);
4654

4755
```C#
56+
AccountController requires a parameterless constructor.
57+
You could instantiate the UserManager in this contructor using any the UserStore constructors.
4858
public AccountController()
4959
{
50-
this.UserManager = new UserManager<ApplicationUser>(
51-
new UserStore<ApplicationUser>("Mongo");
60+
//examples
61+
this.UserManager =
62+
new ApplicationUserManager(new UserStore<ApplicationUser>("MyConnection"));
5263
}
5364
```
5465

@@ -57,9 +68,9 @@ The UserStore has multiple constructors for handling connection strings. Here ar
5768

5869
### 1. SQL Style ###
5970
```C#
60-
UserStore(string connectionNameOrUrl)
71+
UserStore<TUser>(string connectionNameOrUrl)
6172
```
62-
<code>UserStore("Mongo")</code>
73+
<code>UserStore<TUser>("Mongo")</code>
6374

6475
**web.config**
6576
```xml
@@ -68,9 +79,9 @@ UserStore(string connectionNameOrUrl)
6879

6980
### 2. Mongo Style ###
7081
```C#
71-
UserStore(string connectionNameOrUrl)
82+
UserStore<TUser>(string connectionNameOrUrl)
7283
```
73-
<code>UserStore("Mongo")</code>
84+
<code>UserStore<TUser>("Mongo")</code>
7485

7586
**web.config**
7687
```xml
@@ -80,9 +91,9 @@ UserStore(string connectionNameOrUrl)
8091
**OR**
8192

8293
```C#
83-
UserStore(string connectionNameOrUrl)
94+
UserStore<TUser>(string connectionNameOrUrl)
8495
```
85-
<code>UserStore("mongodb://localhost/{YourDataBase}")</code>
96+
<code>UserStore<TUser>("mongodb://localhost/{YourDataBase}")</code>
8697

8798

8899
## Thanks To ##
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System.Web;
2+
using System.Web.Optimization;
3+
4+
namespace TestApplication
5+
{
6+
public class BundleConfig
7+
{
8+
// For more information on bundling, visit http://go.microsoft.com/fwlink/?LinkId=301862
9+
public static void RegisterBundles(BundleCollection bundles)
10+
{
11+
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
12+
"~/Scripts/jquery-{version}.js"));
13+
14+
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
15+
"~/Scripts/jquery.validate*"));
16+
17+
// Use the development version of Modernizr to develop with and learn from. Then, when you're
18+
// ready for production, use the build tool at http://modernizr.com to pick only the tests you need.
19+
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
20+
"~/Scripts/modernizr-*"));
21+
22+
bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
23+
"~/Scripts/bootstrap.js",
24+
"~/Scripts/respond.js"));
25+
26+
bundles.Add(new StyleBundle("~/Content/css").Include(
27+
"~/Content/bootstrap.css",
28+
"~/Content/site.css"));
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)