protected void btnAceptar_Click(object sender, EventArgs e) { try { String stMensaje = String.Empty; if (String.IsNullOrEmpty(txtEmail.Text)) { stMensaje += "Ingrese Email, "; } if (String.IsNullOrEmpty(txtPassword.Text)) { stMensaje += "Ingrese Contraseña, "; } if (!String.IsNullOrEmpty(stMensaje)) { throw new Exception(stMensaje.TrimEnd(',')); } //Defino Objeto con prioridades logica.Models.clsUsuarios obclsUsuarios = new logica.Models.clsUsuarios { stCorreo = txtEmail.Text, stPassword = txtPassword.Text }; //Instancio Controlador Controllers.LoginControllers obLogingController = new Controllers.LoginControllers(); bool blBandera = obLogingController.getValidarUsuarioAdministradorController(obclsUsuarios); if (blBandera) { if (chkRecordar.Checked) { HttpCookie cookieEmail = new HttpCookie("EmailAdministrador", txtEmail.Text); cookieEmail.Expires = DateTime.Now.AddDays(2); Response.Cookies.Add(cookieEmail); } else { HttpCookie cookieEmail = new HttpCookie("EmailAdministrador", txtEmail.Text); cookieEmail.Expires = DateTime.Now.AddDays(-1); Response.Cookies.Add(cookieEmail); } ViewState["viewLoginAdministrador"] = txtEmail.Text; ViewState["ViewPasswordAdministrador"] = txtPassword.Text; Session["SessionEmailAdministrador"] = txtEmail.Text; Session["sesionPasswordAdministrador"] = txtPassword.Text; Response.Redirect("../IndexAdmin/IndexAdmin.aspx"); //Session.RemoveAll(); Remover todas //Session.Remove("sesionLogin"); Nombre Variable a remover } else { throw new Exception("Usuario o password incorrectos"); } } catch (Exception ex) { ClientScript.RegisterStartupScript(this.GetType(), "Mesaje", "<Script> swal('ERROR!', '" + ex.Message + "!', 'error')</Script>"); } }
protected void btnLogin_Click(object sender, EventArgs e) { try { string stMensaje = string.Empty; if (string.IsNullOrEmpty(txtEmail.Text)) { stMensaje += "Ingrese email, "; } if (string.IsNullOrEmpty(txtPassword.Text)) { stMensaje += " Ingrese password,"; } if (!string.IsNullOrEmpty(stMensaje)) { throw new Exception(stMensaje.TrimEnd(',')); } //Defino objeto con propiedades Logica.Models.clsUsuarios obclsUsuarios = new Logica.Models.clsUsuarios { stLogin = txtEmail.Text, stPassword = txtPassword.Text }; //Instalcio controlador Controllers.LoginControllers obloginController = new Controllers.LoginControllers(); bool blBandera = obloginController.getValidarUsuariosController(obclsUsuarios); //Valido respuesta if (blBandera) { Session["sessionEmail"] = txtEmail.Text; if (chkRecordar.Checked) { //creo un objetocookie HttpCookie cookie = new HttpCookie("cookieEmail", txtEmail.Text); //adicciono el tiempo de vida cookie.Expires = DateTime.Now.AddDays(2); //agrego a la coleccion de cookies Response.Cookies.Add(cookie); } else { HttpCookie cookie = new HttpCookie("cookieEmail", txtEmail.Text); //la cookie expira el dia de ayer cookie.Expires = DateTime.Now.AddDays(-1); Response.Cookies.Add(cookie); } Response.Redirect("../Index/Index.aspx"); } else { throw new Exception("Email o Password incorrecto"); } } catch (Exception ex) { Logica.BL.clsGeneral obclsGeneral = new Logica.BL.clsGeneral(); string stError = obclsGeneral.Log(ex.Message.ToString()); ClientScript.RegisterStartupScript(this.GetType(), "mensaje", "<script>swal('Error!', '" + stError + "', 'error')</script>"); } }