Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Daniel Larsen 116 posts 381 karma points
    Feb 24, 2015 @ 14:09
    Daniel Larsen
    0

    How to make shared and private content?

    Hello!

    I am making a website, where there is a login protected members area. I know how to make that, so that is not the problem.

    I want some information to be visible to all members and some information to be visible to only one or a few members. See example below.

    Home (all)
    - News (all)
    - Images (private)
    - Calendar (all)
    - Documents (some for all / some private)
    

    How do I set this up, in the best possible way?

    Using u7 and Razor.

    Thank you for your help!

    Daniel

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Feb 24, 2015 @ 14:19
    Jan Skovgaard
    1

    Hi Daniel

    You should be able to control this using Member groups - On the "Images" node you setup protection and only allow members of certain groups.

    Then in your razor rendering you can check if an item is restricted or accessible by all.

    The same goes for "Documents" but you will need to group them in "public" and "Restricted" childs...if you need to hide some of the restricted documents for certain members but make them visible for other members you need to have more user groups and a structure that allows you to specify that certain documents in the restricted area are only visible for a certain group as well.

    I hope this makes sense? :)

    /Jan

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Feb 24, 2015 @ 14:21
    Jan Skovgaard
    1

    You should be able to check for access using a combination of .HasAccess() .IsProtected() btw.

    /Jan

  • Tobias Klika 101 posts 570 karma points c-trib
    Feb 24, 2015 @ 14:22
    Tobias Klika
    1

    All Members belong to one or more Roles.
    You can easily set up new roles in the Members Dashboard.

    If you right-click on a page in the content tree, you can select Public Access => Role based, where you can specify the roles which have access to the page.

    You can also check if a member is in a role or group or whatever in the code with MembershipHelper.IsMemberAuthorized().

    If you want to do checks (i.e. Documents) for specific members, you can do something like this in your controller:

    Document myDocument = ....
    
    if (!Members.IsLoggedIn() || Members.GetCurrentMember().Id != myDocument.CreatorId)
    {
      return new HttpStatusCodeResult(HttpStatusCode.Forbidden);
    }
    

    Hope this helps, bye Tobi

  • Daniel Larsen 116 posts 381 karma points
    Feb 24, 2015 @ 14:48
    Daniel Larsen
    0

    Thank you both! I'll give it a try!

  • Daniel Larsen 116 posts 381 karma points
    Feb 25, 2015 @ 09:19
    Daniel Larsen
    0

    Just a quick question.

    Is this the way to structure it? Or do you have a better surgestion?

    Home (all)
    - News (all)
    - Images (private)
    --- Ryan
    --- Sophie
    --- James
    - Calendar (all)
    - Documents (some for all / some private)
    --- Shared
    --- Ryan
    --- Sophie
    --- James
    

    Thank you!

    Daniel

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Feb 25, 2015 @ 09:21
    Jan Skovgaard
    1

    Hi Daniel

    I think that structure looks fine and it should work fine as well :)

    /Jan

  • Daniel Larsen 116 posts 381 karma points
    Feb 25, 2015 @ 09:40
    Daniel Larsen
    0

    Thank you! :-)

  • Daniel Larsen 116 posts 381 karma points
    Feb 28, 2015 @ 14:45
    Daniel Larsen
    0

    Hi again

    I tried doing it, but it does not seem to work. I added role based protection to the parent nodes and it doesnt work.

    Home - access for all members
    - News
    - Images
    - Calendar
    - Documents
    --- Shared - no protection other than from the top level node
    ----- node
    ----- node
    ----- node
    --- Ryan - Added protection for first group
    ----- node
    ----- node
    ----- node
    --- Sophie  - Added protection for second group
    ----- node
    ----- node
    ----- node
    

    Here is my partial view:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    @if (CurrentPage.Children.Where("Visible").Any())
    {
        <ul>            
            @foreach (var childPage in CurrentPage.Children.Where("Visible"))
            {
                if(childPage.HasAccess())
                {
                    <li>
                        <a href="@childPage.Url">@childPage.Name</a>
                    </li>
    
                    foreach (var item in childPage.Children.Where("Visible")) 
                    {
                        <a href="@item.Url">@item.Name</a><br>
                    }
                }
            }
        </ul>
    }
    

    When the if.HasAccess is not here, everything is shown, but when there, nothing is shown.

    Can you guys see, where I am going wrong?

    Thank you for your help! :-)

    Daniel

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Feb 28, 2015 @ 17:51
    Jan Skovgaard
    0

    Hi Daniel

    Are you logged in as either of the groups when nothing is shown? And what exact version of Umbraco 7 are you using?

    /Jan

  • Daniel Larsen 116 posts 381 karma points
    Feb 28, 2015 @ 17:56
    Daniel Larsen
    0

    Yes, I am logged in.

    I am using the second newest version. Don't remember the number. :-)

    Daniel

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Feb 28, 2015 @ 18:16
    Jan Skovgaard
    0

    Hi Daniel

    Ok - Don't know if it will work but could you try to upgrade to 7.2.2? I think the above code looks fine and should be working...but have not tried doing it in Razor before though.

    /Jan

  • Daniel Larsen 116 posts 381 karma points
    Feb 28, 2015 @ 18:43
    Daniel Larsen
    0

    Hi Jan

    It did not work, but it was worth a try :-)

    Thanks!

    Daniel

  • Shlomit Levikson 1 post 71 karma points
    Dec 22, 2016 @ 10:09
    Shlomit Levikson
    0

    Hello Daniel,

    I see that you wrote:

    "I am making a website, where there is a login protected members area. I know how to make that, so that is not the problem."

    But i do not know how to do this, and I don't find anything about it in the internet, can anyone help me? How should I make private area? Via code, or via CMS? Thank you all!

  • Steve Morgan 1346 posts 4453 karma points c-trib
    Dec 22, 2016 @ 12:59
    Steve Morgan
    0

    Hi Shlomit,

    Try working through my blog posts:

    That should cover what you need. Any questions - start a new thread !

    Hope that helps

    Steve

Please Sign in or register to post replies

Write your reply to:

Draft