public async Task <String> Login(LoginVMO userloginVMO) { LoginDTO userLogin = LoginMapper.MapToDTO(userloginVMO); String token = await this.request.GetToken(userLogin); return(token); }
public static LoginVMO MapToModel(LoginDTO loginDto) { LoginVMO login = new LoginVMO(); login.Username = loginDto.Username; login.Password = loginDto.Password; return(login); }
public static LoginDTO MapToDTO(LoginVMO login) { LoginDTO loginDTO = new LoginDTO(); loginDTO.Username = login.Username; loginDTO.Password = login.Password; return(loginDTO); }
public async Task <IActionResult> SignIn(LoginVMO loginVMO) { if (SessionUserId.HasValue) { return(RedirectToAction("Home", "Home")); } String token = await userService.Login(loginVMO); if (token != null) { int userId = await userService.GetUserIdByUsername(loginVMO.Username); int roleId = await userService.GetRoleId(userId); ClaimsIdentity identity = new ClaimsIdentity(CookieAuthenticationDefaults.AuthenticationScheme, ClaimTypes.NameIdentifier, ClaimTypes.Role); identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, userId.ToString())); identity.AddClaim(new Claim(ClaimTypes.Role, roleId.ToString())); identity.AddClaim(new Claim("Token", token)); ClaimsPrincipal user = new ClaimsPrincipal(identity); await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, user, new AuthenticationProperties { IsPersistent = true, ExpiresUtc = DateTime.Now.AddMinutes(20) }); SessionUserId = await userService.GetUserIdByUsername(loginVMO.Username); object controller = TempData["controller"]; object action = TempData["action"]; var redirect = (controller == null || action == null) ? RedirectToAction("Home", "Home") : RedirectToAction(action.ToString(), controller.ToString()); TempData["controller"] = null; TempData["action"] = null; return(redirect); } else { ViewBag.Error = "Usuario o Contraseña Incorrectos"; return(View()); } }
public async Task <IActionResult> Index(LoginVMO vmo) { if (ModelState.IsValid) { var model = _serviceUsuario.Login(vmo.Nickname, vmo.Password); if (model != null) { var claims = new List <Claim> { new Claim(ClaimTypes.Name, model.Nombre), new Claim(ClaimTypes.Role, "Administrator") }; var claimsIdentity = new ClaimsIdentity(claims, "User"); await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(claimsIdentity)); return(RedirectToAction("Index", "Home")); } ViewData["ErrorLogin"] = "******"; } return(View(vmo)); }
public IActionResult Index() { var vmo = new LoginVMO(); return(View(vmo)); }