x First time here? Check out the FAQ
Join us a the Umbraco event of the year - get your Codegarden 14 early bird ticket today
  • Avatar591posts221karma

    How to retrieve a members membergroups?

    Sjors Pals started this topic July 20, 2009 @ 01:54

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


  • Avatar273posts768karma
    Comment with ID: 10118
    Ron Brouwer posted this reply July 20, 2009 @ 02:11

    Is this what you are looking for?

    umbraco.cms.businesslogic.member.MemberGroup.GetAll

    Ron


  • Avatar273posts768karma
    Comment with ID: 10119
    Ron Brouwer posted this reply July 20, 2009 @ 02:15

  • Avatar83posts145karma
    Comment with ID: 10120
    Martin Bentzen posted this reply July 20, 2009 @ 02:28

    I think you you can use something like

    member m = new member(1234);
    foreach (var group in m.Groups){
    //Do something
    }

  • Avatar591posts221karma
    Comment with ID: 10122
    Sjors Pals posted this reply July 20, 2009 @ 02:50

    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";

            }
        }


  • Avatar273posts768karma
    Comment with ID: 10125
    Ron Brouwer posted this reply July 20, 2009 @ 02:55

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


  • Avatar591posts221karma
    Comment with ID: 10172
    Sjors Pals posted this reply July 21, 2009 @ 08:05

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


  • Avatar1442posts1720karma
    Comment with ID: 10175
    Peter Dijksterhuis posted this reply July 21, 2009 @ 08:19

    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)


  • Avatar1687posts2997karma
    CoreComment with ID: 10186
    Aaron Powell posted this reply July 21, 2009 @ 09:58

    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.


  • Avatar591posts221karma
    Comment with ID: 10189
    Sjors Pals posted this reply July 21, 2009 @ 10:28

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


  • Avatar162posts217karma
    Comment with ID: 10263
    rasb posted this reply July 21, 2009 @ 07:31

    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

     


Pages:

Please login or Sign up To post replies