Exemple #1
0
    private static List<ForumJumpto> GetForumJumpTo()
    {
        string[] rolelist = new SnitzRoleProvider().GetRolesForUser(HttpContext.Current.User.Identity.Name);
        List<ForumJumpto> result = new List<ForumJumpto>();

        foreach (ForumJumpto fo in SnitzCachedLists.GetCachedForumList(false))
        {
            fo.Roles = Forums.GetForumRoles(fo.Id).ToList();
            if (rolelist.Length == 0)
                if (fo.Roles.Count == 0)
                    result.Add(fo);
            foreach (string role in rolelist)
            {
                if(result.Contains(fo))
                    break;
                switch (role)
                {
                    case "Administrator":
                        result.Add(fo);
                        break;
                    default:
                        if (fo.Roles.Count == 0)
                            result.Add(fo);
                        else if (fo.Roles.Contains(role))
                            result.Add(fo);
                        break;
                }
            }
        }

        return result;
    }
    protected void btnNewSubmit_Click(object sender, EventArgs e)
    {
        SnitzRoleProvider srp = new SnitzRoleProvider();
        // Check if the RoleID exists

        bool idExists = srp.RoleExists(Convert.ToInt32(txtNewRoleID.Text));

        if (idExists) // Check if the RoleID exists
        {
            errLbl.Text = "The chosen RoleID already exists. Please choose another!";
            errLbl.Visible = true;
            return;
        }

        errLbl.Visible = false;

        // Check if the role name already exists

        bool nameExists = Roles.RoleExists(txtNewName.Text);

        if (nameExists) // Check if the RoleID exists
        {
            errLbl.Text = "The chosen role name already exists. Please choose another!";
            errLbl.Visible = true;
            return;
        }

        //Ok, so the data  that could be invalid is valid, let's create the role.

        bool res = srp.CreateRoleFullInfo(txtNewName.Text, txtNewDescription.Text, Convert.ToInt32(txtNewRoleID.Text));

        if (!res)
        {
            errLbl.Text = "Error writing new role to database";
            errLbl.Visible = true;
        }
        else
        {
            errLbl.Text = "New Role Successfully Created!";
            errLbl.Visible = true;

            txtNewRoleID.Text = "";
            txtNewName.Text = "";
            txtNewDescription.Text = "";
        }
    }
        public static Dictionary<int, string> UserRoles()
        {
            Dictionary<int, string> result = new Dictionary<int, string>();
            if (HttpContext.Current.Session == null)
                return result;

            if (HttpContext.Current.Session["RoleList"] != null)
            {
                result = HttpContext.Current.Session["RoleList"] as Dictionary<int, string>;
            }
            else
            {
                result = new SnitzRoleProvider().ListAllRolesForUser(HttpContext.Current.User.Identity.Name);
                if (result.Count > 0)
                    HttpContext.Current.Session.Add("RoleList", result);
            }

            return result;
        }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        int avIndex = Convert.ToInt32(DropDownList1.SelectedValue);

        MultiView1.ActiveViewIndex = avIndex;

        SnitzRoleProvider srp = new SnitzRoleProvider();

        if (avIndex == 0) //Moderator View
        {
            if (ModeratorList.Items.Count == 0) // if the list has never been filled
            {

                ModeratorList.DataSource = srp.GetUsersInRole("Moderator");
                ModeratorList.DataTextField = "u.UserName";
                ModeratorList.DataValueField = "u.UserId";
                ModeratorList.DataBind();

                if (ModeratorList.SelectedItem == null)
                    ModeratorList.SelectedIndex = 0;
            }

            int memberId = Convert.ToInt32(ModeratorList.SelectedItem.Value);

            Dictionary<int, string> unForumList = Moderators.GetUnModeratedForumsIdNameList(memberId);
            AvForumsList.DataSource = unForumList;
            AvForumsList.DataTextField = "Value";
            AvForumsList.DataValueField = "Key";

            Dictionary<int, string> forumList = Moderators.GetModeratedForumsIdNameList(memberId);
            MdForumsList.DataSource = forumList;
            MdForumsList.DataTextField = "Value";
            MdForumsList.DataValueField = "Key";

        }
        else  // Forums View
        {
            if (ForumsList.Items.Count == 0)
            {

                ForumsList.DataSource = Forums.GetAllForums();
                ForumsList.DataTextField = "Subject";
                ForumsList.DataValueField = "Id";

                ForumsList.DataBind();

                if (ForumsList.SelectedItem == null)
                    ForumsList.SelectedIndex = 0;
            }

            int forumId = Convert.ToInt32(ForumsList.SelectedItem.Value);

            Dictionary<int, string> avList = Moderators.GetAvailableModeratorsIdName(forumId);
            AvModsList.DataSource = avList;
            AvModsList.DataTextField = "Value";
            AvModsList.DataValueField = "Key";

            Dictionary<int, string> mList = Moderators.GetCurrentModeratorsIdName(forumId);
            CurModsList.DataSource = mList;
            CurModsList.DataTextField = "Value";
            CurModsList.DataValueField = "Key";

        }

        Page.DataBind();
    }
    protected void SaveBtn_Click(object sender, EventArgs e)
    {
        int memberID = Convert.ToInt32(ModeratorList.SelectedValue);
            int count = 0;
            int[] forumList = new int[MdForumsList.Items.Count];

            foreach (ListItem li in MdForumsList.Items)
                    forumList[count++] = Convert.ToInt32(li.Value);

            SnitzRoleProvider srp = new SnitzRoleProvider();
            Moderators.SetUserAsModeratorForForums(memberID, forumList);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            SnitzRoleProvider srp = new SnitzRoleProvider();
            int avIndex = Convert.ToInt32(DropDownList1.SelectedValue);
            MultiView1.ActiveViewIndex = Convert.ToInt32(DropDownList1.SelectedValue);

            if (avIndex == 0) //Moderator View
            {
                int memberId;

                ModeratorList.DataSource = Moderators.GetAll();
                ModeratorList.DataTextField = "Name";
                ModeratorList.DataValueField = "MemberId";

                ModeratorList.DataBind();

                if (ModeratorList.SelectedItem == null)
                    ModeratorList.SelectedIndex = 0;
                if (ModeratorList.Items.Count > 0)
                    memberId = Convert.ToInt32(ModeratorList.SelectedValue);
                else
                {
                    SaveBtn.Enabled = false;
                    memberId = 0;
                }

                Dictionary<int, string> unForumList = Moderators.GetUnModeratedForumsIdNameList(memberId);
                AvForumsList.DataSource = unForumList;
                AvForumsList.DataTextField = "Value";
                AvForumsList.DataValueField = "Key";

                Dictionary<int, string> forumList = Moderators.GetModeratedForumsIdNameList(memberId);
                MdForumsList.DataSource = forumList;
                MdForumsList.DataTextField = "Value";
                MdForumsList.DataValueField = "Key";
            }
            else  // Forums View
            {
                //DataTable fList = ForumDatasource.GetForumsIDSubject();

                ForumsList.DataSource = Forums.GetAllForums();
                ForumsList.DataTextField = "Title";
                ForumsList.DataValueField = "ForumId";

                ForumsList.DataBind();

                if (ForumsList.SelectedItem == null)
                    ForumsList.SelectedIndex = 0;

                int forumId = Convert.ToInt32(ForumsList.SelectedItem.Value);

                List<MemberInfo> avList = Moderators.GetAvailableModerators(forumId);
                AvModsList.DataSource = avList;
                AvModsList.DataTextField = "Username";
                AvModsList.DataValueField = "Id";

                CurModsList.DataSource = Forums.GetForumModerators(forumId);
                CurModsList.DataTextField = "Value";
                CurModsList.DataValueField = "Key";

            }

            Page.DataBind();
        }
    }
    private void RefreshUserList()
    {
        UserList.Items.Clear();
        SnitzRoleProvider srp = new SnitzRoleProvider();
        srp.GetUsersInRole(txtName.Text);
        UserList.DataSource = srp.GetUsersInRole(txtName.Text);
        UserList.DataBind();

        UsersInRole.Text = String.Format("{0} User(s) in {1} Role", UserList.Items.Count, txtName.Text);
        NewUserForRole.Text = "";
    }
    protected void NewUsername_Click(object sender, EventArgs e)
    {
        string[] roles = new string[1];
        string[] users = new string[1];

        SnitzRoleProvider srp = new SnitzRoleProvider();
        roles[0] = txtName.Text;
        users[0] = NewUserForRole.Text;

        srp.AddUsersToRoles(users, roles);
        RefreshUserList();
    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "DeleteClick")
        {
            try
            {
                if (Roles.DeleteRole(e.CommandArgument.ToString(), !delPopRoles.Checked))
                {
                    errLbl2.Text = "Role deleted successfully.";
                    errLbl2.Visible = true;
                }
            }
            catch (ProviderException p)
            {
                errLbl2.Text = p.Message;
                errLbl2.Visible = true;
            }

            RoleTable.DataBind();
        }

        if (e.CommandName == "EditClick")
        {
            SnitzRoleProvider srp = new SnitzRoleProvider();

            int roleid = Convert.ToInt32(e.CommandArgument);
            RoleInfo role  = SnitzRoleProvider.GetRoleFull(roleid);

            txtRoleID.Text = roleid.ToString();
            txtName.Text = role.RoleName;
            txtDescription.Text = role.Description.ToString();
            UsersInRole.Text = String.Format("{0} User(s) in {1} Role", srp.GetUsersInRole(txtName.Text).Length, role.RoleName);
            RoleView.SetActiveView(viewEditRole);
            errLbl2.Visible = false;

            UserListPanel.Visible = (roleid > 1);
            RefreshUserList();
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        if (UserList.SelectedIndex == -1)
            return;
        string[] roles = new string[1];
        string[] users = new string[1];

        roles[0] = txtName.Text;
        users[0] = UserList.SelectedItem.Text;

        SnitzRoleProvider srp = new SnitzRoleProvider();
        srp.RemoveUsersFromRoles(users, roles);
        RefreshUserList();
    }
Exemple #11
0
        private void UpdateUserRoles()
        {
            UpdateProgress(0,"Adding adninistrator/moderators to role table<br/>");
            string[] admins = Moderators.GetForumAdmins();
            var mods = Moderators.GetAll();

            SnitzRoleProvider roles = new SnitzRoleProvider();
            roles.AddUsersToRoles(admins, new string[] { "Administrator" });
            roles.AddUsersToRoles(mods.Select(m => m.Name).ToArray(), new string[] { "Moderator" });
            UpdateProgress(0,"UserRoles Table Updated</br>");
            Thread.Sleep(500);
        }
Exemple #12
0
        private void UpdateForumAllowedRoles()
        {
            //1, 6 '## Allowed Users
            //2 '## password
            //3 '## Either Password or Allowed
            //7 '## members or password
            //4, 5 '## members only
            UpdateProgress(0,"Updating allowed forum lists<br/>");
            Thread.Sleep(500);
            SnitzRoleProvider roles = new SnitzRoleProvider();
            var privateforums = Snitz.BLL.Admin.PrivateForums();
            int newroleid = 500;

            foreach (ForumInfo forum in privateforums)
            {
                int forumid = forum.Id;
                string description = forum.Subject;

                switch (forum.PrivateForum)
                {
                    case 4: //## members
                    case 5:
                    case 7:
                        RoleInfo rInfo = SnitzMembership.Helpers.BusinessUtil.GetRoleFull(1);
                        string role = rInfo.RoleName.ToLower();
                        SnitzMembership.Helpers.BusinessUtil.AddRolesToForum(forumid, new[] { role });
                        break;
                    case 1: //## Allowed Users
                    case 3:
                    case 6:
                        //create a Role for this forum
                        string rolename = "Forum_" + forumid;
                        roles.CreateRoleFullInfo(rolename, description, newroleid);
                        SnitzMembership.Helpers.BusinessUtil.AddRolesToForum(forumid, new[] { rolename });
                        //get the allowed members for this forum and add to the new role
                        string[] allowedmembers = Snitz.BLL.Admin.AllowedMembers(forumid);
                        roles.AddUsersToRoles(allowedmembers, new[] { rolename });

                        newroleid++;
                        break;
                }
            }
            UpdateProgress(0,"ForumAllowedRoles Updated</br>");
            Thread.Sleep(500);
        }
Exemple #13
0
 private void AddRoles()
 {
     UpdateProgress(0,"Adding default Roles<br/>");
     SnitzRoleProvider roles = new SnitzRoleProvider();
     if(!roles.RoleExists("Administrator"))
         roles.CreateRoleFullInfo("Administrator", "Forum Administrator", 99);
     if (!roles.RoleExists("Member"))
         roles.CreateRoleFullInfo("Member", "Snitz Forum member", 1);
     if (!roles.RoleExists("Moderator"))
         roles.CreateRoleFullInfo("Moderator", "Snitz Forum Moderator", 10);
     if (!roles.RoleExists("All"))
         roles.CreateRoleFullInfo("All", "All Visitors", 0);
     UpdateProgress(0,"New Forum Roles Added</br>");
 }