private static void CreateUsers(XAppDbContext context) { var users = new List <XUser> { new XUser { FirstName = "K", LastName = "KK", UserName = "******", Email = "*****@*****.**", Address = "addr 0 wro", CreationDate = DateTime.Parse("2017-11-22") }, new XUser { FirstName = "Carson", LastName = "Alexander", UserName = "******", Address = "addr 1x", CreationDate = DateTime.Parse("2017-11-22") }, new XUser { FirstName = "Meredith", LastName = "Alonso", UserName = "******", Address = "addr 2x", CreationDate = DateTime.Parse("2017-11-22") } }; users.ForEach(u => context.Users.AddOrUpdate(uu => uu.UserName, u)); context.SaveChanges(); var userManager = new XUserManager(new UserStore <XUser, XRole, long, XLogin, XUserRole, XClaim>(context), new IdentityFactoryOptions <XUserManager>()); var roleManager = new XRoleManager(new RoleStore <XRole, long, XUserRole>(context), new IdentityFactoryOptions <XRoleManager>()); var superPowerUser = new XUser { UserName = "******", Email = "*****@*****.**", FirstName = "Admin", LastName = "Power", CreationDate = DateTime.Parse("2017-11-24") }; userManager.Create(superPowerUser, "P@ssw0rd"); var krzyhook = userManager.FindByName("krzyhook"); if (krzyhook.PasswordHash == null) { userManager.AddPassword(krzyhook.Id, "P@ssw0rd"); } if (!roleManager.Roles.Any()) { roleManager.Create(new XRole { Name = "SuperAdmin" }); roleManager.Create(new XRole { Name = "Admin" }); roleManager.Create(new XRole { Name = "User" }); } var adminUser = userManager.FindByName(superPowerUser.UserName); userManager.AddToRoles(adminUser.Id, new string[] { "SuperAdmin", "Admin" }); var krzyhookUser = userManager.FindByName(krzyhook.UserName); userManager.AddToRoles(krzyhookUser.Id, new string[] { "User" }); }
public async Task <ClaimsIdentity> GenerateUserIdentityAsync(XUserManager userManager, string authenticationType) { var userIdentity = await userManager.CreateIdentityAsync(this, authenticationType); //var userIdentity = await userManager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); // Add custom user claims here return(userIdentity); }
public IdentityController(IUserService userService, XUserManager userManager, XRoleManager roleManager) { this.userService = userService; this.userManager = userManager; this.roleManager = roleManager; }
public UserService(XAppDbContext dbContext, XUserManager userManager) { this.db = dbContext; this.userManager = userManager; }