Update with latest Identity API changes
This commit is contained in:
parent
39b5c4439b
commit
36770ccf05
|
|
@ -11,31 +11,15 @@ namespace MusicStore.Controllers
|
||||||
[Authorize]
|
[Authorize]
|
||||||
public class AccountController : Controller
|
public class AccountController : Controller
|
||||||
{
|
{
|
||||||
public AccountController(ApplicationUserManager userManager)
|
public AccountController(ApplicationUserManager userManager, ApplicationSignInManager signInManager)
|
||||||
{
|
{
|
||||||
UserManager = userManager;
|
UserManager = userManager;
|
||||||
|
SignInManager = signInManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserManager<ApplicationUser> UserManager { get; private set; }
|
public UserManager<ApplicationUser> UserManager { get; private set; }
|
||||||
|
|
||||||
private SignInManager<ApplicationUser> _signInManager;
|
public ApplicationSignInManager SignInManager { get; private set; }
|
||||||
public SignInManager<ApplicationUser> SignInManager
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (_signInManager == null)
|
|
||||||
{
|
|
||||||
_signInManager = new SignInManager<ApplicationUser>
|
|
||||||
{
|
|
||||||
UserManager = UserManager,
|
|
||||||
Context = Context,
|
|
||||||
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return _signInManager;
|
|
||||||
}
|
|
||||||
set { _signInManager = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// GET: /Account/Login
|
// GET: /Account/Login
|
||||||
|
|
@ -96,7 +80,7 @@ namespace MusicStore.Controllers
|
||||||
//Bug: https://github.com/aspnet/WebFx/issues/247
|
//Bug: https://github.com/aspnet/WebFx/issues/247
|
||||||
//if (ModelState.IsValid == true)
|
//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);
|
var result = await UserManager.CreateAsync(user, model.Password);
|
||||||
if (result.Succeeded)
|
if (result.Succeeded)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,24 @@
|
||||||
using System;
|
using System;
|
||||||
|
using Microsoft.AspNet.Abstractions;
|
||||||
|
using Microsoft.AspNet.DependencyInjection;
|
||||||
using Microsoft.AspNet.Identity;
|
using Microsoft.AspNet.Identity;
|
||||||
|
using Microsoft.AspNet.Identity.Security;
|
||||||
|
|
||||||
namespace MusicStore.Models
|
namespace MusicStore.Models
|
||||||
{
|
{
|
||||||
public class ApplicationUserManager : UserManager<ApplicationUser>
|
public class ApplicationUserManager : UserManager<ApplicationUser>
|
||||||
{
|
{
|
||||||
public ApplicationUserManager(IServiceProvider services) : base(services) { }
|
public ApplicationUserManager(IServiceProvider services, IUserStore<ApplicationUser> store, IOptionsAccessor<IdentityOptions> optionsAccessor) : base(services, store, optionsAccessor) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ApplicationRoleManager : RoleManager<IdentityRole>
|
public class ApplicationRoleManager : RoleManager<IdentityRole>
|
||||||
{
|
{
|
||||||
public ApplicationRoleManager(IServiceProvider services) : base(services) { }
|
public ApplicationRoleManager(IServiceProvider services, IRoleStore<IdentityRole> store) : base(services, store) { }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ApplicationSignInManager : SignInManager<ApplicationUserManager, ApplicationUser>
|
||||||
|
{
|
||||||
|
public ApplicationSignInManager(ApplicationUserManager manager, IContextAccessor<HttpContext> contextAccessor) : base(manager, contextAccessor) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ApplicationUser : IdentityUser
|
public class ApplicationUser : IdentityUser
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ public class Startup
|
||||||
#else
|
#else
|
||||||
services.AddEntityFramework(s => s.AddInMemoryStore());
|
services.AddEntityFramework(s => s.AddInMemoryStore());
|
||||||
#endif
|
#endif
|
||||||
services.AddTransient<MusicStoreContext, MusicStoreContext>();
|
services.AddTransient<MusicStoreContext>();
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -66,18 +66,26 @@ public class Startup
|
||||||
//Bug: https://github.com/aspnet/Identity/issues/50
|
//Bug: https://github.com/aspnet/Identity/issues/50
|
||||||
services.AddIdentity<ApplicationUser, IdentityRole>(s =>
|
services.AddIdentity<ApplicationUser, IdentityRole>(s =>
|
||||||
{
|
{
|
||||||
// Turn off password defaults since register error display blows up
|
|
||||||
s.UsePasswordValidator(() => new PasswordValidator());
|
|
||||||
|
|
||||||
//s.UseDbContext(() => context);
|
//s.UseDbContext(() => context);
|
||||||
//s.UseUserStore(() => new UserStore(context));
|
//s.UseUserStore(() => new UserStore(context));
|
||||||
s.UseUserStore(() => new InMemoryUserStore<ApplicationUser>());
|
s.AddInMemory();
|
||||||
s.UseUserManager<ApplicationUserManager>();
|
s.AddUserManager<ApplicationUserManager>();
|
||||||
s.UseRoleStore(() => new InMemoryRoleStore<IdentityRole>());
|
s.AddRoleManager<ApplicationRoleManager>();
|
||||||
s.UseRoleManager<ApplicationRoleManager>();
|
|
||||||
});
|
});
|
||||||
|
services.AddTransient<ApplicationSignInManager>();
|
||||||
|
// Turn off password defaults since register error display blows up
|
||||||
|
services.SetupOptions<IdentityOptions>(
|
||||||
|
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.
|
/* 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.
|
* Note: ErrorPageOptions.ShowAll to be used only at development time. Not recommended for production.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue