Esempio n. 1
0
        public async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true
            // var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);
            var token = await UserAuthentication.GetTokenAsync(Client, model.Username, model.Password);

            if (!string.IsNullOrEmpty(token))
            {
                HttpCookie httpCookie = new HttpCookie("nossobolao");
                httpCookie.Value   = token;
                httpCookie.Expires = DateTime.Now.AddHours(10);
                Response.Cookies.Add(httpCookie);
                return(RedirectToLocal(returnUrl));
            }

            ModelState.AddModelError("", "Tentativa inválida de login.");
            return(View(model));
        }