public async Task <IActionResult> LoginAsync(LoginViewModel model) { var newModel = new LoginViewModel() { Mail = model.Mail }; if (!api.Login(model.Password, model.Mail)) { ModelState.AddModelError("mail", "El usuario o la contraseña son incorrectos"); return(View("Login", newModel)); } if (!api.IsUserVerified(model.Mail, model.Password)) { ModelState.AddModelError("mail", "La cuenta no ha sido verificada"); return(View("Login", newModel)); } var user = api.GetUserByEmail(model.Mail); var emailClaim = new Claim(ClaimTypes.Email, model.Mail); var roleClaim = new Claim(ClaimTypes.Role, user.Role); var idClaim = new Claim(ClaimTypes.Sid, user.Id.ToString()); var nameClaim = new Claim(ClaimTypes.Name, user.Name); var identity = new ClaimsIdentity(new[] { emailClaim, roleClaim, nameClaim, idClaim }, "cookie"); var principal = new ClaimsPrincipal(identity); await this.HttpContext.SignInAsync(principal); User.FindFirstValue(ClaimTypes.Email); return(RedirectToAction("Index", "")); }