Esempio n. 1
0
        public async Task <IActionResult> Login(LoginViewModel model)
        {
            ViewData["ReturnUrl"] = model.ReturnUrl;
            if (!ModelState.IsValid)
            {
                return(View(ViewUri, model));
            }

            try
            {
                var user = await _loginService.Login(model.Email, model.Password);

                var isValidReturnUrl = await _externalLoginService.IsValidExternalReturnUrl(model.ReturnUrl);

                if (!isValidReturnUrl)
                {
                    return(Redirect("~/"));
                }

                return(Redirect(model.ReturnUrl));
            }
            catch (InvalidCredentialsException)
            {
                //TODO : GLobalization and error catch middleware
                ModelState.AddModelError("", "Invalid username or password.");
                return(View(ViewUri, model));
            }
        }