Copied to clipboard

Flag this post as spam?

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


  • Sjors Pals 594 posts 244 karma points
    Jul 20, 2009 @ 13:54
    Sjors Pals
    0

    How to retrieve a members membergroups?

    Hi i did intensively look in the code, but can't find it, is it possible to retrieve all membergroups from a particular member?

  • Ron Brouwer768 karma points
    Jul 20, 2009 @ 14:11
    Ron Brouwer
    0

    Is this what you are looking for?

    umbraco.cms.businesslogic.member.MemberGroup.GetAll

    Ron

  • Ron Brouwer768 karma points
    Jul 20, 2009 @ 14:15
  • Martin Bentzen145 karma points
    Jul 20, 2009 @ 14:28
    Martin Bentzen
    1

    I think you you can use something like

    member m = new member(1234);
    foreach (var group in m.Groups){
    //Do something
    }
  • Sjors Pals244 karma points
    Jul 20, 2009 @ 14:50
    Sjors Pals
    0

    Thx got it working,

    protected void btn_Click(object sender, EventArgs e) {
            string groups;
            umbraco.cms.businesslogic.member.Member m =

                umbraco.cms.businesslogic.member.Member.GetMemberFromLoginNameAndPassword(

                login.Text, password.Text);
            if (m != null)
            {
                umbraco.cms.businesslogic.member.Member.AddMemberToCache(m);
                foreach (MemberGroup mg in MemberGroup.GetAll)
                {
                   
                    if (m.Groups.ContainsKey(mg.Id))
                        //my code here
                        lblLogin.Text += "group id=\"" + mg.Id.ToString() + "\" groupName=\"" + mg.Text + "\n";
                }
            }
            else {
                lblLogin.Text = "fout";

            }
        }

  • Ron Brouwer768 karma points
    Jul 20, 2009 @ 14:55
    Ron Brouwer
    0

    Thanks for sharing your result. Please select the solution to close the ticket.

  • Sjors Pals244 karma points
    Jul 21, 2009 @ 08:05
    Sjors Pals
    0

    When my code is finished, i will post it on the wiki, can someone tell me how i can set the topic as solved?

  • Peter Dijksterhuis1721 karma points
    Jul 21, 2009 @ 08:19
    Peter Dijksterhuis
    0

    You can set a topic as solution only if you haven't voted it up yet. There should then also be a green icon next to the thumbs. If you allready voted up, the icon is gone and you can't set it as solution anymore. (They're aware of this and it will be fixed so I've heard)

  • Aaron Powell3018 karma points core c-trib
    Jul 21, 2009 @ 09:58
    Aaron Powell
    2

    If you are using Umbraco 4 I would strongly recommend that you use the standard ASP.NET methods to get back the roles. For example you should do this:

    var roles = System.Web.Security.Roles.GetRolesForUser("user_name");

    This will then go via the umbraco.providers.members.MemberRoleProvider by default, or any custom ASP.NET role provider you choose to implement.

    Directly interacting with the Member API is no longer recommended.

  • Sjors Pals244 karma points
    Jul 21, 2009 @ 10:28
    Sjors Pals
    0

    Thanks for your advice Slace, will change it in my code :)

  • rasb217 karma points
    Jul 21, 2009 @ 19:31
    rasb
    0

    Hi Slace,

    Is there a similar approach to getting user properties? I currently use this membership provider because I want my users to click on an avtivation link I email to them. If they haven't activated themselves, then I don't want to validate them. When they click the link in the email a boolean property called Active is set.

    public class CustomMembershipProvider : umbraco.providers.members.UmbracoMembershipProvider
    {
        public override bool ValidateUser(string username, string password)
        {
            Member m =Member.GetMemberFromLoginAndEncodedPassword(username, EncodePassword(password));
    
            if (m == null)
                return false;
            else
            {
                try
                {
                    if (m.getProperty("active").Value.ToString() == "1")
                        return true;
                    else
                        return false;
                }
                catch
                {
                    return false;
                }
            }
        }
    }

    Could I validate the user using:

    bool validated = base.Validate(username, password);

    And then get the property from the 

    System.Web.Security.MembershipUser

    instead?

    /rasb

     

  • Aaron Powell3018 karma points core c-trib
    Jul 22, 2009 @ 00:56
    Aaron Powell
    0

    @rasb - You really should be using the ASP.NET Profile Provider for this. I think I'm going to have to get around to doing some info on this as it seems to be a common question.

    Long story short (ie - all I've got written yet :P) you can implement a ProfileProvider (MSDN has examples of how to set one up) and then specify the ProfileProvider class to be umbraco.providers.members.UmbracoProfileProvider

  • rasb217 karma points
    Jul 22, 2009 @ 11:46
    rasb
    0

    Hi Slace,

    I will try to look into ProfileProviders, but since this works for now, I am afraid it is being bumped down the list of priorities :(

    But a list of "best practices" on the wiki would be a good idea as you say yourself.

    /rasb

  • Aaron Powell3018 karma points core c-trib
    Jul 22, 2009 @ 13:26
    Aaron Powell
    1

    I've done a post on the ProfileProvider which I'll put onto the wiki when you are able to upload images onto it! http://www.aaron-powell.com/blog/july-2009/umbraco-member-profiles.aspx is where the info is at the moment

  • rasb217 karma points
    Jul 22, 2009 @ 13:39
    rasb
    0

    What about the Access class? Is that also deprecated then?

    I am thinking of for example checking to see if a node i protected like this:

    if (!Access.IsProtected(n.Id, n.Path) || Access.GetProtectionType(n.Id) == ProtectionType.NotProtected)

    Is there a way to that through the provider?

    /rasb

  • Aaron Powell3018 karma points core c-trib
    Jul 22, 2009 @ 13:50
    Aaron Powell
    0

    I'm not sure, I've never looked into the Access class. I'll put that on the cards for tomorrow

Please Sign in or register to post replies

Write your reply to:

Draft
Our.umbraco.org is the community mothership for Umbraco, the open source asp.net cms. With a friendly forum for all your questions, a comprehensive documentation and a ton of packages from the community. This site is running Umbraco version 7.3.0-RC