Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Sri Nistala 1 post 71 karma points
    Apr 08, 2023 @ 09:28
    Sri Nistala
    0

    Umbraco Cloud Member Login Not Working

    I'm setting up a protected website on Umbraco Cloud Sandbox and followed the steps in this tutorial https://docs.umbraco.com/umbraco-cms/tutorials/members-registration-and-login

    My login macro snippet has the following code. I have not made any code changes, just used out of box Umbraco Cloud. I have set up a member group and added a member and would like to use local Umbraco users. The login doesn't seem to be working.

    When I click the submit button, I stay on the login screen and the login status is always "not logged in".

    I'm new to Umbraco and using this as a proof of concept for an application I'm building. Please help!

    @inherits Umbraco.Cms.Web.Common.Macros.PartialViewMacroPage
    
    
    @using Umbraco.Cms.Web.Common.Models
    @using Umbraco.Cms.Web.Common.Security
    @using Umbraco.Cms.Web.Website.Controllers
    @using Umbraco.Cms.Core.Services
    @using Umbraco.Extensions
    @inject IMemberExternalLoginProviders memberExternalLoginProviders
    @inject ITwoFactorLoginService twoFactorLoginService
    @{
        var loginModel = new LoginModel();
        // You can modify this to redirect to a different URL instead of the current one
        loginModel.RedirectUrl = "/";
    }
    
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.0/jquery.validate.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validation-unobtrusive/3.2.11/jquery.validate.unobtrusive.min.js"></script>
    
    
    @if (ViewData.TryGetTwoFactorProviderNames(out var providerNames))
    {
    
        foreach (var providerName in providerNames)
        {
            <div class="2fa-form">
                <h4>Two factor with @providerName.</h4>
                <div asp-validation-summary="All" class="text-danger"></div>
                @using (Html.BeginUmbracoForm<UmbTwoFactorLoginController>(nameof(UmbTwoFactorLoginController.Verify2FACode)))
                {
    
                    <text>
                        <input type="hidden" name="provider" value="@providerName"/>
                        Input security code: <input name="code" value=""/><br/>
                        <button type="submit" class="btn btn-primary">Validate</button>
                        <div asp-validation-summary="ModelOnly" class="text-danger"></div>
                    </text>
                }
            </div>
        }
    
    }
    else
    {
    
    
    <div class="login-form">
    
        @using (Html.BeginUmbracoForm<UmbLoginController>(
            "HandleLogin", new { RedirectUrl = loginModel.RedirectUrl })) {
    
                <h4>Log in with a local account.</h4>
                <hr />
                <div asp-validation-summary="ModelOnly" class="text-danger"></div>
                <div class="mb-3">
                    <label asp-for="@loginModel.Username" class="form-label"></label>
                    <input asp-for="@loginModel.Username" class="form-control" />
                    <span asp-validation-for="@loginModel.Username" class="form-text text-danger"></span>
                </div>
                <div class="mb-3">
                    <label asp-for="@loginModel.Password" class="form-label"></label>
                    <input asp-for="@loginModel.Password" class="form-control" />
                    <span asp-validation-for="@loginModel.Password" class="form-text text-danger"></span>
                </div>
                <div class="mb-3 form-check">
                    <input asp-for="@loginModel.RememberMe" class="form-check-input">
                    <label asp-for="@loginModel.RememberMe" class="form-check-label">
                        @Html.DisplayNameFor(m => loginModel.RememberMe)
                    </label>
                </div>
    
                <button type="submit" class="btn btn-primary">Log in</button>
    
    
            }
    @{
        var loginProviders = await memberExternalLoginProviders.GetMemberProvidersAsync();
        var externalSignInError = ViewData.GetExternalSignInProviderErrors();
    
        if (loginProviders.Any())
        {
            <hr/>
            <h4>Or using external providers</h4>
            if (externalSignInError?.AuthenticationType is null && externalSignInError?.Errors.Any() == true)
            {
                @Html.DisplayFor(x => externalSignInError.Errors);
            }
    
            @foreach (var login in await memberExternalLoginProviders.GetMemberProvidersAsync())
            {
    
                @using (Html.BeginUmbracoForm<UmbExternalLoginController>(nameof(UmbExternalLoginController.ExternalLogin)))
                {
                    <button type="submit" name="provider" value="@login.ExternalLoginProvider.AuthenticationType">
                        Sign in with @login.AuthenticationScheme.DisplayName
                    </button>
    
                    if (externalSignInError?.AuthenticationType == login.ExternalLoginProvider.AuthenticationType)
                    {
                        @Html.DisplayFor(x => externalSignInError.Errors);
                    }
                }
            }
        }
    }
    </div>
    }
    
  • girish 14 posts 87 karma points
    Aug 02, 2024 @ 06:59
    girish
    0

    To troubleshoot your Umbraco Cloud member login issue, let's go through some common potential problems and solutions:

    Member Group Configuration: Ensure that the member you are trying to log in with is correctly assigned to the appropriate member group. Go to the Members section in the Umbraco backoffice, find your member, and verify that the member belongs to the correct group.

    User Credentials: Double-check the username and password for the member. Make sure the member's account is active and not locked.

    Redirection Issues: Sometimes, the redirection URL might cause issues. In your loginModel, you're setting RedirectUrl to "/". Try changing it to another valid URL within your application to see if that resolves the issue.

    Validation Summary: Check if any validation errors are being shown. You have an asp-validation-summary="ModelOnly" in your code, but it might not be displaying the errors clearly. Ensure you have proper error handling and display in place.

    Form Submission: Verify that the form is submitting correctly. Use browser developer tools (F12) to inspect the network requests and console logs when you click the submit button. Look for any errors or issues in the console or network tab.

    Check the Umbraco Log: The Umbraco log files can provide detailed information about what is going wrong. Check the logs in the App_Data/Logs folder for any errors related to member login.

    Here's a revised version of your login form with additional checks and messages for better debugging:

    @inherits Umbraco.Cms.Web.Common.Macros.PartialViewMacroPage
    @using Umbraco.Cms.Web.Common.Models
    @using Umbraco.Cms.Web.Common.Security
    @using Umbraco.Cms.Web.Website.Controllers
    @using Umbraco.Cms.Core.Services
    @using Umbraco.Extensions
    @inject IMemberExternalLoginProviders memberExternalLoginProviders
    @inject ITwoFactorLoginService twoFactorLoginService
    @{
        var loginModel = new LoginModel();
        loginModel.RedirectUrl = "/";
    }
    
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.0/jquery.validate.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validation-unobtrusive/3.2.11/jquery.validate.unobtrusive.min.js"></script>
    
    @if (ViewData.TryGetTwoFactorProviderNames(out var providerNames))
    {
        foreach (var providerName in providerNames)
        {
            <div class="2fa-form">
                <h4>Two factor with @providerName.</h4>
                <div asp-validation-summary="All" class="text-danger"></div>
                @using (Html.BeginUmbracoForm<UmbTwoFactorLoginController>(nameof(UmbTwoFactorLoginController.Verify2FACode)))
                {
                    <text>
                        <input type="hidden" name="provider" value="@providerName"/>
                        Input security code: <input name="code" value=""/><br/>
                        <button type="submit" class="btn btn-primary">Validate</button>
                        <div asp-validation-summary="ModelOnly" class="text-danger"></div>
                    </text>
                }
            </div>
        }
    }
    else
    {
        <div class="login-form">
            @using (Html.BeginUmbracoForm<UmbLoginController>("HandleLogin", new { RedirectUrl = loginModel.RedirectUrl }))
            {
                <h4>Log in with a local account.</h4>
                <hr />
                <div asp-validation-summary="ModelOnly" class="text-danger"></div>
                <div class="mb-3">
                    <label asp-for="@loginModel.Username" class="form-label"></label>
                    <input asp-for="@loginModel.Username" class="form-control" />
                    <span asp-validation-for="@loginModel.Username" class="form-text text-danger"></span>
                </div>
                <div class="mb-3">
                    <label asp-for="@loginModel.Password" class="form-label"></label>
                    <input asp-for="@loginModel.Password" class="form-control" />
                    <span asp-validation-for="@loginModel.Password" class="form-text text-danger"></span>
                </div>
                <div class="mb-3 form-check">
                    <input asp-for="@loginModel.RememberMe" class="form-check-input">
                    <label asp-for="@loginModel.RememberMe" class="form-check-label">
                        @Html.DisplayNameFor(m => loginModel.RememberMe)
                    </label>
                </div>
                <button type="submit" class="btn btn-primary">Log in</button>
            }
    
            @* Display any login errors *@
            @if (ViewData["LoginErrorMessage"] != null)
            {
                <div class="alert alert-danger">
                    @ViewData["LoginErrorMessage"]
                </div>
            }
    
            @* Display external login providers *@
            @{
                var loginProviders = await memberExternalLoginProviders.GetMemberProvidersAsync();
                var externalSignInError = ViewData.GetExternalSignInProviderErrors();
    
                if (loginProviders.Any())
                {
                    <hr/>
                    <h4>Or using external providers</h4>
                    if (externalSignInError?.AuthenticationType is null && externalSignInError?.Errors.Any() == true)
                    {
                        @Html.DisplayFor(x => externalSignInError.Errors);
                    }
    
                    @foreach (var login in loginProviders)
                    {
                        @using (Html.BeginUmbracoForm<UmbExternalLoginController>(nameof(UmbExternalLoginController.ExternalLogin)))
                        {
                            <button type="submit" name="provider" value="@login.ExternalLoginProvider.AuthenticationType">
                                Sign in with @login.AuthenticationScheme.DisplayName
                            </button>
    
                            if (externalSignInError?.AuthenticationType == login.ExternalLoginProvider.AuthenticationType)
                            {
                                @Html.DisplayFor(x => externalSignInError.Errors);
                            }
                        }
                    }
                }
            }
        </div>
    }
    

    If the issue persists, check the form submission details using developer tools to see if the form is submitting correctly, and verify any error messages in the console or network tab. This will give you more insight into what might be going wrong.

Please Sign in or register to post replies

Write your reply to:

Draft