Open Closed

Tenant field not being hided even implemented custom tenant resolver #9097


User avatar
0
JimmyLiew created

I have implemented my own custom tenant resolver(Please refers screenshot below). My question is why the tenant field still visible even i have resolved the tenant in my custom tenant resolver? Did I miss anything in the implementation? How can I hide the tenant field once the custom tenant resolver successfully identifies the tenant?

Thanks.


2 Answer(s)
  • User Avatar
    0
    berkansasmaz created
    Support Team .NET Developer

    For this, you can override the Login page and remove the relevant code blocks. You can follow the steps below to override the login page.

    1-) Create Account folder in Pages folder like below:

    2-) Create Login.cshtml file in Account folder in your AuthServer.

    3-) Update Login.cshtml file like below:

    @page
    @using Microsoft.AspNetCore.Mvc.Localization
    @using Microsoft.Extensions.Options
    @using Owl.reCAPTCHA
    @using Volo.Abp.Account.Localization
    @using Volo.Abp.Account.Public.Web.Pages.Account;
    @using Volo.Abp.Account.Public.Web.Security.Recaptcha
    @using Volo.Abp.Account.Settings
    @using Volo.Abp.Identity;
    @using Volo.Abp.Settings
    @model Volo.Abp.Account.Public.Web.Pages.Account.LoginModel
    @inject IHtmlLocalizer<AccountResource> L
    @inject Volo.Abp.AspNetCore.Mvc.UI.Layout.IPageLayout PageLayout
    @inject ISettingProvider SettingProvider
    @{
        PageLayout.Content.Title = L["Login"].Value;
        var reCaptchaVersion = await SettingProvider.GetAsync<int>(AccountSettingNames.Captcha.Version);
        if (Model.UseCaptcha)
        {
            await Model.ReCaptchaOptions.SetAsync(reCaptchaVersion == 3 ? reCAPTCHAConsts.V3 : reCAPTCHAConsts.V2);
        }
    
    }
    
    @section scripts
        {
        <abp-script-bundle name="@typeof(LoginModel).FullName">
            <abp-script src="/Pages/Account/Login.js" />
        </abp-script-bundle>
    
        @if (Model.UseCaptcha)
        {
            if (reCaptchaVersion == 3)
            {
                <recaptcha-script-v3 />
                <recaptcha-script-v3-js action="login" execute="false" />
            }
            else
            {
                <recaptcha-script-v2 />
            }
        }
    }
    
    @if (Model.IsLinkLogin)
    {
        <abp-alert alert-type="Warning">
            @L["LinkAccountWarning", Url.PageLink()]
        </abp-alert>
    }
    
    @if (Model.BackToExternalLogins)
    {
        <div class="d-grid gap-2">
            <a class="mb-3 btn btn-primary btn-block" href="@Url.Page("./ExternalLogins")">@L["Back"]</a>
        </div>
    }
    
    @if (Model.ShowRequireMigrateSeedMessage)
    {
        <div class="alert alert-danger">
            <h4 class="alert-heading">@L["RequireMigrateSeedTitle"]</h4>
            <p>@L["RequireMigrateSeedMessage"]</p>
        </div>
    }
    
    <div class="account-module-form">
    
        @if (Model.IsSelfRegistrationEnabled)
        {
            <h5 class="mb-2">@L["NotAMemberYet"] <a class="text-decoration-none" href="@Url.Page("./Register", new {returnUrl = Model.ReturnUrl, returnUrlHash = Model.ReturnUrlHash})">@L["Register"]</a></h5>
        }
    
        @if (Model.EnableLocalLogin)
        {
            <form method="post" id="loginForm">
                @if (Model.UseCaptcha)
                {
                    <input class="mb-3" data-captcha="true" type="hidden" name="@RecaptchaValidatorBase.RecaptchaResponseKey" id="@RecaptchaValidatorBase.RecaptchaResponseKey"/>
                }
                <div>
                    <div class="form-floating mb-2">
                        <input asp-for="LoginInput.UserNameOrEmailAddress" type="text" class="form-control" placeholder="name@example.com">
                        @Html.LabelFor(m => m.LoginInput.UserNameOrEmailAddress)
                        <span asp-validation-for="LoginInput.UserNameOrEmailAddress"/>
                    </div>
    
                    <div class="form-floating mb-2">
                        <input asp-for="LoginInput.Password" id="password-input" type="password" class="form-control" placeholder="Password">
                        @Html.LabelFor(m => m.LoginInput.Password)
                        <i id="PasswordVisibilityButton" class="bi bi-eye-slash show-pass-icon" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-html="true" aria-label="@L["ShowPassword"]" data-bs-original-title="@L["ShowPassword"]"></i>
                        <i id="capslockicon" class="bi bi-capslock caps-lock-icon" style="display: none;" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-html="true" aria-label="<i class='bi bi-exclamation-circle'></i> @L["CapsLockOn"]!" data-bs-original-title="<i class='bi bi-exclamation-circle'></i> @L["CapsLockOn"]!"></i>
                        <span asp-validation-for="LoginInput.Password"/>
                    </div>
                </div>
                <abp-row>
                    <abp-column>
                        <div class="form-switch ps-2">
                            <abp-input asp-for="LoginInput.RememberMe" class="mb-4"/>
                        </div>
                    </abp-column>
                    <abp-column class="text-end">
                        <a href="@Url.Page("./ForgotPassword", new {returnUrl = Model.ReturnUrl, returnUrlHash = Model.ReturnUrlHash})">@L["ForgotPassword"]</a>
                    </abp-column>
                </abp-row>
    
                @if (reCaptchaVersion == 2)
                {
                    <script>
                        recaptchaCallback = function (token) {
                            $('form button[type=submit]').removeAttr("disabled");
                            $('#@RecaptchaValidatorBase.RecaptchaResponseKey').val(token)
                        };
                    </script>
                    <div class="mb-3">
                        <recaptcha-div-v2 callback="recaptchaCallback"/>
                    </div>
                }
    
                <div class="d-grid gap-2">
                    <abp-button button-type="Primary" type="submit" class="mb-3" name="Action" value="Login" disabled="true">
                        <i class="bi bi-box-arrow-in-right me-1"></i>
                        @L["Login"]
                    </abp-button>
                </div>
    
                @if (Model.ShowCancelButton)
                {
                    <div class="d-grid gap-2">
                        <abp-button button-type="Secondary" type="submit" formnovalidate="formnovalidate" class="mb-3" name="Action" value="Cancel">@L["Cancel"]</abp-button>
                    </div>
                }
            </form>
        }
    
        @if (Model.VisibleExternalProviders.Any())
        {
            if(Model.EnableLocalLogin)
            {
                <hr/>
                @L["OrSignInWith"]
                <br/>
            }
            else
            {
                @L["SignInWithOneOfTheFollowingProviders"]
            }
    
            <form asp-page="./Login" asp-page-handler="ExternalLogin"
                  asp-route-returnUrl="@Model.ReturnUrl"
                  asp-route-returnUrlHash="@Model.ReturnUrlHash"
                  asp-route-linkTenantId="@Model.LinkTenantId"
                  asp-route-linkUserId="@Model.LinkUserId"
                  asp-route-linkToken="@Model.LinkToken"
                  method="post">
                @foreach (var provider in Model.VisibleExternalProviders)
                {
                    <button type="submit"
                            class="mt-2 me-2 btn btn-outline-primary btn-sm"
                            name="provider"
                            value="@provider.AuthenticationScheme"
                            data-busy-text="@L["ProcessingWithThreeDot"]">
                        @if (provider.Icon != null)
                        {
                            <i class="@provider.Icon"></i>
                        }
                        <span>@provider.DisplayName</span>
                    </button>
                }
            </form>
        }
    </div>
    

    You can then customize it any way you want. If you have a specific question in the implementation, you can ask.

  • User Avatar
    0
    JimmyLiew created

    Hi,

    Thanks for the code! I'll tailor it to fit my specific needs.

    Thanks.

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
Do you need assistance from an ABP expert?
Schedule a Meeting
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v9.3.0-preview. Updated on April 16, 2025, 12:13