Please upgrade here. These earlier versions are no longer being updated and have security issues.

automatic assigning roles

This discussion is related to the Vanilla jsConnect addon.
jeroengjeroeng New
edited March 2012 in Vanilla 2.0 - 2.8

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

Tagged:
«1

Comments

  • Did you ever figure this out?

  • RippRipp New
    edited May 2012

    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?

    westhian
  • 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.

  • RippRipp New
    edited May 2012

    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.

  • jeroengjeroeng New
    edited August 2012

    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.

  • It's possible to do this in our 2.1 branch with a config setting, but not in 2.0.18.

    This was the reply I got.

  • @jeroeng said:
    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:

    $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!

    HalfCatUnderDogcassiofagundes
  • 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
            );
    
    HalfCat
  • Thank you for sharing @KezzB. This is amazing stuff.

  • KezzBKezzB New
    edited October 2012

    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!

Sign In or Register to comment.