Exemplo n.º 1
0
        public async Task <IActionResult> Login(LoginViewModel model, string ReturnUrl)
        {
            try
            {
                if (String.IsNullOrEmpty(ReturnUrl))
                {
                    ReturnUrl = "/";
                }

                await HttpContext.SignOutAsync();

                bool isModelValid = ModelState.IsValid;
                //isModelValid = true;

                if (isModelValid)
                {
                    //String[] errorInfo;
                    //string pidm = "41149";// await AccountBus.AuthenticateUser(model.LoginHandle, model.Password);

                    bool    isAuth   = false;
                    UserEnt authUser = null;
                    await Task.Run(() =>
                    {
                        isAuth = UserBus.Authenticate(model.LoginHandle, model.Password, out authUser);
                    });

                    if (isAuth)
                    {
                        await _Login(ReturnUrl, authUser);
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, "Invalid login attempt.");
                    }
                }
            }
            catch (Exception e)
            {
                ModelState.AddModelError(string.Empty, e.Message);
            }
            ViewData["ReturnUrl"] = ReturnUrl;
            return(View());
        }