отображать div при неудачной авторизации в html, используя Umbraco amd MVC - PullRequest
0 голосов
/ 11 июня 2019

У меня есть div, в котором я хочу отображать сообщение об ошибке входа в систему только при попытке неудачного входа в систему. Звонок для входа в систему

[HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult HandleLoginSubmit(LoginModel model)
        {
            if (!ModelState.IsValid)
            {
                return CurrentUmbracoPage();
            }

            if (Membership.ValidateUser(model.Username, model.Password))
            {
                FormsAuthentication.SetAuthCookie(model.Username, createPersistentCookie: false);
                return Redirect(model.ReturnUrl ?? "/login");

            }
            else
            {

                ModelState.AddModelError(nameof(model.Username), "Incorrect UserName");
                ModelState.AddModelError(nameof(model.Password), "Incorrect password");
                return CurrentUmbracoPage();


            }
        }

и div

<div class="col-lg-10 alert alert-danger justify-content-around mt-2" style="margin-left:auto; margin-right:auto;">
            <div class="container">
                <div class="alert-icon">
                    <i class="material-icons">error_outline</i>
                </div>
                <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                    <span aria-hidden="true"><i class="material-icons">clear</i></span>
                </button>
                <b>Error Alert: </b>
            </div>
        </div>

Что я должен вернуться из звонка, если вход в систему успешен, и как я могу ссылаться на него в html?

1 Ответ

0 голосов
/ 11 июня 2019

Похоже, ваша версия Umbraco - 7.x.Со следующим именем контроллера и именем метода, например:

public class RecoverUserDataSurfaceController : SurfaceControllerBaseController
{ 
    [HttpPost]
    public ActionResult SubmitEmailForPasswordReset(UserModel model)
    {
        if (!ModelState.IsValid)
        {
            return CurrentUmbracoPage();
        }

        bool success = _recoverUnpwWorkflow.RecoverPasswordSubmitEmail(model);
        TempData.Add("Success", success);

        return RedirectToCurrentUmbracoPage();
    }
}

HTML должен быть:

<form method="post" id="form-lost-password">
@using(Html.BeginUmbracoForm<UmbracoApp.Controllers.RecoverUserDataSurfaceController>("SubmitEmailForPasswordReset"))
{
    <div class="text-field validate-email required">
        <label for="EmailAddress">Email Address</label>
        @Html.ValidationMessageFor(x => x.EmailAddress)
        @Html.TextBoxFor(x => x.EmailAddress, new { @placeholder = "name@domain.com" })
    </div>
    <div class="submit-field">
        <input type="submit" value="Submit" title="Submit" class="btn-default" />
    </div>
}
</form>

Надеюсь, что поможет.

...