diff --git a/RavenDB.Identity/IdentityUser.cs b/RavenDB.Identity/IdentityUser.cs index 0271b14..e5f7b42 100644 --- a/RavenDB.Identity/IdentityUser.cs +++ b/RavenDB.Identity/IdentityUser.cs @@ -105,6 +105,7 @@ namespace Raven.Identity this.Claims = new List(); this.Roles = new List(); this.Logins = new List(); + this.TwoFactorRecoveryCodes = new List(); } /// diff --git a/Readme.md b/Readme.md index 115556e..a801944 100644 --- a/Readme.md +++ b/Readme.md @@ -11,7 +11,7 @@ public void ConfigureServices(IServiceCollection services) { // Add RavenDB and identity. services - .AddRavenDbAsyncSession(docStore) // Create a RavenDB IAsyncDocumentSession for each request. docStore is your IDocumentStore instance. + .AddRavenDbAsyncSession(docStore) // Create a RavenDB IAsyncDocumentSession for each request. docStore is your IDocumentStore instance. You're responsible for calling .SaveChanges after each request. .AddRavenDbIdentity(); // Use Raven for users and roles. AppUser is your class, a simple DTO to hold user data. See https://github.com/JudahGabriel/RavenDB.Identity/blob/master/Sample/Models/AppUser.cs ... @@ -22,6 +22,6 @@ public void ConfigureServices(IServiceCollection services) 3. You're done! -Need help? See the [sample app](https://github.com/JudahGabriel/RavenDB.Identity/tree/master/Sample). +Need help? See the [sample app](https://github.com/JudahGabriel/RavenDB.Identity/tree/master/Sample). It supports regular sign-ins as well as 2-factor authentication. Not using .NET Core? See our [sister project](https://github.com/JudahGabriel/RavenDB.AspNet.Identity) for a RavenDB Identity Provider for MVC 5+ and WebAPI 2+ on the full .NET Framework. \ No newline at end of file diff --git a/Sample/Controllers/ManageController.cs b/Sample/Controllers/ManageController.cs index 29e6f3b..e5f7468 100644 --- a/Sample/Controllers/ManageController.cs +++ b/Sample/Controllers/ManageController.cs @@ -10,6 +10,7 @@ using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; +using Raven.Client.Documents.Session; using Sample.Models; using Sample.Models.ManageViewModels; using Sample.Services; @@ -18,7 +19,7 @@ namespace Sample.Controllers { [Authorize] [Route("[controller]/[action]")] - public class ManageController : Controller + public class ManageController : RavenController { private readonly UserManager _userManager; private readonly SignInManager _signInManager; @@ -29,11 +30,13 @@ namespace Sample.Controllers private const string AuthenicatorUriFormat = "otpauth://totp/{0}:{1}?secret={2}&issuer={0}&digits=6"; public ManageController( - UserManager userManager, - SignInManager signInManager, - IEmailSender emailSender, - ILogger logger, - UrlEncoder urlEncoder) + IAsyncDocumentSession dbSession, + UserManager userManager, + SignInManager signInManager, + IEmailSender emailSender, + ILogger logger, + UrlEncoder urlEncoder) + : base(dbSession) { _userManager = userManager; _signInManager = signInManager; diff --git a/Sample/Startup.cs b/Sample/Startup.cs index 137c170..c8a9324 100644 --- a/Sample/Startup.cs +++ b/Sample/Startup.cs @@ -29,29 +29,14 @@ namespace Sample { // Connect to a Raven server. We're using the public test playground at http://live-test.ravendb.net - // NOTE: Getting a DatabaseDoesNotExistException? Go to http://live-test.ravendb.net and create a database with the name 'Raven.Identity.Sample' + var databaseName = "Raven.Identity.Sample"; var docStore = new DocumentStore { Urls = new string[] { "http://live-test.ravendb.net" }, - Database = "Raven.Identity.Sample" + Database = databaseName }; docStore.Initialize(); - - // Create the database if it doesn't exist yet. - try - { - using (var dbSession = docStore.OpenSession()) - { - dbSession.Query().Take(0).ToList(); - } - } - catch (Raven.Client.Exceptions.Database.DatabaseDoesNotExistException) - { - docStore.Maintenance.Server.Send(new Raven.Client.ServerWide.Operations.CreateDatabaseOperation(new Raven.Client.ServerWide.DatabaseRecord - { - DatabaseName = "Raven.Identity.Sample" - })); - } + CreateDatabaseIfNotExists(docStore, databaseName); // Add RavenDB and identity. services @@ -67,6 +52,24 @@ namespace Sample services.AddMvc(); } + private void CreateDatabaseIfNotExists(IDocumentStore docStore, string databaseName) + { + try + { + using (var dbSession = docStore.OpenSession()) + { + dbSession.Query().Take(0).ToList(); + } + } + catch (Raven.Client.Exceptions.Database.DatabaseDoesNotExistException) + { + docStore.Maintenance.Server.Send(new Raven.Client.ServerWide.Operations.CreateDatabaseOperation(new Raven.Client.ServerWide.DatabaseRecord + { + DatabaseName = databaseName + })); + } + } + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) {