YAFLogo

Zero2Cool
  • Zero2Cool
  • 100% (Exalted)
  • YAF Leader Topic Starter YAF Version: YAF 3.1.16
11 years ago
I'm creating a role called Probation . It will be set to IsStart for users and will permit them read access to all forums and member access to one section where they are instructed to introduce themselves.

I have an executable that runs every 3 minutes that checks for new users. If one is found, a Welcome PM is sent to them. I will be expanding this executable to check for users in group Probation and if they have one ore more posts, they will be promoted to the Registered role.

UserId is 2243

Probation role is 22

Registered role is 3

Stored Procedure attempt failed

 yaf_usergroup_save 2243,3,1

SQL statement failed

  update yaf_usergroup
  set GroupID = 3
  where groupid = 22
  and UserID = 2243

I looked at the source code and there is a sync of some kind that is done after a role is changed, right? How do I emulate this or trigger it outside of YAF?

Sponsor
Zero2Cool
  • Zero2Cool
  • 100% (Exalted)
  • YAF Leader Topic Starter YAF Version: YAF 3.1.16
11 years ago
If anyone can point me in the right direction to achieve this goal, that'd be great too.
tha_watcha
  • tha_watcha
  • 100% (Exalted)
  • YAF.NET Project Lead 🤴 YAF Version: 4.0.0 rc 2
11 years ago
You need to add the user to the role also via the role manager.

if (!RoleMembershipHelper.IsUserInRole(userName, roleName))

{

RoleMembershipHelper.AddUserToRole(userName, roleName);

}

and also do not forget to clear the access table for that user

YAFContext.Current.Get().Remove(Constants.Cache.ActiveUserLazyData.FormatWith(userID));

Zero2Cool
  • Zero2Cool
  • 100% (Exalted)
  • YAF Leader Topic Starter YAF Version: YAF 3.1.16
11 years ago
I referenced the YAF.Core to have access to the role helper, but then I got "The Role Manager feature has not been enabled." while testing.

That deleting activeaccess made me try this and it appears to have worked.

delete yaf_ActiveAccess where userid = 2243

yaf_usergroup_save 2243, 3, 1

Edit, hmmm. It did update the access properly and now the user has access to create topics, reply, etc as necessary. But, the user profile says they are under role "Probation" when it should be "Registered".

Edit2, the user 2243 GroupId is still 22 which is role Probation, however, userid 2243 has the access of GroupId 3 which is role Registered.

Zero2Cool
  • Zero2Cool
  • 100% (Exalted)
  • YAF Leader Topic Starter YAF Version: YAF 3.1.16
11 years ago
22 = probation role

3 = registered role

logged into account, probation role working as expected, meaning I can only post/reply in one section.

So I checked the groupid

select * from yaf_UserGroup where UserID = 2243

groupid = 22

Then..

delete yaf_ActiveAccess where userid = 2243

delete yaf_usergroup where userid = 2243 and groupid = 22

yaf_usergroup_save 2243,3,1

I can now post as registered role as expected

Then...

select * from yaf_UserGroup where UserID = 2243

groupid = 3

SO ... okay we're all good. I logged out, checked again, still 3. Then I logged in with my admin account and when I went to the admin page, I did another select on groupid and it was BACK to 22!!!

Edit, I think the problem (or my oversight if you will) is the aspnet_* tables.

Progress!!

-- 398346A6-66B3-4A32-9255-76D1FE8E252F SlickVision

-- F90F7740-8105-4653-9ADE-26DBBBB56C0B Probation

-- 51C1CB88-8C52-41A9-8A6F-43F801A2445B Registered

update [aspnet_UsersInRoles]

set roleid = '51C1CB88-8C52-41A9-8A6F-43F801A2445B'

where userid = '398346A6-66B3-4A32-9255-76D1FE8E252F'

and roleid = 'F90F7740-8105-4653-9ADE-26DBBBB56C0B'

And now the role/groupid accurately reflects the value it should.

exhumed
  • exhumed
  • 54.4% (Neutral)
  • YAF Camper
11 years ago
Hi Zero2Cool,

I'm looking to do the same sort of thing as you.

Basically I want new registrations to be in a role like your probation one above, but outside of YAF in my asp.net c# site I would like to be able to move a user to a different role programattically based on various conditions via c# and sql stored procedures.

Did your method above work OK, and have you since found a better technique at all?

Thank you for your help

Zero2Cool
  • Zero2Cool
  • 100% (Exalted)
  • YAF Leader Topic Starter YAF Version: YAF 3.1.16
11 years ago
It's cut down on spam quite dramatically. So, I'd say it worked pretty well and in turn we get to learn something about the new registrants too.

New members are assigned the probation role which they can only post in one section.

I have a program that I threw together that checks every few minutes for members in that role AND has one or more posts. The ones it finds, it promotes them to the registered role and they can then start posting in all available sections.

squirrel
11 years ago
I am interested in this as a possible extension or plugin that could be added to the task scheduler of YAF or something along those lines --


If you can't find it using the forum search, try my signature link -- searches this site using Google: Google is my Friend