Esempio n. 1
0
        /// <summary>
        /// Adds a user to a role
        /// </summary>
        /// <param name="user"/><param name="roleName"/>
        /// <returns/>
        public Task AddToRoleAsync(TMember user, string roleName)
        {
            ThrowIfDisposed();
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }
            if (string.IsNullOrWhiteSpace(roleName))
            {
                throw new ArgumentException("roleName is null or empty");
            }

            var roleEntity = _memberGroupService.GetByName(roleName);

            if (roleEntity == null)
            {
                throw new InvalidOperationException(roleName + " does not exist as a role");
            }

            var roles    = user.Roles;
            var instance = new IdentityMemberRole {
                UserId = user.Id, RoleName = roleEntity.Name
            };
            var userRole = instance;

            roles.Add(userRole);

            return(Task.FromResult(0));
        }
        public SecurityGroup CreateOrFindGroup(string groupNamePrefix, string suggestedGroupName, IEnumerable <string> noiseWords)
        {
            var          groupName = _routeGenerator.GenerateRoute(groupNamePrefix, suggestedGroupName, noiseWords);
            IMemberGroup group;

            do
            {
                group = _memberGroupService.GetByName(groupName);
                if (group == null)
                {
                    group = new MemberGroup
                    {
                        Name = groupName
                    };
                    _memberGroupService.Save(group);
                    break;
                }
                else
                {
                    groupName = _routeGenerator.IncrementRoute(groupName);
                }
            }while (group != null);

            return(new SecurityGroup {
                Key = group.Key, Name = group.Name
            });
        }
Esempio n. 3
0
        public Task <T> FindByNameAsync(string roleName)
        {
            var memberGroup = _memberGroupService.GetByName(roleName);

            return(Task.FromResult(memberGroup == null
                ? (T)null
                : MapFromMemberGroup(memberGroup)));
        }
        public virtual int Create(string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                return(int.MinValue);
            }
            var group = _memberGroupService.GetByName(name);

            if (group != null)
            {
                return(group.Id);
            }
            _memberGroupService.Save(new MemberGroup {
                Name = name
            });
            group = _memberGroupService.GetByName(name);

            ClearCache();

            return(group.Id);
        }
Esempio n. 5
0
        /// <inheritdoc />
        public Task <UmbracoIdentityRole> FindByNameAsync(string name, CancellationToken cancellationToken = default)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();

            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException(nameof(name));
            }
            IMemberGroup memberGroup = _memberGroupService.GetByName(name);

            return(Task.FromResult(memberGroup == null ? null : MapFromMemberGroup(memberGroup)));
        }
Esempio n. 6
0
        public bool IsMemberGroupNameUnique(int id, string oldName, string newName)
        {
            if (newName == oldName)
            {
                return(true); // name hasn't changed
            }
            var memberGroup = _memberGroupService.GetByName(newName);

            if (memberGroup == null)
            {
                return(true); // no member group found
            }
            return(memberGroup.Id == id);
        }
Esempio n. 7
0
        public IEnterspeedProperty Convert(IPublishedProperty property)
        {
            var value      = property.GetValue <string>();
            var arrayItems = new List <IEnterspeedProperty>();

            if (!string.IsNullOrWhiteSpace(value))
            {
                var memberGroupNames = value.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                var memberGroups     = memberGroupNames.Select(x => _memberGroupService.GetByName(x)).ToList();

                foreach (var memberGroup in memberGroups)
                {
                    var memberGroupObject = ConvertToEnterspeedProperty(memberGroup);
                    if (memberGroupObject != null)
                    {
                        arrayItems.Add(memberGroupObject);
                    }
                }
            }

            return(new ArrayEnterspeedProperty(property.PropertyTypeAlias, arrayItems.ToArray()));
        }
Esempio n. 8
0
 public IMemberGroup GetGroupByName(string groupName)
 {
     return(_memberGroupService.GetByName(groupName));
 }
Esempio n. 9
0
        public string CreateForumContent(int rootId)
        {
            StringBuilder contentStatus = new StringBuilder();


            if (rootId == -1)
            {
                var home = _contentService.GetRootContent().FirstOrDefault();
                rootId = home.Id;
            }

            var rootNode = _contentService.GetById(rootId);

            if (rootNode == null)
            {
                contentStatus.Append("<p>Can't find that node </p>");
                return(contentStatus.ToString());
            }

            var test = Umbraco.ContentAtRoot().DescendantsOrSelfOfType("forum").ToList();

            if (test.Any())
            {
                contentStatus.Append("<ul>");
                if (Umbraco.ContentAtRoot().DescendantsOrSelfOfType("forumSearch") == null)
                {
                    rootNode = _contentService.GetById(test.FirstOrDefault().Id);
                    contentStatus.Append("<li>Creating Search holder: ");
                    var srchnode = _contentService.Create("ForumSearch", rootNode, "forumSearch");
                    if (srchnode != null)
                    {
                        srchnode.SetValue("intPageSize", 5);
                        _contentService.SaveAndPublish(srchnode);
                        contentStatus.Append("<strong>done</strong>");
                    }
                    contentStatus.Append("</li>");
                }

                contentStatus.Append("<li>Forum Content already exists</li>");
                contentStatus.Append("</ul>");
                return(contentStatus.ToString());
            }
            contentStatus.Append("<ul>");

            contentStatus.Append("<li>Creating Forums Node: ");
            var rootnode = _contentService.Create("Forums", rootNode, "forum");

            if (rootnode != null)
            {
                rootnode.SetValue("forumName", "Media Wizard Forums for Umbraco");
                rootnode.SetValue("forumIntro",
                                  @"<p>Thank you for installing the MediaWizards forum package. We hope you enjoy this great tool to support your organization!</p>
                    <p>Many thanks go out to <a href=''>Kevin Jump</a> for the original source code and to all the members of Our Umbraco at <a href=''>http://our.umbraco.com/forum</a> for helping to test.</p>");
                rootnode.SetValue("forumActive", true);
                rootnode.SetValue("hideChildrenFromNav", true);
                rootnode.SetValue("intPageSize", 10);
                _contentService.SaveAndPublish(rootnode);
                contentStatus.Append("<strong>done</strong>");
                rootNode = rootnode;
            }
            contentStatus.Append("</li>");
            contentStatus.Append("<li>Creating Default Forum: ");
            var testnode = _contentService.Create("Test Forum", rootNode, "forum");

            if (testnode != null)
            {
                testnode.SetValue("forumName", "Test Forum");
                testnode.SetValue("forumIntro", "This forum gives you a chance to become more familiar with how this product responds to different features and keeps testing in one place instead of posting tests all over. Happy Posting!");
                testnode.SetValue("forumActive", true);
                testnode.SetValue("postAtRoot", true);
                testnode.SetValue("intPageSize", 10);

                _contentService.SaveAndPublish(testnode);
                contentStatus.Append("<strong>done</strong>");
            }
            contentStatus.Append("</li>");

            contentStatus.Append("<li>Creating Private Forum: ");
            var privnode = _contentService.Create("Private Forum", rootNode, "forum");

            if (privnode != null)
            {
                privnode.SetValue("forumName", "ForumSearch");
                privnode.SetValue("forumIntro", "This is a private forum, it can only be seen by certain Member Groups, defined under 'Can View groups'");
                privnode.SetValue("forumActive", true);
                privnode.SetValue("postAtRoot", true);
                privnode.SetValue("intPageSize", 20);
                privnode.SetValue("membersOnly", true);
                var moderator = _memberGroupService.GetByName("ForumModerator");
                var admin     = _memberGroupService.GetByName("ForumAdministrator");

                privnode.SetValue("canViewGroups", $"{moderator.Id.ToString()},{admin.Id.ToString()}");
                privnode.SetValue("canPostGroups", moderator.Id.ToString());
                _contentService.SaveAndPublish(privnode);
                contentStatus.Append("<strong>done</strong>");
            }
            contentStatus.Append("</li>");

            contentStatus.Append("<li>Creating Search holder: ");
            var node = _contentService.Create("ForumSearch", rootNode, "forumSearch");

            if (node != null)
            {
                node.SetValue("intPageSize", 5);
                _contentService.SaveAndPublish(node);
                contentStatus.Append("<strong>done</strong>");
            }
            contentStatus.Append("</li>");
            contentStatus.Append("</ul>");

            contentStatus.Append("<p><strong>Basic Forum pages created</strong></p>");
            string data = "{\"root\": \"" + rootNode.Id + "\", \"content\": \"" + contentStatus.ToString() + "\"}";

            return(data);
        }