Example #1
0
        protected void BtnAceptar_Click1(object sender, EventArgs e)
        {
            try
            {
                string stMensaje = string.Empty;
                if (string.IsNullOrWhiteSpace(TxtEmail.Text))
                {
                    stMensaje += "ingrese email,";
                }
                if (string.IsNullOrWhiteSpace(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
                };
                //instancio controlador
                Controllers.LoginController obLoginController = new Controllers.LoginController();
                bool blBandera = obLoginController.getvalidarUsuarioController(obclsUsuarios);

                if (blBandera)
                {
                    Response.Redirect("../Index/Index.aspx");//redirecciono
                }
                else
                {
                    throw new Exception("Usuario o Password incorrectos");
                }
            }
            catch (Exception ex)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "mensaje", "<script>swal('Error!','" + ex.Message + "!','error')</script>");
            }
        }
Example #2
0
        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 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
                };
                //instancio controlador
                Controllers.LoginController obloginController = new Controllers.LoginController();

                bool blBandera = obloginController.getvalidarUsuarioController(obclsUsuarios);

                if (blBandera)
                {
                    Session["sessionEmail"] = txtemail.Text;

                    if (CheckRecordar.Checked)
                    {
                        //crear objeto cookie
                        HttpCookie cookie = new HttpCookie("cookieEmail", txtemail.Text);

                        //adicciono time de vida
                        cookie.Expires = DateTime.Now.AddDays(2);

                        //adicciono ala coleccion de cookie
                        Response.Cookies.Add(cookie);
                    }
                    else
                    {
                        //crear objeto cookie
                        HttpCookie cookie = new HttpCookie("cookieEmail", txtemail.Text);

                        //cookie expira el dira de ayer
                        cookie.Expires = DateTime.Now.AddDays(-1);
                        Response.Cookies.Add(cookie);
                    }

                    Response.Redirect("../Index/Index.aspx?stEmail=" + txtemail.Text); //redirecciono y atrapo el coreo y lo pongo en la url
                }


                else
                {
                    throw new Exception("Usuario o clave incorrecta");
                }
            }
            catch (Exception ex)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "mensaje", "<script> swal('error!','" + ex.Message + "!', 'error') </Script>");
            }
        }