Exemple #1
0
        public async Task <ActionResult> Acessar(AcessarModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var user = await daoUsuario.ConsultarAsync(model.Email);

            if (user == null)
            {
                ModelState.AddModelError("Email", "Correio não foi registrado.");
                return(View(model));
            }

            var identity = new ClaimsIdentity(new[]
            {
                new Claim(ClaimTypes.Name, user.Nome),
                new Claim(ClaimTypes.Email, user.Email)
            },
                                              "ApplicationCookie");

            var context     = Request.GetOwinContext();
            var authManager = context.Authentication;

            authManager.SignIn(identity);

            return(Redirect(GetRedirectUrl(model.RetornoUrl)));
        }