automatic assigning roles
Best Answers
-
KezzB New
I just spent the whole day trying to figure this out and finally got it going.
As mentioned above, you need 2.1 branch.
After that it's actually super easy once you find it.
You just add to your config.php this setting:
$Configuration['Garden']['SSO']['SynchRoles'] = TRUE;
Then your array of roles will carry through perfectly.
I'm using WP Vanilla Connect plugin on WordPress, so I just changed it from this:
$user = array( 'uniqueid' => $current_user->ID, 'name' => $current_user->display_name, 'email' => $current_user->user_email );
To this:
$user = array( 'uniqueid' => $current_user->ID, 'name' => $current_user->display_name, 'email' => $current_user->user_email, 'roles' => "Member,Moderator" );
Now it's working great.
I'm also going to have it check on my user's levels on WP first, as I'm using the s2Member plugin, so then I can create a tiered access system in the forum.
Perfect!
3 -
KezzB New
Thought I'd also share the code I used to synch my WP s2Member roles with my forum in case anyone else finds it useful:
//get current user role if(current_user_can("access_s2member_level4")){ $thisrole = "Level 4"; } else if(current_user_can("access_s2member_level3")){ $thisrole = "Level 3"; } else if(current_user_can("access_s2member_level2")){ $thisrole = "Level 2"; } else if(current_user_can("access_s2member_level1")){ $thisrole = "Level 1"; } else if($current_user->role=="subscriber"){ $thisrole = "Free Member"; } else { $thisrole = ""; } // Map the current user values for jsConnect $user = array( 'uniqueid' => $current_user->ID, 'name' => $current_user->display_name, 'email' => $current_user->user_email, 'roles' => $thisrole );
1 -
Webkadabra New
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:- Put this in your config:
$Configuration['Garden']['SSO']['SyncRoles'] = TRUE;
notice how I'm saying 'sync', not 'synch'.
- Open file applications/dashboard/models/class.usermodel.php
find
public function InsertForBasic($FormPostValues, $CheckCaptcha = TRUE, $Options = array()) {
and in the beginning change this line:
$RoleIDs = Gdn::Config('Garden.Registration.DefaultRoles');
to this:
$syncRoles = Gdn::Config('Garden.SSO.SyncRoles');
if($syncRoles ) {
$RoleIDs = (isset($FormPostValues['Roles']) ? $FormPostValues['Roles'] : Gdn::Config('Garden.Registration.DefaultRoles'));
} else {
$RoleIDs = Gdn::Config('Garden.Registration.DefaultRoles');
}- in plugins\jsconnect\class.jsconnect.plugin.php
find
public function Base_ConnectData_Handler($Sender, $Args)
and in the end of that method, before "$Sender->SetData('Verified', TRUE);" add:
$Form->SetFormValue('Roles', GetValue('roles', $JsData, ''));
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)
5
Answers
Did you ever figure this out?
So I played around with this a bit, adding:
$Form->SetFormValue('Roles', GetValue('roles', $JsData, ''));
line to class.jsconnect.plugin.php, and also making some other changes (including of course, specifying the roles string in my application.)
However, it seems that jsConnect completely ignores this.
Where is documentation for exactly how the class Gdn_Form works, and this function SetFormValue?
What conceptually is it doing? Are we creating a temporary form?
Does JsConnect initialize this "Roles" entry to "Member", and then use this temporary form to write the User model to the database?
I kind of suspect that it ignores the Roles field of this Form which I am setting. If so, where exactly is Roles being set?
Any insight would be greatly appreciated.
Unfortunately I didn't figure it out. But I will look at your ideas!
I can set up a github repository, perhaps we can figure it out between the two of us.
Github repo here: http://bit.ly/JaYmU3
The readme file also contains a diff between my version of "class.jsconnect.plugin.php" and the default one.
Actually it looks like their repository on Github made the same change...
https://github.com/vanillaforums/Addons/blob/master/plugins/jsconnect/class.jsconnect.plugin.php
I tried their version and it doesn't work for me either. The user I add is always only just a Member, right than Member and Moderator like I intended.
So now I'm wondering if I'm generating the string incorrectly..?
Here is the JSON string I'm generating, anonymity a bit:
{"uniqueid":"xxx","name":"xxx","email":"xxx","photourl":"","roles":"Member,Moderator","clientid":"xxx","signature":"xxx"}
This is the right way to set "roles", right? Comma separated string, no spaces?
The Gdn_Form class : http://lincolnwebs.com/vanilla2doc/class_gdn___form.html
I'll watch your repo. Maybe it's better if you commit the Vanilla file and then commit your adjustments. Then it is possible to use the Git Diff tool. That is better to read and understand
Since the roles in JSON is an array (or isn't it?), maybe it should look like
"roles":{"Member","Moderator"}, "clientid" etc.
Yeah I can go back and do that, but a bit lazy
From my email conversation with the author of the module, it seems the development branch version works. I'll try it out when I get home (as well as your suggestion about roles.)
I didn't have any success with their development branch, nor with your suggestion for the stable branch. Constantly logs me out of the dashboard for development branch; stable branch your suggestion didn't make a difference.
Let me know if you have better luck.
Can we send a mail or something like that to the author? It seems that he is not looking in this forums.
I send an email to him before, didn't seem like he was too interested. Perhaps we'll have better luck if you shoot him an email.
After some time, I didn't get a response, sadly.
EDIT: maybe I did something wrong (I couldn't find the message) so I've send another one.
@Ripp @jeroeng
Did one of you guys figure this out? I am also interested in this.
This was the reply I got.
Nice, thanks for the reply. Now we just need to figure out how to set those config settings.
I just spent the whole day trying to figure this out and finally got it going.
As mentioned above, you need 2.1 branch.
After that it's actually super easy once you find it.
You just add to your config.php this setting:
Then your array of roles will carry through perfectly.
I'm using WP Vanilla Connect plugin on WordPress, so I just changed it from this:
To this:
Now it's working great.
I'm also going to have it check on my user's levels on WP first, as I'm using the s2Member plugin, so then I can create a tiered access system in the forum.
Perfect!
Thought I'd also share the code I used to synch my WP s2Member roles with my forum in case anyone else finds it useful:
Thank you for sharing @KezzB. This is amazing stuff.
You're welcome!
Thanks also to you guys above, @HalfCat @Ripp @jeroeng , for figuring out the first part so I could get the whole thing going.
I tested everything out last night btw and it works great, so my whole s2Member user base is all set to easily sign into the forum now and instantly get access to exclusive sections depending on their level. Stoked!