Thanks a lot!
One sidenote: with this solution, you can not simply change the name of roles, can you? Since the roles are hardcoded, it will blow up if I change 'Moderator' to 'Supervisor' in the Vanilla admin. So be aware of that.
hi, is there a way to pass over the user roles assigned in wordpress over to vanilla? i created the same user roles in wordpress and vanilla. if a new user registers in wordpress and automatically gets a new user role, i want to sync them with vanilla. since the username and password is send over to vanilla it must be possible with the user role as well, or?
I am using jsconnect PHP in my website for SSO
Some users are administrators and some are moderators.
I tried passing
'roles' => "Member,Moderator"
But didn't get it working.
I tried searching but didn't find any documentation on this.
Please guide.
$Configuration['Garden']['Registration']['DefaultRoles'] = 'a:1:{i:0;s:1:"8";}';
a:1 indicates the array contains 1 role
In parentheses i is the role index (just increment for each role you add)
"8" is my role id for member.
e.g. 'a:2:{i:0;s:1:"8";i:1;s1:"9"}'
If you already have the account created but want to sync roles for every login.
In applications\dashboard\controllers\class.profilecontroller.php on around line 285 after the photo is set and before starting the session add or modify
@bubazineti said:
As an additional to Webkadabra's solution if you are sending in rolenames as opposed to roleids you could use this at the beginning of InsertForBasic
This handles initial synchronisation when an account is created.
$Configuration['Garden']['Registration']['DefaultRoles'] = 'a:1:{i:0;s:1:"8";}';
a:1 indicates the array contains 1 role
In parentheses i is the role index (just increment for each role you add)
"8" is my role id for member.
e.g. 'a:2:{i:0;s:1:"8";i:1;s1:"9"}'
If you already have the account created but want to sync roles for every login.
In applications\dashboard\controllers\class.profilecontroller.php on around line 285 after the photo is set and before starting the session add or modify
i tried to put the code where you said, but i didnt get it to work. i registered a new user within wordpress and gave him a new role. then i logged into wordpress with the new user account and went over to the forum to start the sync process. then i logged out again and logged in as admin to see if the roles were synchronized or not. unfortunately, they were not. it would be really good, if there was an easy tutorial how to set up new user roles and how this have to be done with wordpress and where exactly to place which code. i wasnt sure if i would also have to use the code by the thread owner. otherwise, i would just say, i need a developer to fix this ;-)
When your user is being synched / created are you sure it is the InsertForBasic method that is being used. If you look at the entry controller there are a few insert types. It could be that it's not taking the logic pathway you are expecting.
I'm not actually using wordpress. I am embedding the forum into a fairly complicated MVC php site (major headache) where I have a 'forum' controller that initially sends a GET request to vanilla.
I specify an authenticate URL in the plugin screen within vanilla. This is actually a method on my forum controller (within my application).
The success call backback likewise is a method on the controller which renders the view (embeds the forum).
Answers
Thanks a lot!
One sidenote: with this solution, you can not simply change the name of roles, can you? Since the roles are hardcoded, it will blow up if I change 'Moderator' to 'Supervisor' in the Vanilla admin. So be aware of that.
hi, is there a way to pass over the user roles assigned in wordpress over to vanilla? i created the same user roles in wordpress and vanilla. if a new user registers in wordpress and automatically gets a new user role, i want to sync them with vanilla. since the username and password is send over to vanilla it must be possible with the user role as well, or?
I am using jsconnect PHP in my website for SSO
Some users are administrators and some are moderators.
I tried passing
'roles' => "Member,Moderator"
But didn't get it working.
I tried searching but didn't find any documentation on this.
Please guide.
I can understand that this will work in branch 2.1 But how to make it work in other versions
Guys, I've been able to fix that thing for 2.0.18 Vanilla.
I'm not a Vanilla developer, so if someone can review my patc that'd be great:
notice how I'm saying 'sync', not 'synch'.
find
and in the beginning change this line:
to this:
find
and in the end of that method, before "$Sender->SetData('Verified', TRUE);" add:
Now, one thing here - you have to pass role IDs, not names (it's convenient for what I'm doing, hopefully it'll work for you too)
wow. if that is gonna working out, then you will be the king!
As an additional to Webkadabra's solution if you are sending in rolenames as opposed to roleids you could use this at the beginning of InsertForBasic
This handles initial synchronisation when an account is created.
$syncRoles = Gdn::Config('Garden.SSO.SyncRoles');
if($syncRoles && isset($FormPostValues['Roles'])) {
$Rolenames = array_map('trim', explode(',', $FormPostValues['Roles']));
$RoleIDs = $this->SQL
->Select('r.RoleID')
->From('Role r')
->WhereIn('r.Name', $Rolenames)
->Get()->ResultArray();
$RoleIDs = ConsolidateArrayValuesByKey($RoleIDs, 'RoleID');
}
else {
$RoleIDs = Gdn::Config('Garden.Registration.DefaultRoles');
}
You can define the defaultroles in config.php
$Configuration['Garden']['Registration']['DefaultRoles'] = 'a:1:{i:0;s:1:"8";}';
a:1 indicates the array contains 1 role
In parentheses i is the role index (just increment for each role you add)
"8" is my role id for member.
e.g. 'a:2:{i:0;s:1:"8";i:1;s1:"9"}'
If you already have the account created but want to sync roles for every login.
In applications\dashboard\controllers\class.profilecontroller.php on around line 285 after the photo is set and before starting the session add or modify
$UserModel->Save($Data, array('NoConfirmEmail' => TRUE, 'SaveRoles' => FALSE));
$UserModel->SaveRoles($UserID, $Data['Roles']);
if ($Attributes = $this->Form->GetFormValue('Attributes')) {
$UserModel->SaveAttribute($UserID, $Attributes);
}
I'm sure you could have it save the roles in the save call but as I had them as rolenames it was easier to do it this way
you can format above so it is more readable.
I can also suggest when posting code - mark it (select it and press the C on the buttonbar).
this will format it - so it is readable.
conversely you could try three tildes above and below your code.
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
i agree. the threat is also so long now that I would recommend writing a summary on how and where exactly to implement the code
great. but where do i have to place your code?
@netigate
applications/dashboard/models/class.usermodel.php
InsertForBasic function.
replace
with
In config.php add or modify your default roles
To sync roles at every login
In applications\dashboard\controllers\class.profilecontroller.php on line 285 just before the session is set
Cheers,
Buba
@bubazineti thanks for this.
i tried to put the code where you said, but i didnt get it to work. i registered a new user within wordpress and gave him a new role. then i logged into wordpress with the new user account and went over to the forum to start the sync process. then i logged out again and logged in as admin to see if the roles were synchronized or not. unfortunately, they were not. it would be really good, if there was an easy tutorial how to set up new user roles and how this have to be done with wordpress and where exactly to place which code. i wasnt sure if i would also have to use the code by the thread owner. otherwise, i would just say, i need a developer to fix this ;-)
@netigate
When your user is being synched / created are you sure it is the InsertForBasic method that is being used. If you look at the entry controller there are a few insert types. It could be that it's not taking the logic pathway you are expecting.
I'm not actually using wordpress. I am embedding the forum into a fairly complicated MVC php site (major headache) where I have a 'forum' controller that initially sends a GET request to vanilla.
I specify an authenticate URL in the plugin screen within vanilla. This is actually a method on my forum controller (within my application).
The success call backback likewise is a method on the controller which renders the view (embeds the forum).
Cheers,
Bub