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

            Usuario user = await _mongo.Users.Find(Builders <Usuario> .Filter.Eq(u => u.Email, model.Email)).FirstOrDefaultAsync();

            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)));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Acessar(AcessarModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            // XXXX TRABALHE AQUI
            // Neste ponto iremos buscar o email digitado ao acessar o Blog
            // Descomentar as linhas abaixo

            //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)));
        }
        public async Task <ActionResult> Acessar(AcessarModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var connectarMongoDB = new AcessoMongoDB();
            var user             = await connectarMongoDB.Usuarios.Find(x => x.Email == model.Email).SingleOrDefaultAsync();

            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)));
        }
Exemplo n.º 4
0
        public ActionResult Acessar(string returnUrl)
        {
            var model = new AcessarModel
            {
                RetornoUrl = returnUrl
            };

            return(View(model));
        }