Ejemplo n.º 1
0
        public async Task <JsonResult> Login(LoginViewModel loginModel, string returnUrl = "", string returnUrlHash = "")
        {
            try
            {
                CheckModelState();
                _captchaManager.CheckCaptcha(loginModel.Captcha);
                await _logInManager.CheckLoginSetting(loginModel.UsernameOrEmailAddress);

                var loginResult = await GetLoginResultAsync(
                    loginModel.UsernameOrEmailAddress,
                    loginModel.Password,
                    "Default" //GetTenancyNameOrNull()
                    );

                await SignInAsync(loginResult.User, loginResult.Identity, loginModel.RememberMe);

                if (string.IsNullOrWhiteSpace(returnUrl))
                {
                    returnUrl = Request.ApplicationPath;
                }

                if (!string.IsNullOrWhiteSpace(returnUrlHash))
                {
                    returnUrl = returnUrl + returnUrlHash;
                }

                return(Json(new AjaxResponse(new { ShouldChangePasswordOnNextLogin = loginResult.User.ShouldChangePasswordOnNextLogin })
                {
                    TargetUrl = returnUrl
                }));
            }
            catch (Exception ex)
            {
                LogHelper.LogException(Logger, ex);
                Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                EventBus.Trigger(this, new AbpHandledExceptionData(ex));
                return(Json(new AjaxResponse(ErrorInfoBuilder.BuildForException(ex))));
            }
        }