private async Task AddUsers() { var adminUser = new IdentityUser(_guidGenerator.Create(), "administrator", "*****@*****.**"); adminUser.AddRole(_adminRole.Id); adminUser.AddClaim(_guidGenerator, new Claim("TestClaimType", "42")); await _userRepository.InsertAsync(adminUser); var john = new IdentityUser(_testData.UserJohnId, "john.nash", "*****@*****.**"); john.AddRole(_moderatorRole.Id); john.AddRole(_supporterRole.Id); john.AddOrganizationUnit(_ou111.Id); john.AddOrganizationUnit(_ou112.Id); john.AddLogin(new UserLoginInfo("github", "john", "John Nash")); john.AddLogin(new UserLoginInfo("twitter", "johnx", "John Nash")); john.AddClaim(_guidGenerator, new Claim("TestClaimType", "42")); john.SetToken("test-provider", "test-name", "test-value"); await _userRepository.InsertAsync(john); var david = new IdentityUser(_testData.UserDavidId, "david", "*****@*****.**"); david.AddOrganizationUnit(_ou112.Id); await _userRepository.InsertAsync(david); var neo = new IdentityUser(_testData.UserNeoId, "neo", "*****@*****.**"); neo.AddRole(_supporterRole.Id); neo.AddClaim(_guidGenerator, new Claim("TestClaimType", "43")); neo.AddOrganizationUnit(_ou111.Id); await _userRepository.InsertAsync(neo); }
private void AddUsers() { _adminUser = new IdentityUser(_guidGenerator.Create(), "administrator"); _adminUser.AddRole(_adminRole.Id); _userRepository.Insert(_adminUser); _john = new IdentityUser(_guidGenerator.Create(), "john.nash"); _john.AddRole(_moderator.Id); _john.AddRole(_supporterRole.Id); _userRepository.Insert(_john); _david = new IdentityUser(_guidGenerator.Create(), "david"); _userRepository.Insert(_david); }
public async Task HandleEventAsync(CreateEventData eventData) { using (CurrentTenant.Change(eventData.Id, eventData.Name)) { const string tenantAdminRoleName = "admin"; var tenantAdminRoleId = Guid.Empty;; if (!await IdentityRoleManager.RoleExistsAsync(tenantAdminRoleName)) { tenantAdminRoleId = GuidGenerator.Create(); var tenantAdminRole = new IdentityRole(tenantAdminRoleId, tenantAdminRoleName, eventData.Id) { IsStatic = true, IsPublic = true }; (await IdentityRoleManager.CreateAsync(tenantAdminRole)).CheckErrors(); } else { var tenantAdminRole = await IdentityRoleManager.FindByNameAsync(tenantAdminRoleName); tenantAdminRoleId = tenantAdminRole.Id; } var tenantAdminUser = await IdentityUserManager.FindByNameAsync(eventData.AdminEmailAddress); if (tenantAdminUser == null) { tenantAdminUser = new IdentityUser(eventData.AdminUserId, eventData.AdminEmailAddress, eventData.AdminEmailAddress, eventData.Id); tenantAdminUser.AddRole(tenantAdminRoleId); // 创建租户管理用户 (await IdentityUserManager.CreateAsync(tenantAdminUser)).CheckErrors(); (await IdentityUserManager.AddPasswordAsync(tenantAdminUser, eventData.AdminPassword)).CheckErrors(); } //var identitySeedResult = await IdentityDataSeeder // .SeedAsync(eventData.AdminEmailAddress, eventData.AdminPassword, eventData.Id); //if (!identitySeedResult.CreatedAdminUser) //{ // Logger.LogWarning("Tenant {0} admin user {1} not created!", eventData.Name, eventData.AdminEmailAddress); //} //if (!identitySeedResult.CreatedAdminRole) //{ // Logger.LogWarning("Tenant {0} admin role not created!", eventData.Name); //} } }