|
|
|
@ -1,8 +1,8 @@ |
|
|
|
using System.Security.Claims; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Microsoft.AspNetCore.Identity; |
|
|
|
using Volo.Abp.DependencyInjection; |
|
|
|
using Volo.Abp.Guids; |
|
|
|
using Volo.Abp.Threading; |
|
|
|
|
|
|
|
namespace Volo.Abp.Identity |
|
|
|
{ |
|
|
|
@ -35,31 +35,31 @@ namespace Volo.Abp.Identity |
|
|
|
_testData = testData; |
|
|
|
} |
|
|
|
|
|
|
|
public void Build() |
|
|
|
public async Task Build() |
|
|
|
{ |
|
|
|
AddRoles(); |
|
|
|
AddUsers(); |
|
|
|
AddClaimTypes(); |
|
|
|
await AddRoles(); |
|
|
|
await AddUsers(); |
|
|
|
await AddClaimTypes(); |
|
|
|
} |
|
|
|
|
|
|
|
private void AddRoles() |
|
|
|
private async Task AddRoles() |
|
|
|
{ |
|
|
|
_adminRole = AsyncHelper.RunSync(()=> _roleRepository.FindByNormalizedNameAsync(_lookupNormalizer.NormalizeName("admin"))); |
|
|
|
_adminRole = await _roleRepository.FindByNormalizedNameAsync(_lookupNormalizer.NormalizeName("admin")); |
|
|
|
|
|
|
|
_moderator = new IdentityRole(_testData.RoleModeratorId, "moderator"); |
|
|
|
_moderator.AddClaim(_guidGenerator, new Claim("test-claim", "test-value")); |
|
|
|
_roleRepository.Insert(_moderator); |
|
|
|
await _roleRepository.InsertAsync(_moderator); |
|
|
|
|
|
|
|
_supporterRole = new IdentityRole(_guidGenerator.Create(), "supporter"); |
|
|
|
_roleRepository.Insert(_supporterRole); |
|
|
|
await _roleRepository.InsertAsync(_supporterRole); |
|
|
|
} |
|
|
|
|
|
|
|
private void AddUsers() |
|
|
|
private async Task AddUsers() |
|
|
|
{ |
|
|
|
var adminUser = new IdentityUser(_guidGenerator.Create(), "administrator", "admin@abp.io"); |
|
|
|
adminUser.AddRole(_adminRole.Id); |
|
|
|
adminUser.AddClaim(_guidGenerator, new Claim("TestClaimType", "42")); |
|
|
|
_userRepository.Insert(adminUser); |
|
|
|
await _userRepository.InsertAsync(adminUser); |
|
|
|
|
|
|
|
var john = new IdentityUser(_testData.UserJohnId, "john.nash", "john.nash@abp.io"); |
|
|
|
john.AddRole(_moderator.Id); |
|
|
|
@ -68,23 +68,23 @@ namespace Volo.Abp.Identity |
|
|
|
john.AddLogin(new UserLoginInfo("twitter", "johnx", "John Nash")); |
|
|
|
john.AddClaim(_guidGenerator, new Claim("TestClaimType", "42")); |
|
|
|
john.SetToken("test-provider", "test-name", "test-value"); |
|
|
|
_userRepository.Insert(john); |
|
|
|
await _userRepository.InsertAsync(john); |
|
|
|
|
|
|
|
var david = new IdentityUser(_testData.UserDavidId, "david", "david@abp.io"); |
|
|
|
_userRepository.Insert(david); |
|
|
|
await _userRepository.InsertAsync(david); |
|
|
|
|
|
|
|
var neo = new IdentityUser(_testData.UserNeoId, "neo", "neo@abp.io"); |
|
|
|
neo.AddRole(_supporterRole.Id); |
|
|
|
neo.AddClaim(_guidGenerator, new Claim("TestClaimType", "43")); |
|
|
|
_userRepository.Insert(neo); |
|
|
|
await _userRepository.InsertAsync(neo); |
|
|
|
} |
|
|
|
|
|
|
|
private void AddClaimTypes() |
|
|
|
private async Task AddClaimTypes() |
|
|
|
{ |
|
|
|
var ageClaim = new IdentityClaimType(_testData.AgeClaimId, "Age", false, false, null, null, null,IdentityClaimValueType.Int); |
|
|
|
_identityClaimTypeRepository.Insert(ageClaim); |
|
|
|
await _identityClaimTypeRepository.InsertAsync(ageClaim); |
|
|
|
var educationClaim = new IdentityClaimType(_testData.EducationClaimId, "Education", true, false, null, null, null); |
|
|
|
_identityClaimTypeRepository.Insert(educationClaim); |
|
|
|
await _identityClaimTypeRepository.InsertAsync(educationClaim); |
|
|
|
} |
|
|
|
} |
|
|
|
} |