예제 #1
0
        public async Task <IActionResult> Login(LoginViewModel loginVM)
        {
            var loggedUser = UsuarioLogeado.MapearUsuario(_usuarioLogic.Login(loginVM.NombreUsuario, loginVM.Clave));

            if (loggedUser == null)
            {
                ModelState.AddModelError("", "Usuario o contraseña incorrectos");
                return(View(loginVM));
            }

            await _usuarioManager.SignIn(this.HttpContext, loggedUser, loginVM.IsPersistent);

            return(RedirectToAction(controllerName: "Home", actionName: "Index"));
        }
예제 #2
0
        public async Task SignIn(HttpContext httpContext, UsuarioLogeado usuarioLogeado, bool isPersistent = false)
        {
            var claims = new List <Claim>()
            {
                new(ClaimTypes.NameIdentifier, usuarioLogeado.Id.ToString()),
                new(ClaimTypes.Name, usuarioLogeado.Nombre),
                new(ClaimTypes.Email, usuarioLogeado.NombreUsuario),
                new(ClaimTypes.Role, usuarioLogeado.Role.ToString())
            };

            string authSheme      = CookieAuthenticationDefaults.AuthenticationScheme;
            var    claimPrincipal = new ClaimsPrincipal(new ClaimsIdentity(claims, authSheme));

            await httpContext.SignInAsync(
                authSheme,
                claimPrincipal,
                new AuthenticationProperties()
            {
                IsPersistent = isPersistent
            }
                );
        }
예제 #3
0
 public async Task SignIn(HttpContext httpContext, UsuarioLogeado usuarioLogeado, bool isPersistent = false)
 {
     throw new NotImplementedException();
 }