protected override void Seed(StoreIdentityDbContext context) { StoreUserManager userMgr = new StoreUserManager(new UserStore <StoreUser>(context)); StoreRoleManager roleMgr = new StoreRoleManager(new RoleStore <StoreRole>(context)); string roleName = "Administrators"; string userName = "******"; string password = "******"; string email = "*****@*****.**"; if (!roleMgr.RoleExists(roleName)) { roleMgr.Create(new StoreRole(roleName)); } StoreUser user = userMgr.FindByName(userName); if (user == null) { userMgr.Create(new StoreUser { UserName = userName, Email = email }, password); user = userMgr.FindByName(userName); } if (!userMgr.IsInRole(user.Id, roleName)) { userMgr.AddToRole(user.Id, roleName); } base.Seed(context); }
public async Task <ActionResult> SignIn() { IAuthenticationManager authMgr = HttpContext.GetOwinContext().Authentication; StoreUserManager userMgr = HttpContext.GetOwinContext().GetUserManager <StoreUserManager>(); StoreUser user = await userMgr.FindAsync("Admin", "secret"); authMgr.SignIn(await userMgr.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie)); return(RedirectToAction("Index")); }
protected override void Dispose(bool disposing) { if (disposing && UserManager != null) { UserManager.Dispose(); UserManager = null; } base.Dispose(disposing); }
public AccountController(StoreUserManager userManager) { UserManager = userManager; }