Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Auto-Tenant Selection #1454


User avatar
0
thomas created

Hi,

Setup is for Multi-Tenancy: I´m trying to remove the tenant from the login view, so that the user only need to insert email and password. The application should know the tenant by the user-email.

I tried the following steps:

  1. get all users
  2. find user by email
  3. if ONE user was found, continue with login function
private async Task<AbpUserManager<Tenant, Role, User>.AbpLoginResult> GetLoginResultAsync(string usernameOrEmailAddress, string password, string tenancyName)
        {
            // try to get all user
            string sqlCommand = "SELECT * FROM USER";
            ObjectQuery<User> query = new ObjectQuery<User>(sqlCommand, context , MergeOption.NoTracking);

            var loginResult = await _userManager.LoginAsync(usernameOrEmailAddress, password, tenancyName);
            
          //....Login-Code

The problem is, that ObjectQuery needs an context object - from where I can use the context object?

Is there a better way to implement this function/way?

Thanks, Thomas


1 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    You can implement a custom repository for finding the user. Check this document <a class="postlink" href="http://aspnetboilerplate.com/Pages/Documents/Repositories#custom-repository-interface">http://aspnetboilerplate.com/Pages/Docu ... -interface</a>.

    But, if you want to use different databases for some of the tenant, then you will face some problems with this approach. You can use AbpUserAccounts table to find user, because it's in the host context.