If you're creating a bug/problem report, please include followings:
- ABP Framework version: v7
-
- UI type: Angular
- DB provider: EF Core
- Tiered (MVC) or Identity Server Separated (Angular): yes
- Exception message and stack trace:
- Steps to reproduce the issue:"
i need the explanation on how to hide tenant switch step by step and i also need when the user sign in , the system directoly knows which tenant im in without selecting a tenant .
5 Answer(s)
-
1
hide tenant switch
You can remove the
CookieTenantResolveContributor
Configure<AbpTenantResolveOptions>(options => { options.TenantResolvers.RemoveAll((x => x.Name == CookieTenantResolveContributor.ContributorName)); });
the system directoly knows which tenant
You can custom the
LoginModel
. for example:[ExposeServices(typeof(LoginModel))] public class MyLoginModel : OpenIddictSupportedLoginModel { private readonly ITenantRepository _tenantRepository; public MyLoginModel( IAuthenticationSchemeProvider schemeProvider, IOptions<AbpAccountOptions> accountOptions, IAbpRecaptchaValidatorFactory recaptchaValidatorFactory, IAccountExternalProviderAppService accountExternalProviderAppService, ICurrentPrincipalAccessor currentPrincipalAccessor, IOptions<IdentityOptions> identityOptions, IOptionsSnapshot<reCAPTCHAOptions> reCaptchaOptions, AbpOpenIddictRequestHelper openIddictRequestHelper, ITenantRepository tenantRepository) : base(schemeProvider, accountOptions, recaptchaValidatorFactory, accountExternalProviderAppService, currentPrincipalAccessor, identityOptions, reCaptchaOptions, openIddictRequestHelper) { _tenantRepository = tenantRepository; } public async override Task<IActionResult> OnPostAsync(string action) { using (CurrentTenant.Change(await FindTenantByUser())) { return await base.OnPostAsync(action); } } private async Task<Guid?> FindTenantByUser() { var tenants = await _tenantRepository.GetListAsync(); foreach (var tenant in tenants) { using(CurrentTenant.Change(tenant.Id)) { ///...Find User and return the TenantId } } return null; } }
-
0
in which file should i write this code
Configure<AbpTenantResolveOptions>(options => { options.TenantResolvers.RemoveAll((x => x.Name == CookieTenantResolveContributor.ContributorName)); });
-
0
The authserver project.
-
0
hide tenant switch
You can remove the
CookieTenantResolveContributor
Configure<AbpTenantResolveOptions>(options => { options.TenantResolvers.RemoveAll((x => x.Name == CookieTenantResolveContributor.ContributorName)); });
the system directoly knows which tenant
You can custom the
LoginModel
. for example:[ExposeServices(typeof(LoginModel))] public class MyLoginModel : OpenIddictSupportedLoginModel { private readonly ITenantRepository _tenantRepository; public MyLoginModel( IAuthenticationSchemeProvider schemeProvider, IOptions<AbpAccountOptions> accountOptions, IAbpRecaptchaValidatorFactory recaptchaValidatorFactory, IAccountExternalProviderAppService accountExternalProviderAppService, ICurrentPrincipalAccessor currentPrincipalAccessor, IOptions<IdentityOptions> identityOptions, IOptionsSnapshot<reCAPTCHAOptions> reCaptchaOptions, AbpOpenIddictRequestHelper openIddictRequestHelper, ITenantRepository tenantRepository) : base(schemeProvider, accountOptions, recaptchaValidatorFactory, accountExternalProviderAppService, currentPrincipalAccessor, identityOptions, reCaptchaOptions, openIddictRequestHelper) { _tenantRepository = tenantRepository; } public async override Task<IActionResult> OnPostAsync(string action) { using (CurrentTenant.Change(await FindTenantByUser())) { return await base.OnPostAsync(action); } } private async Task<Guid?> FindTenantByUser() { var tenants = await _tenantRepository.GetListAsync(); foreach (var tenant in tenants) { using(CurrentTenant.Change(tenant.Id)) { ///...Find User and return the TenantId } } return null; } }
How I to find the user and return TenantId??
-
0
How I to find the user and return TenantId??
For example:
private async Task<Guid?> FindTenantByUser() { var tenants = await _tenantRepository.GetListAsync(); foreach (var tenant in tenants) { using(CurrentTenant.Change(tenant.Id)) { var user = await UserManager.FindByEmailAsync(LoginInput.UserNameOrEmailAddress) ?? await UserManager.FindByNameAsync(LoginInput.UserNameOrEmailAddress); if (user != null) { if (await UserManager.CheckPasswordAsync(user, LoginInput.Password)) { return tenant.Id; } } } } return null; }
- Find the user by email&username and check the password if user exists
ABP Login Hiding Tenant + checking the user in which tenant to sign in Directly
This code does not work if users under different tenants have the same email and password According to your needs, I think this is unavoidable