Esempio n. 1
0
        public RoleStruct[] GetUsers(string sDomain)
        {
            using (new Sitecore.SecurityModel.SecurityDisabler())
            {
                Sitecore.SecurityModel.Domain domain = Sitecore.SecurityModel.Domain.FromName(sDomain);
                Sitecore.Data.Database        db     = domain.Database;
                if (db == null)
                {
                    return(null);
                }
                // create a query that will handle the Role retrieval
                // here we simply rely on the Role's Template ID
                string query = "//*[@@templateid='" + Sitecore.TemplateIDs.User + "']";

                Sitecore.Data.Items.Item[]        items = db.SelectItems(query);
                Sitecore.SecurityModel.UserItem[] users = new Sitecore.SecurityModel.UserItem[items.Length];

                List <RoleStruct> roles5x = new List <RoleStruct>();
                // fill this array with Role Items
                for (int i = 0; i < users.Length; i++)
                {
                    users[i] = new Sitecore.SecurityModel.UserItem(items[i], domain);
                    RoleStruct role = new RoleStruct();
                    role.Name        = users[i].Domain.Name + "\\" + users[i].Name;
                    role.ID          = users[i].ID.ToString();
                    role.Path        = users[i].InnerItem.Paths.ContentPath;
                    role.AccessRight = AccessRights.NotSet;
                    role.Email       = users[i].Email;
                    role.FullName    = users[i].Fullname;
                    if (users[i].InnerItem.Fields["password"] != null)
                    {
                        role.PassWord = users[i].InnerItem.Fields["password"].Value;
                    }
                    role.IsAdmin = users[i].IsAdministrator;
                    role.Roles   = "";
                    for (int t = 0; t < users[i].Roles.RoleNames.Length; t++)
                    {
                        if (role.Roles != "")
                        {
                            role.Roles += "|";
                        }
                        role.Roles += users[i].Roles.RoleNames[t];
                    }
                    roles5x.Add(role);
                }
                return(roles5x.ToArray());
            }
        }
Esempio n. 2
0
        public RoleStruct[] GetUsers(string sDomain)
        {
            using (new Sitecore.SecurityModel.SecurityDisabler())
            {
                Sitecore.SecurityModel.Domain domain = Sitecore.SecurityModel.Domain.FromName(sDomain);
                Sitecore.Data.Database db = domain.Database;
                if (db == null)
                {
                    return null;
                }
                // create a query that will handle the Role retrieval
                // here we simply rely on the Role's Template ID
                string query = "//*[@@templateid='" + Sitecore.TemplateIDs.User + "']";

                Sitecore.Data.Items.Item[] items = db.SelectItems(query);
                Sitecore.SecurityModel.UserItem[] users = new Sitecore.SecurityModel.UserItem[items.Length];

                List<RoleStruct> roles5x = new List<RoleStruct>();
                // fill this array with Role Items
                for (int i = 0; i < users.Length; i++)
                {
                    users[i] = new Sitecore.SecurityModel.UserItem(items[i], domain);
                    RoleStruct role = new RoleStruct();
                    role.Name = users[i].Domain.Name + "\\" + users[i].Name;
                    role.ID = users[i].ID.ToString();
                    role.Path = users[i].InnerItem.Paths.ContentPath;
                    role.AccessRight = AccessRights.NotSet;
                    role.Email = users[i].Email;
                    role.FullName = users[i].Fullname;
                    if (users[i].InnerItem.Fields["password"] != null)
                        role.PassWord = users[i].InnerItem.Fields["password"].Value;
                    role.IsAdmin = users[i].IsAdministrator;
                    role.Roles = "";
                    for (int t=0; t<users[i].Roles.RoleNames.Length; t++)
                    {
                        if (role.Roles != "")
                            role.Roles += "|";
                        role.Roles += users[i].Roles.RoleNames[t];
                    }
                    roles5x.Add(role);
                }
                return roles5x.ToArray();
            }
        }