public IActionResult Login(UsuarioViewModel model) { try { LoginDAO dao = new LoginDAO(); UsuarioViewModel usuarioLogado = dao.ObtemUsuario(model); if (usuarioLogado != null) { HttpContext.Session.SetString("Logado", "true"); ViewBag.Logado = HelperController.VerificaUserLogado(HttpContext.Session); return(RedirectToAction("Index", "Professor")); } else { ViewBag.Erro = "Usuário ou senha inválidos!"; return(View("Index")); } } catch (Exception ex) { ViewBag.Erro = ex.Message; return(View("Index")); } }
/// <summary> /// Validação de login /// </summary> /// <param name="context"></param> public override void OnActionExecuting(ActionExecutingContext context) { if (!HelperController.VerificaUserLogado(HttpContext.Session)) { context.Result = RedirectToAction("Index", "Login"); } else { ViewBag.Logado = true; base.OnActionExecuting(context); } }