How to check for specific group on a user Options
Scott the God
Posted: Friday, October 17, 2008 12:31:07 PM

Rank: Devotee

Joined: 10/16/2008
Posts: 64
Location: Spain
Hey,

I'm trying to figure out how I can with one line find out if a specific user is member of a specific group.

I have this code which works but I'd like to optimize it a bit.

Code:

string group = "MY GROUP";
Member m = Member.GetMemberFromLoginNameAndPassword(txtUserName.Text, txtPassword.Text);
           
            foreach (MemberGroup mg in m.Groups.Values)
            {
                if (mg.Text.ToLower().Equals(group))
                {
                    m = null;
                    break;
                }
            }


Thanks

Scott

Scott
Dirk
Posted: Friday, October 17, 2008 12:55:58 PM

Rank: Umbracoholic

Joined: 9/27/2007
Posts: 1,123
Location: Belgium
Hi Scott,

MemberGroup.HasMember(memberId) could be usefull in this case, but you'll need MemberGroup.GetbyName(name) as well

Both methods available in MemberGroup class which resides in umbraco.cms.businesslogic.member namespace

Hope this helps.

Regards,
/Dirk


level 1 & 2 certified - umbraco MVP 2008/2009 - umbraco blog at netaddicts.be - working on an integrated forum4umbraco
Scott the God
Posted: Friday, October 17, 2008 1:02:41 PM

Rank: Devotee

Joined: 10/16/2008
Posts: 64
Location: Spain
I have been trying to get the MemberGroup.HasMember however it does not exist in my businesslogic namespace.

Could you post an example of how to do this?

Thanks

Scott

Scott
Dirk
Posted: Friday, October 17, 2008 1:11:21 PM

Rank: Umbracoholic

Joined: 9/27/2007
Posts: 1,123
Location: Belgium
Nope, scott, don't have a working example (Currently at the client's office).

It should live in the cms assembly (umbraco.cms project if you have the code floating somewhere; Namespaces/assemblies are a bit confusing at times...)

Greetz,
/Dirk


level 1 & 2 certified - umbraco MVP 2008/2009 - umbraco blog at netaddicts.be - working on an integrated forum4umbraco
Scott the God
Posted: Friday, October 17, 2008 3:40:23 PM

Rank: Devotee

Joined: 10/16/2008
Posts: 64
Location: Spain
Could you when you get back please let me know if you can find/make a working example because I don't seem to be able to figure it out.

Thanks

Scott

Scott
Dirk
Posted: Sunday, October 19, 2008 8:22:39 PM

Rank: Umbracoholic

Joined: 9/27/2007
Posts: 1,123
Location: Belgium
Hi Scott,

Got some working example. It is just sample code, but works as expected.
Contact me through e-mail and I'll send some of the code and a sample setup for testing.

Regards,
/Dirk


level 1 & 2 certified - umbraco MVP 2008/2009 - umbraco blog at netaddicts.be - working on an integrated forum4umbraco
Dirk
Posted: Monday, October 20, 2008 7:56:28 PM

Rank: Umbracoholic

Joined: 9/27/2007
Posts: 1,123
Location: Belgium
Hi Scott,

Did you receive my e-mail?

Greetz,
/Dirk


level 1 & 2 certified - umbraco MVP 2008/2009 - umbraco blog at netaddicts.be - working on an integrated forum4umbraco
Scott the God
Posted: Monday, October 20, 2008 9:54:17 PM

Rank: Devotee

Joined: 10/16/2008
Posts: 64
Location: Spain
Hey Dirk,

Thanks I did - I haven't had the time to look at it yet though I have had plenty of things to take care of today. Well a peek - could not help it. I found a quite simple line MemberGroup.GetByname(group).HasMember(m.Id) which checks it. I haven't tested it fully yet though.

I will look more into it tomorrow..

Again thank you very much Dirk.!

Scott

Scott
Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.