diff --git a/src/MusicStore/Controllers/AccountController.cs b/src/MusicStore/Controllers/AccountController.cs index b2866d3a0e..b245d0c396 100644 --- a/src/MusicStore/Controllers/AccountController.cs +++ b/src/MusicStore/Controllers/AccountController.cs @@ -11,31 +11,15 @@ namespace MusicStore.Controllers [Authorize] public class AccountController : Controller { - public AccountController(ApplicationUserManager userManager) + public AccountController(ApplicationUserManager userManager, ApplicationSignInManager signInManager) { UserManager = userManager; + SignInManager = signInManager; } public UserManager UserManager { get; private set; } - private SignInManager _signInManager; - public SignInManager SignInManager - { - get - { - if (_signInManager == null) - { - _signInManager = new SignInManager - { - UserManager = UserManager, - Context = Context, - AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie - }; - } - return _signInManager; - } - set { _signInManager = value; } - } + public ApplicationSignInManager SignInManager { get; private set; } // // GET: /Account/Login @@ -96,7 +80,7 @@ namespace MusicStore.Controllers //Bug: https://github.com/aspnet/WebFx/issues/247 //if (ModelState.IsValid == true) { - var user = new ApplicationUser() { UserName = model.UserName }; + var user = new ApplicationUser { UserName = model.UserName }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { diff --git a/src/MusicStore/Models/IdentityModels.cs b/src/MusicStore/Models/IdentityModels.cs index a3b8c427aa..bf1d686900 100644 --- a/src/MusicStore/Models/IdentityModels.cs +++ b/src/MusicStore/Models/IdentityModels.cs @@ -1,16 +1,24 @@ using System; +using Microsoft.AspNet.Abstractions; +using Microsoft.AspNet.DependencyInjection; using Microsoft.AspNet.Identity; +using Microsoft.AspNet.Identity.Security; namespace MusicStore.Models { public class ApplicationUserManager : UserManager { - public ApplicationUserManager(IServiceProvider services) : base(services) { } + public ApplicationUserManager(IServiceProvider services, IUserStore store, IOptionsAccessor optionsAccessor) : base(services, store, optionsAccessor) { } } public class ApplicationRoleManager : RoleManager { - public ApplicationRoleManager(IServiceProvider services) : base(services) { } + public ApplicationRoleManager(IServiceProvider services, IRoleStore store) : base(services, store) { } + } + + public class ApplicationSignInManager : SignInManager + { + public ApplicationSignInManager(ApplicationUserManager manager, IContextAccessor contextAccessor) : base(manager, contextAccessor) { } } public class ApplicationUser : IdentityUser diff --git a/src/MusicStore/Startup.cs b/src/MusicStore/Startup.cs index 79590daa34..da9eb7ed14 100644 --- a/src/MusicStore/Startup.cs +++ b/src/MusicStore/Startup.cs @@ -54,7 +54,7 @@ public class Startup #else services.AddEntityFramework(s => s.AddInMemoryStore()); #endif - services.AddTransient(); + services.AddTransient(); /* @@ -66,18 +66,26 @@ public class Startup //Bug: https://github.com/aspnet/Identity/issues/50 services.AddIdentity(s => { - // Turn off password defaults since register error display blows up - s.UsePasswordValidator(() => new PasswordValidator()); - //s.UseDbContext(() => context); //s.UseUserStore(() => new UserStore(context)); - s.UseUserStore(() => new InMemoryUserStore()); - s.UseUserManager(); - s.UseRoleStore(() => new InMemoryRoleStore()); - s.UseRoleManager(); + s.AddInMemory(); + s.AddUserManager(); + s.AddRoleManager(); }); + services.AddTransient(); + // Turn off password defaults since register error display blows up + services.SetupOptions( + options => + { + options.Password.RequireDigit = false; + options.Password.RequireLowercase = false; + options.Password.RequireNonLetterOrDigit = false; + options.Password.RequireUppercase = false; + options.Password.RequiredLength = 0; + }); }); + /* Error page middleware displays a nice formatted HTML page for any unhandled exceptions in the request pipeline. * Note: ErrorPageOptions.ShowAll to be used only at development time. Not recommended for production. */