public async Task Should_Link_User_To_Already_Linked_User() { //Arrange LoginAsHostAdmin(); var testTenantId = await CreateTestTenantAndTestUser(); LoginAsDefaultTenantAdmin(); await CreateTestUsersForAccountLinkingAsync(); var linkToTestTenantUserInput = new LinkToUserInput { TenancyName = "Test", UsernameOrEmailAddress = "test", Password = "******" }; //Act //Link Default\admin -> Test\test await _userLinkAppService.LinkToUser(linkToTestTenantUserInput); LoginAsTenant(AbpTenantBase.DefaultTenantName, "jnash"); //Link Default\jnash->Test\test await _userLinkAppService.LinkToUser(linkToTestTenantUserInput); //Assert var defaultTenantAdmin = await UsingDbContextAsync(context => context.Users.FirstOrDefaultAsync(u => u.TenantId == AbpSession.TenantId && u.UserName == AbpUserBase.AdminUserName)); var defaultTenantAdminAccount = await _userLinkManager.GetUserAccountAsync(defaultTenantAdmin.ToUserIdentifier()); var jnash = await UsingDbContextAsync(context => context.Users.FirstOrDefaultAsync(u => u.UserName == "jnash")); var jnashAccount = await _userLinkManager.GetUserAccountAsync(jnash.ToUserIdentifier()); var testTenantUser = await UsingDbContextAsync(testTenantId, context => context.Users.FirstOrDefaultAsync(u => u.UserName == "test")); var testTenantUserAccount = await _userLinkManager.GetUserAccountAsync(testTenantUser.ToUserIdentifier()); jnashAccount.UserLinkId.ShouldBe(jnashAccount.Id); defaultTenantAdminAccount.UserLinkId.ShouldBe(jnashAccount.Id); testTenantUserAccount.UserLinkId.ShouldBe(jnashAccount.Id); jnashAccount.UserLinkId.ShouldBe(defaultTenantAdminAccount.UserLinkId); jnashAccount.UserLinkId.ShouldBe(testTenantUserAccount.UserLinkId); }
public async Task LinkToUser(LinkToUserInput input) { var loginResult = await _logInManager.LoginAsync(input.UsernameOrEmailAddress, input.Password, input.TenancyName); if (loginResult.Result != AbpLoginResultType.Success) { throw _abpLoginResultTypeHelper.CreateExceptionForFailedLoginAttempt(loginResult.Result, input.UsernameOrEmailAddress, input.TenancyName); } if (AbpSession.IsUser(loginResult.User)) { throw new UserFriendlyException(L("YouCannotLinkToSameAccount")); } if (loginResult.User.ShouldChangePasswordOnNextLogin) { throw new UserFriendlyException(L("ChangePasswordBeforeLinkToAnAccount")); } await _userLinkManager.Link(GetCurrentUser(), loginResult.User); }
public async Task LinkToUser(LinkToUserInput input) { using (UnitOfWorkManager.Current.DisableFilter(AbpDataFilters.MayHaveTenant)) { var loginResult = await UserManager.LoginAsync(input.UsernameOrEmailAddress, input.Password, input.TenancyName); if (loginResult.Result != AbpLoginResultType.Success) { throw _abpLoginResultTypeHelper.CreateExceptionForFailedLoginAttempt(loginResult.Result, input.UsernameOrEmailAddress, input.TenancyName); } if (loginResult.User.Id == AbpSession.GetUserId()) { throw new UserFriendlyException(L("YouCannotLinkToSameAccount")); } if (loginResult.User.ShouldChangePasswordOnNextLogin) { throw new UserFriendlyException(L("ChangePasswordBeforeLinkToAnAccount")); } await _userLinkManager.Link(AbpSession.GetUserId(), loginResult.User.Id); } }
public async Task Should_Link_User_To_Already_Linked_User() { //Arrange LoginAsHostAdmin(); await CreateTestTenantAndTestUser(); LoginAsDefaultTenantAdmin(); CreateTestUsers(); var linkToTestTenantUserInput = new LinkToUserInput { TenancyName = "Test", UsernameOrEmailAddress = "test", Password = "******" }; //Act //Link Default\admin -> Test\test await _userLinkAppService.LinkToUser(linkToTestTenantUserInput); LoginAsTenant(Tenant.DefaultTenantName, "jnash"); //Link Default\jnash->Test\test await _userLinkAppService.LinkToUser(linkToTestTenantUserInput); //Assert await UsingDbContextAsync(async context => { var defaultTenantAdmin = await context.Users.FirstOrDefaultAsync(u => u.Id == AbpSession.UserId); var jnash = await context.Users.FirstOrDefaultAsync(u => u.UserName == "jnash"); var testTenantUser = await context.Users.FirstOrDefaultAsync(u => u.UserName == "test"); jnash.UserLinkId.ShouldBe(jnash.Id); defaultTenantAdmin.UserLinkId.ShouldBe(jnash.Id); testTenantUser.UserLinkId.ShouldBe(jnash.Id); }); }