Copied to clipboard

Flag this post as spam?

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


  • Adriano Fabri 416 posts 1433 karma points
    Jul 07, 2021 @ 14:19
    Adriano Fabri
    0

    LoginForm Snippet return english messages instead of localized messages

    Hi,

    I'm using Umbraco 8 and I set my website with italian culture. All function properly except the login form messages.

    I create a partial view based on the available snippets.

    <div class="container">
    <div class="row">
        <div class="col-2"></div>
        <div class="col-8">
            <h6 style="margin-top:50px; margin-bottom:25px; text-align:center; color:#444;">Per accedere, inserisci le credenziali che ti abbiamo inviato.</h6>
            @using (Html.BeginUmbracoForm<UmbLoginController>("HandleLogin"))
            {
                <fieldset>
                    @Html.ValidationSummary("loginModel", true)
    
                    <div class="mb-3">
                        @Html.TextBoxFor(m => loginModel.Username, new { placeholder = "Nome utente", @class = "form-control" })
                    </div>
                    <div class="mb-3">
                        @Html.PasswordFor(m => loginModel.Password, new { placeholder = "Password", @class = "form-control" })
                    </div>
                    <div class="d-grid gap-2 col-6 mx-auto">
                        @Html.HiddenFor(m => loginModel.RedirectUrl)
                        <button name="login" type="submit" class="btn btn-secondary">Accedi</button>
                    </div>
                </fieldset>
            }
        </div>
        <div class="col-2"></div>
    </div>
    </div>
    

    How can I localize those messages without creating a custom login form?

    Thanks

    A.

  • marina.b 11 posts 101 karma points
    Jul 07, 2021 @ 14:25
    marina.b
    0

    Hi Adriano,

    are you referring to the system messages? I think you can solve it by checking the dictionary and adding the Italian translation.

    M.

  • Adriano Fabri 416 posts 1433 karma points
    Jul 07, 2021 @ 14:55
    Adriano Fabri
    0

    Hi Marina,

    Yes is a system message but I think that there is no solution about that, because I just saw the relative method Umbraco.Web.Controllers.UmbLoginController.HandleLogin(LoginModel model) and the returned message is a simple english message and not a localized message

    [HttpPost]
    [ValidateAntiForgeryToken]
    [ValidateUmbracoFormRouteString]
    public ActionResult HandleLogin([Bind(Prefix = "loginModel")]LoginModel model)
    {
        if (ModelState.IsValid == false)
        {
            return CurrentUmbracoPage();
        }
        if (Members.Login(model.Username, model.Password) == false)
        {
            //don't add a field level error, just model level
            ModelState.AddModelError("loginModel", "Invalid username or password");
            return CurrentUmbracoPage();
        }
    
        TempData["LoginSuccess"] = true;
    
        //if there is a specified path to redirect to then use it
        if (model.RedirectUrl.IsNullOrWhiteSpace() == false)
        {
            // validate the redirect URL
            // if it's not a local URL we'll redirect to the root of the current site
            return Redirect(Url.IsLocalUrl(model.RedirectUrl)
                ? model.RedirectUrl
                : CurrentPage.AncestorOrSelf(1).Url());
        }
    
        //redirect to current page by default
    
        return RedirectToCurrentUmbracoPage();
    }
    

    I think the only solution is that I create a custom login form.

    A.

  • Yakov Lebski 440 posts 1694 karma points
    Jul 07, 2021 @ 14:58
    Yakov Lebski
    0

    You can use https://our.umbraco.com/packages/developer-tools/umbraco-dictionary-metadataprovider/

    just create Dictonary in relevant language

    Login Login.PROPERTY_NAME = username

    PROPERTY_NAME - property name in model

  • Adriano Fabri 416 posts 1433 karma points
    Jul 07, 2021 @ 15:09
    Adriano Fabri
    0

    Hi Yakov,

    the problem isn't the property name, but the Html.ValidationSummary's messages.

    This is my login form (no problem with this)

    Login Form

    This is the error I received with invalid credentials (no localized)

    Login Form - Error credentials

    As you can see, I received an "Invalid username or password" error message but I would to see that message in italian...but as I wrote, I saw that the HandleLogin method return only a simple text and not a localized text (see above)

    A.

  • marina.b 11 posts 101 karma points
    Jul 07, 2021 @ 15:22
    marina.b
    0

    If your site is in Italian only, you can translate the message directly in the code.

     if (Members.Login(model.Username, model.Password) == false)
    {
        //don't add a field level error, just model level
        ModelState.AddModelError("loginModel", "Invalid username or password");
        return CurrentUmbracoPage();
    }
    

    M.

  • Adriano Fabri 416 posts 1433 karma points
    Jul 07, 2021 @ 15:40
    Adriano Fabri
    100

    Marina...the Umbraco.Web.Controllers.UmbLoginController.HandleLogin(LoginModel model) is an Umbraco Core method.

    I should change the Umbraco Core method and re-compile all umbraco website...unthinkable.

    I think that is more secure and flexible to create a custom login form with a custom surface controller to manage the login.

    A.

  • Yakov Lebski 440 posts 1694 karma points
    Jul 07, 2021 @ 15:30
    Yakov Lebski
    1

    I think you are right need to create new controller for it

  • Adriano Fabri 416 posts 1433 karma points
    Jul 07, 2021 @ 15:41
    Adriano Fabri
    0

    Yep...I think so!!!

  • Yakov Lebski 440 posts 1694 karma points
    Jul 07, 2021 @ 17:05
    Yakov Lebski
    1

    create your custom controller, don't change umbraco code

Please Sign in or register to post replies

Write your reply to:

Draft