Exemplo n.º 1
0
        protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
        {
            using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["OCKO_EvaluacionPersonal"].ToString()))
            {
                cn.Open();
                SqlCommand cmd = new SqlCommand();
                cmd.CommandText = "OCKO_Acceso";
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Connection  = cn;
                cmd.Parameters.AddWithValue("@usuario", Login.UserName);
                cmd.Parameters.AddWithValue("@contraseña", Login.Password);
                SqlDataReader reader = cmd.ExecuteReader();
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        Session["Username"]  = reader.GetValue(0);
                        Session["tipo"]      = reader.GetValue(1);
                        Session["JefeIdEva"] = reader.GetValue(2);


                        int jefeId = Convert.ToInt32(Session["tipo"].ToString());
                        Session["EmpId"] = reader.GetValue(2);
                        if (jefeId == 3 || jefeId == 4)
                        {
                            Session["IdJefe"] = jefeId;
                        }
                        else if (jefeId == 5 || jefeId == 6)
                        {
                            Session["PM"] = reader.GetValue(2);
                        }
                        else
                        {
                            Session["IdEmpleado"] = reader.GetValue(2);
                        }
                    }
                    e.Authenticated = true;
                }
                else
                {
                    if (!usuarioClass.BuscarUsuario(Login.UserName))
                    {
                        Response.Write("<script language=javascript>alert('Usuario no Registrado');</script>");
                    }
                    else
                    {
                        Response.Write("<script language=javascript>alert('Usuario o Contraseña Incorrecta..!');</script>");
                        e.Authenticated = false;
                    }
                }
            }
        }
        protected void btnIngresar_Click(object sender, EventArgs e)
        {
            int             intento = Convert.ToInt32(Session["intento"].ToString());
            OCKO_TblUsuario usuario = OckoUsuario.BuscarUsuario(TxtUserName.Text, TxtPassword.Text);//OckoValidaciones.Encriptar(TxtPassword.Text));

            if (usuario != null)
            {
                string nombre = usuario.OCKO_TblRol.RolNombre;
                if (nombre.Trim() == "RRHH")
                {
                    if (usuario.UsuEstado.Equals(Convert.ToChar("R")))
                    {
                        Response.Redirect("cambiarContraseña.aspx?id=" + usuario.UsuId);
                    }
                    else
                    {
                        Session["usuario"] = usuario;
                        Response.Redirect("RRHH/RRHH_Index.aspx");
                    }
                }
                else
                {
                    //AQUI SE REDIRECCIONA AL TEMPLATE DEL USUARIO
                }
            }
            else
            {
                if (OckoUsuario.OckoBbuscarPorNombre(TxtUserName.Text) != null)
                {
                    Response.Write("<script>window.alert('Contraseña incorrecta')</script>");
                }
                else
                {
                    Response.Write("<script>window.alert('Usuario NO Registrado')</script>");
                }
                if (intento >= 2)
                {
                    btnIngresar.Enabled = false;
                    intentos.Text       = "Intente mas tarde";
                }
                else
                {
                    intento            = intento + 1;
                    Session["intento"] = intento;
                    intentos.Text      = "INTENTOS   :" + intento;
                }
            }
        }