Esempio n. 1
0
        public async Task <IActionResult> Login([Bind] UserLoginRequest request)
        {
            var user = await _movtechAPIService.Login(request);

            if (user != null)
            {
                var claims = new List <Claim>
                {
                    new Claim(ClaimTypes.NameIdentifier, request.CPF),
                    new Claim(ClaimTypes.Name, user.Name)
                };

                ClaimsIdentity  userIdentity = new ClaimsIdentity(claims, "login");
                ClaimsPrincipal principal    = new ClaimsPrincipal(userIdentity);

                await HttpContext.SignInAsync(principal);


                return(RedirectToAction("Index", "Home"));

                //if (User.Identity.IsAuthenticated)
                //    return RedirectToAction("Index", "Home");
                //else
                //{
                //    ModelState.AddModelError("", "Erro ao tentar logar-se");
                //    return View(request);
                //}
            }
            else
            {
                ModelState.AddModelError("", "Usuário ou senha inválido");
                return(View(request));
            }
        }