Example #1
0
        public async Task <ActionResult> Test2()
        {
            UserManager    manager = ServiceProvider.GetService <UserManager>();
            IdentityResult result  = await manager.AddPasswordAsync(1, "gmf31529019");

            return(Content(result.ToJsonString()));
        }
Example #2
0
        public async Task <IActionResult> Test()
        {
            StringBuilder      sb          = new StringBuilder();
            string             token       = DateTime.Now.ToString("HHmmss");
            UserManager <User> userManager = _provider.GetService <UserManager <User> >();
            User user = new User()
            {
                UserName = $"gmf520{token}", Email = $"gmf520{token}@yeah.net"
            };
            IdentityResult result = await userManager.CreateAsync(user);

            sb.AppendLine(result.ToJsonString());

            //RoleManager<Role> roleManager = _provider.GetService<RoleManager<Role>>();
            //Role role = new Role() { Name = $"角色{token}" };
            //result = await roleManager.CreateAsync(role);
            //sb.AppendLine(result.ToJsonString());

            //result = await userManager.AddToRoleAsync(user, role.Name);
            //sb.AppendLine(result.ToJsonString());

            return(Content(sb.ToString()));
        }