public ActionResult Logon(LogonVM model) { var ch = repos.CheckUserLoginPasswordPair(model.Login, model.Password); if (ch == 0) { FormsAuthentication.RedirectFromLoginPage(model.Login, createPersistentCookie: true); return(RedirectToAction("Index", "User", Mapper.Map <UserVM>(repos.GetUser(model.Login)))); } else { return(RedirectToAction("Index", "Home")); } }
private LogonVM RecuperarSenha(LogonVM viewModel, string cpf, string email) { Validacao.Erros.Clear(); if (!GerenciarAutenticacao.ValidarRecuperacaoSenha(cpf, email)) { viewModel.EsqueciSenha = true; viewModel.AlterarSenhaMsg = "Será gerada nova chave de validação que lhe permitirá restabelecer o acesso ao sistema. A chave será enviada ao e-mail registrado no seu cadastro do SIMLAM."; return(viewModel); } GerenciarAutenticacao.RecuperarSenha(cpf, email); return(viewModel); }
public ActionResult LogOn(string login, string senha, bool?alterarSenha, string novaSenha, string confirmarNovaSenha, string returnUrl) { LogonVM viewModel = new LogonVM() { AlterarSenha = alterarSenha ?? false }; viewModel.IsAjaxRequest = Request.IsAjaxRequest(); try { string strSessionId = null; if (!GerenciarAutenticacao.ValidarLogOn(login, senha, out strSessionId)) { if (Request.IsAjaxRequest()) { return(PartialView("LogOnPartial", new LogonVM() { IsAjaxRequest = Request.IsAjaxRequest() })); } else { return(View(viewModel)); } } FuncionarioBus busFuncionario = new FuncionarioBus(new FuncionarioValidar()); string alterarSenhaMsg = busFuncionario.AlterarSenhaMensagem(login); if (!String.IsNullOrEmpty(alterarSenhaMsg)) { Validacao.Erros.Clear(); if (!viewModel.AlterarSenha || !busFuncionario.AlterarSenha(login, senha, novaSenha, confirmarNovaSenha)) { viewModel = new LogonVM() { AlterarSenha = true, AlterarSenhaMsg = alterarSenhaMsg }; if (Request.IsAjaxRequest()) { return(PartialView("LogOnPartial", new LogonVM() { IsAjaxRequest = Request.IsAjaxRequest() })); } else { return(View(viewModel)); } } } this.formsAuthenticationService.SetAuthCookie(login, true); FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, login, DateTime.Now, DateTime.Now.Add(FormsAuthentication.Timeout), true, strSessionId); HttpCookie cookie = null; String cookieName = this.formsAuthenticationService.FormsCookieName; if (cookieName != null) { cookie = Request.Cookies[cookieName]; } if (cookie != null) { cookie.Value = this.formsAuthenticationService.Encrypt(ticket); } //Cria o cookie que é usado para a verificação periódica de E-PTVs aguardando análise. #region Insere cookie EPTV InsereCookieEPTV(); #endregion Insere cookie EPTV GerenciarAutenticacao.CarregarUser(login); BusMenu.Menu = null; //Gera a mensagem de alerta de E-PTV (se houver) #region Alerta de E-PTV var funcionario = new FuncionarioBus().ObterFuncionarioAutenticacao(login); PTVBus _busPTV = new PTVBus(); _busPTV.VerificaAlertaEPTV(funcionario.Id, login); #endregion Alerta de E-PTV if (Request.IsAjaxRequest()) { return(PartialView("LogOnPartial", new LogonVM() { IsAjaxRequest = Request.IsAjaxRequest() })); } else if (!String.IsNullOrEmpty(returnUrl)) { return(Redirect(Validacao.QueryParamSerializer(HttpUtility.UrlDecode(returnUrl)))); } else { return(RedirectToAction("Index", "Home", Validacao.QueryParamSerializer())); } } catch (Exception exc) { Validacao.AddErro(exc); } if (Request.IsAjaxRequest()) { return(RedirectToAction("Index", "Home", Validacao.QueryParamSerializer())); } else { return(View(viewModel)); } }
public ActionResult LogOn(string login, string senha, bool?alterarSenha, string novaSenha, string confirmarNovaSenha, string returnUrl, bool?esqueciSenha, bool?verificarTrocarSenha, string email, string cpf) { LogonVM viewModel = new LogonVM() { AlterarSenha = alterarSenha ?? false, EsqueciSenha = esqueciSenha }; viewModel.IsAjaxRequest = Request.IsAjaxRequest(); if (esqueciSenha == true) { viewModel.AlterarSenhaMsg = "Será gerada nova chave de validação que lhe permitirá restabelecer o acesso ao sistema. A chave será enviada ao e-mail registrado no seu cadastro do SIMLAM."; if (Request.IsAjaxRequest()) { return(this.getAjaxLogOnPartial()); } return(View(viewModel)); } if (verificarTrocarSenha == true) { viewModel = RecuperarSenha(viewModel, cpf, email); return(View(viewModel)); } try { string strSessionId = null; if (!GerenciarAutenticacao.ValidarLogOn(login, senha, out strSessionId)) { if (Request.IsAjaxRequest()) { return(this.getAjaxLogOnPartial()); } return(View(viewModel)); } CredenciadoBus credenciadoBus = new CredenciadoBus(new CredenciadoValidar()); string alterarSenhaMsg = credenciadoBus.AlterarSenhaMensagem(login); if (!String.IsNullOrEmpty(alterarSenhaMsg)) { Validacao.Erros.Clear(); if (!viewModel.AlterarSenha || !credenciadoBus.AlterarSenha(login, senha, novaSenha, confirmarNovaSenha)) { viewModel = new LogonVM() { AlterarSenha = true, AlterarSenhaMsg = alterarSenhaMsg }; if (Request.IsAjaxRequest()) { return(this.getAjaxLogOnPartial()); } return(View(viewModel)); } } this.formsAuthenticationService.SetAuthCookie(login, true); FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, login, DateTime.Now, DateTime.Now.Add(FormsAuthentication.Timeout), true, strSessionId); HttpCookie cookie = null; String cookieName = this.formsAuthenticationService.FormsCookieName; if (cookieName != null) { cookie = Request.Cookies[cookieName]; } if (cookie != null) { cookie.Value = this.formsAuthenticationService.Encrypt(ticket); } GerenciarAutenticacao.CarregarUser(login); BusMenu.Menu = null; if (Request.IsAjaxRequest()) { return(PartialView("LogOnPartial", new LogonVM() { IsAjaxRequest = Request.IsAjaxRequest() })); } if (!String.IsNullOrEmpty(returnUrl)) { return(Redirect(Validacao.QueryParamSerializer(HttpUtility.UrlDecode(returnUrl)))); } return(RedirectToAction("Index", "Home", Validacao.QueryParamSerializer()) as RedirectToRouteResult);; } catch (Exception exc) { Validacao.AddErro(exc); } if (Request.IsAjaxRequest()) { return(RedirectToAction("Index", "Home", Validacao.QueryParamSerializer())); } return(View(viewModel)); }
public ActionResult LogOn(string login, string senha, bool?alterarSenha, string novaSenha, string confirmarNovaSenha, string returnUrl) { LogonVM viewModel = new LogonVM() { AlterarSenha = alterarSenha ?? false }; viewModel.IsAjaxRequest = Request.IsAjaxRequest(); try { string strSessionId = null; if (!GerenciarAutenticacao.ValidarLogOn(login, senha, out strSessionId)) { if (Request.IsAjaxRequest()) { return(PartialView("LogOnPartial", new LogonVM() { IsAjaxRequest = Request.IsAjaxRequest() })); } else { return(View(viewModel)); } } FuncionarioBus busFuncionario = new FuncionarioBus(new FuncionarioValidar()); string alterarSenhaMsg = busFuncionario.AlterarSenhaMensagem(login); if (!String.IsNullOrEmpty(alterarSenhaMsg)) { Validacao.Erros.Clear(); if (!viewModel.AlterarSenha || !busFuncionario.AlterarSenha(login, senha, novaSenha, confirmarNovaSenha)) { viewModel = new LogonVM() { AlterarSenha = true, AlterarSenhaMsg = alterarSenhaMsg }; if (Request.IsAjaxRequest()) { return(PartialView("LogOnPartial", new LogonVM() { IsAjaxRequest = Request.IsAjaxRequest() })); } else { return(View(viewModel)); } } } FormsAuthentication.SetAuthCookie(login, true); FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, login, DateTime.Now, DateTime.Now.Add(FormsAuthentication.Timeout), true, strSessionId); HttpCookie cookie = Request.Cookies[FormsAuthentication.FormsCookieName]; cookie.Value = FormsAuthentication.Encrypt(ticket); GerenciarAutenticacao.CarregarUser(login); BusMenu.Menu = null; if (Request.IsAjaxRequest()) { return(PartialView("LogOnPartial", new LogonVM() { IsAjaxRequest = Request.IsAjaxRequest() })); } else if (!String.IsNullOrEmpty(returnUrl)) { return(Redirect(Validacao.QueryParamSerializer(HttpUtility.UrlDecode(returnUrl)))); } else { return(RedirectToAction("Index", "Home", Validacao.QueryParamSerializer())); } } catch (Exception exc) { Validacao.AddErro(exc); } if (Request.IsAjaxRequest()) { return(RedirectToAction("Index", "Home", Validacao.QueryParamSerializer())); } else { return(View(viewModel)); } }