コード例 #1
0
ファイル: Sitio.Master.cs プロジェクト: mwallace1407/Omega
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.IsAuthenticated)
            {
                imgPath = System.Web.VirtualPathUtility.ToAbsolute("~/App_Themes/imagenes/pistol.jpg");

                if (Session["NombreCompletoUsuario"] != null)
                {
                    ((Label)LoginView3.FindControl("lblNombreCompletoUsuario")).Text = Session["NombreCompletoUsuario"].ToString();
                    ((Label)LoginView3.FindControl("lblNombreCompletoRol")).Text     = Session["NombreCompletoRol"].ToString();
                    if (sender.ToString() == "ASP.forms_sitio_master")
                    {
                        CreaMenu();
                    }
                }
                else
                {
                    try
                    {
                        Session.Clear();
                        System.Web.Security.FormsAuthentication.SignOut();

                        if ((this.Page.ToString().Substring(4, this.Page.ToString().Substring(4).Length - 5) + ".aspx").Trim().ToLower() != "acceso.aspx")
                        {
                            Response.Redirect("~/Forms/sessionTimeout.html");
                        }
                    }
                    catch { Response.Redirect("~/Forms/sessionTimeout.html"); }
                }
            }
            else
            {
                //imgPath = System.Web.VirtualPathUtility.ToAbsolute("~/App_Themes/imagenes/FondoCastor_50.png");
            }
        }
コード例 #2
0
    protected void addDomeniu(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);

        string command = "insert into Domenii values(@dom, @desc)";

        TextBox t    = (TextBox)(LoginView3.FindControl("testD"));
        string  text = t.Text;

        t.Text = "";

        TextBox tt    = (TextBox)(LoginView3.FindControl("testE"));
        string  textt = tt.Text;

        tt.Text = "";

        con.Open();
        using (SqlCommand cmd = new SqlCommand(command, con))
        {
            cmd.Parameters.AddWithValue("@dom", text);
            cmd.Parameters.AddWithValue("@desc", textt);
            cmd.ExecuteNonQuery();
        }

        con.Close();

        Response.Redirect("Default.aspx");
    }
コード例 #3
0
    protected void getAdmin(object sender, EventArgs e)
    {
        TextBox tbox = (TextBox)LoginView3.FindControl("tbmod");
        string  user = tbox.Text;

        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);
        SqlCommand    cmd = null;

        con.Open();

        cmd = new SqlCommand("select * from AspNetUsers", con);
        List <string> users = new List <string>();
        List <string> ids   = new List <string>();


        DataTable      dt = new DataTable();
        SqlDataAdapter da = new SqlDataAdapter(cmd);

        da.Fill(dt);


        foreach (DataRow row in dt.Rows)
        {
            users.Add(row["UserName"].ToString());
            ids.Add(row["id"].ToString());
        }

        string idmod = "";

        for (var i = 0; i < users.Count; ++i)
        {
            if (users[i].Equals(user))
            {
                idmod = ids[i];
            }
        }
        con.Close();
        // --------------------------------------------------------------
        con.Open();
        string command = "UPDATE AspNetUserRoles SET RoleId = @cm WHERE UserId='" + idmod.ToString() + "'";

        using (SqlCommand cmdd = new SqlCommand(command, con))
        {
            cmdd.Parameters.AddWithValue("@cm", 1);
            cmdd.ExecuteNonQuery();
        }

        con.Close();

        // ------------------------------
    }
コード例 #4
0
    protected void BMove_Click(object sender, EventArgs e)
    {
        DropDownList DDL     = (DropDownList)LoginView3.FindControl("DDLCategories");
        int          titleID = int.Parse(DDL.SelectedValue);
        int          forumId = int.Parse(Request.Params["forumId"]);

        SqlConnection connection = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\mydb.mdf;Integrated Security=True");

        string queryString = "UPDATE Forum SET titleId = @titleId WHERE forumId = @forumId";

        var command = new SqlCommand(queryString, connection);

        command.Parameters.Add("@titleId", SqlDbType.Int).Value = titleID;
        command.Parameters.Add("@forumId", SqlDbType.Int).Value = forumId;

        connection.Open();

        int RowsAffected = command.ExecuteNonQuery();

        Response.Redirect("~/index.aspx");
    }
コード例 #5
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Display Picture Code
        if (Page.User.Identity.IsAuthenticated && !Page.User.IsInRole("Administrator"))
        {
            Image  UserPic = LoginView1.FindControl("UserPicture") as Image;
            string strConn = ConfigurationManager.ConnectionStrings["EIMSConnectionString"].ConnectionString;
            using (SqlConnection conn = new SqlConnection(strConn))
            {
                MembershipUser user   = Membership.GetUser(Page.User.Identity.Name);
                Guid           userId = (Guid)user.ProviderUserKey;
                conn.Open();
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = conn;
                string avatarQuery;
                if (Page.User.IsInRole("Student"))
                {
                    DataView dvSql2 = (DataView)AssociationDataSource.Select(DataSourceSelectArguments.Empty);
                    foreach (DataRowView drvSql in dvSql2)
                    {
                        //checking if a record is present in the data view, then show the associated parent
                        if (drvSql["ParentId"].ToString() != "")
                        {
                            MembershipUser parent           = Membership.GetUser(drvSql["ParentId"]);
                            HyperLink      ParentLinkMaster = LoginView3.FindControl("ParentLinkMaster") as HyperLink;
                            ParentLinkMaster.NavigateUrl = "~/Shared/ParentProfile.aspx?id=" + parent.UserName.ToString();
                            //ParentLink.Text = parent.Email + "(" + parent.UserName + ")";
                        }
                        else
                        {
                            HyperLink ParentLinkMaster = LoginView3.FindControl("ParentLinkMaster") as HyperLink;
                            ParentLinkMaster.NavigateUrl = "~/Shared/ParentProfile.aspx?id=NPF";
                        }
                    }
                    avatarQuery     = "select StudentProfiles.Avatar from StudentProfiles where StudentProfiles.StudentId=@StudentId";
                    cmd.CommandText = avatarQuery;
                    cmd.Parameters.AddWithValue("@StudentId", userId);
                }
                else if (Page.User.IsInRole("Teacher"))
                {
                    avatarQuery     = "select TeacherProfiles.Avatar from TeacherProfiles where TeacherProfiles.TeacherId=@TeacherId";
                    cmd.CommandText = avatarQuery;
                    cmd.Parameters.AddWithValue("@TeacherId", userId);
                }
                else
                {
                    avatarQuery     = "select ParentProfiles.Avatar from ParentProfiles where ParentProfiles.ParentId=@ParentId";
                    cmd.CommandText = avatarQuery;
                    cmd.Parameters.AddWithValue("@ParentId", userId);
                }
                SqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    if (dr["Avatar"].ToString() != "")
                    {
                        UserPic.ImageUrl = dr["Avatar"].ToString();
                    }
                }
            }
        }
        // Display Picture Code
        SuccessMessages.Visible = false;
        if (Session["Notice"] == null)
        {
            SuccessMessages.Visible = false;
        }
        else
        {
            SuccessMessages.Visible = true;
            SuccessMessage.Text     = Session["Notice"].ToString();
            Session.Remove("Notice");
        }

        ErrorMessages.Visible = false;
        if (Session["Error"] == null)
        {
            ErrorMessages.Visible = false;
        }
        else
        {
            ErrorMessages.Visible = true;
            ErrorMessage.Text     = Session["Error"].ToString();
            Session.Remove("Error");
        }
    }
コード例 #6
0
ファイル: Main.Master.cs プロジェクト: mwallace1407/Omega
        protected void Page_Load(object sender, EventArgs e)
        {
            string NivelRuta = "";

            string PaginaActual = (this.Page.ToString().Substring(4, this.Page.ToString().Substring(4).Length - 5) + ".aspx").Trim().ToLower();

            if (PaginaActual.Length >= MinimoCadena)
            {
                switch (PaginaActual.Substring(0, 14))
                {
                case "forms_articulo":
                    NivelRuta = "../";
                    break;

                case "forms_catalogo":
                    NivelRuta = "../";
                    break;

                case "forms_software":
                    NivelRuta = "../";
                    break;

                case "forms_reportes":
                    NivelRuta = "../";
                    break;

                case "forms_aplicaci":
                    NivelRuta = "../";
                    break;

                case "forms_administ":
                    NivelRuta = "../";
                    break;

                case "forms_maximage":
                    NivelRuta = "../";
                    break;

                case "forms_servidor":
                    NivelRuta = "../";
                    break;

                case "forms_operacio":
                    NivelRuta = "../";
                    break;
                }

                AplicaEstilo(NivelRuta);
            }


            if (Request.IsAuthenticated)
            {
                if (Session["NombreCompletoUsuario"] != null)
                {
                    ((Label)LoginView3.FindControl("lblNombreCompletoUsuario")).Text = Session["NombreCompletoUsuario"].ToString();
                    //((Label)LoginView3.FindControl("lblNombreCompletoRol")).Text = Session["NombreCompletoRol"].ToString();

                    if (sender.ToString() == "ASP.forms_main_master")
                    {
                        CreaMenu(NivelRuta);
                    }
                }
                else
                {
                    try
                    {
                        Session.Clear();
                        System.Web.Security.FormsAuthentication.SignOut();

                        if ((this.Page.ToString().Substring(4, this.Page.ToString().Substring(4).Length - 5) + ".aspx").Trim().ToLower() != PaginaInicio)
                        {
                            Response.Redirect("~/Forms/sessionTimeout.html");
                        }
                    }
                    catch { Response.Redirect("~/Forms/sessionTimeout.html"); }
                }
            }
            else
            {
                try
                {
                    Session.Clear();
                    System.Web.Security.FormsAuthentication.SignOut();

                    if ((this.Page.ToString().Substring(4, this.Page.ToString().Substring(4).Length - 5) + ".aspx").Trim().ToLower() != PaginaInicio)
                    {
                        Response.Redirect("~/Forms/sessionTimeout.html");
                    }
                }
                catch { Response.Redirect("~/Forms/sessionTimeout.html"); }
            }

            if (!Page.IsPostBack && !Page.IsCallback)
            {
                if (Session["UserNameLogin"] != null && Session["UserNameLogin"].ToString() != "")
                {
                    if (!BLSeguridad.AccesoPermitido(Session["UserNameLogin"].ToString(), this.Page.ToString().Substring(4, this.Page.ToString().Substring(4).Length - 5) + ".aspx"))
                    {
                        Model.DatosGenerales.EnviaMensaje("No tiene autorización para ingresar a la página solicitada: " + this.Page.ToString().Substring(4, this.Page.ToString().Substring(4).Length - 5) + ".aspx", "Permisos insuficientes", Model.DatosGenerales.TiposMensaje.Advertencia);
                    }
                }
            }
        }
コード例 #7
0
    protected void loadDb(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);
        SqlCommand    cmd = null;

        con.Open();

        cmd = new SqlCommand("select * from AspNetUsers", con);
        List <string> users = new List <string>();
        List <string> ids   = new List <string>();


        DataTable      dt = new DataTable();
        SqlDataAdapter da = new SqlDataAdapter(cmd);

        da.Fill(dt);


        foreach (DataRow row in dt.Rows)
        {
            users.Add(row["UserName"].ToString());
            ids.Add(row["id"].ToString());
        }

        System.Web.UI.HtmlControls.HtmlGenericControl adiv =
            (System.Web.UI.HtmlControls.HtmlGenericControl)LoginView3.FindControl("adminDiv");

        // -----------------------------------------

        cmd = new SqlCommand("select * from AspNetUserRoles", con);
        List <string> userids  = new List <string>();
        List <string> rolesids = new List <string>();


        DataTable      dta = new DataTable();
        SqlDataAdapter daa = new SqlDataAdapter(cmd);

        daa.Fill(dta);


        foreach (DataRow row in dta.Rows)
        {
            userids.Add(row["UserId"].ToString());
            rolesids.Add(row["RoleId"].ToString());
        }

        // -----------------------------------------



        for (var i = 0; i < users.Count; ++i)
        {
            System.Web.UI.HtmlControls.HtmlGenericControl p =
                new System.Web.UI.HtmlControls.HtmlGenericControl("p");

            string role = "X";
            for (var j = 0; j < userids.Count; ++j)
            {
                if (ids[i].Equals(userids[j]))
                {
                    if (int.Parse(rolesids[j]) == 1)
                    {
                        role = "Admin";
                    }
                    if (int.Parse(rolesids[j]) == 2)
                    {
                        role = "Moderator";
                    }
                    if (int.Parse(rolesids[j]) == 3)
                    {
                        role = "User";
                    }
                }
            }

            p.InnerHtml = users[i] + " - " + role;


            adiv.Controls.Add(p);
            adiv.Controls.Add(new LiteralControl("<hr>"));
        }

        con.Close();
    }