Hi!
Is it possible when using jsconnect and php to assign users to a certain role? In the example the name, email etc. is passed. But there is no documentation about what else could be passed.
Thanks,
Jeroen
KezzB
newb
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!
KezzB
newb
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
);
Answers
Did you ever figure this out?
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •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.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •Unfortunately I didn't figure it out. But I will look at your ideas!
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •I can set up a github repository, perhaps we can figure it out between the two of us.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •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.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •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..?
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •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?
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •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.- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •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.)
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •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.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •Can we send a mail or something like that to the author? It seems that he is not looking in this forums.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •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.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •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.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •@Ripp @jeroeng Did one of you guys figure this out? I am also interested in this.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •This was the reply I got.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •Nice, thanks for the reply. Now we just need to figure out how to set those config settings.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •Thank you for sharing @KezzB. This is amazing stuff.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •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!
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •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.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •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?
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •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.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •I can understand that this will work in branch 2.1 But how to make it work in other versions
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •