Ejemplo n.º 1
0
        public virtual async Task<JsonResult> Login(LoginModel loginModel, string returnUrl = "")
        {
            if (!ModelState.IsValid)
            {
                throw new UserFriendlyException("Your form is invalid!");
            }

            var result = await _userManager.LoginAsync(loginModel.EmailAddress, loginModel.Password);

            if (result.Result != AbpLoginResultType.Success)
            {
                // ErrorInfo error = CreateErrorInfoForFailedLoginAttempt(result.Result, loginModel.EmailAddress);
                throw CreateExceptionForFailedLoginAttempt(result.Result, loginModel.EmailAddress);

                // throw new UserFriendlyException("Invalid user name or password!");
                // return Json(new MvcAjaxResponse { Error = error });
            }

            await SignInAsync(result.User, loginModel.RememberMe);

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

            return Json(new MvcAjaxResponse { TargetUrl = returnUrl });
        }
Ejemplo n.º 2
0
        public virtual async Task<JsonResult> Login(LoginModel loginModel, string returnUrl = "/")
        {
            if (!ModelState.IsValid)
            {
                throw new UserFriendlyException("Your form is invalid!");
            }

            var user = await _userManager.FindAsync(loginModel.EmailAddress, loginModel.Password);
            if (user == null)
            {
                throw new UserFriendlyException("Invalid user name or password!");
            }
            
            await SignInAsync(user, loginModel.RememberMe);

            return Json(new AbpMvcAjaxResponse { TargetUrl = returnUrl });
        }