Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
1.3k views
in Plugins by

I would like to update the user status when he signed up with facebook or twitter using the open-login-plugin. Reading the documentation of the Library that the plugin uses ( Hybridauth) i found a methode called : setUserStatus and didn't know how to use it, any help please ?

Q2A version: latest

2 Answers

0 votes
by

Hello,

I never looked into the Hybridauth more than to be able to use it as an single-sign-on utility, so the code below is extracted from open-login plugin (see qa-open-login.php).

I haven't tested it but theoretically it should work, with minor code adjustments.

 

require_once 'Hybrid/Auth.php';

$provider = 'Facebook';
$loginCallback = qa_path('', array(), qa_opt('site_url'));

// prepare the configuration of HybridAuth
$config = getConfig($provider, $loginCallback);

try {
    // try to login
    $hybridauth = new Hybrid_Auth( $config );
    $adapter = $hybridauth->authenticate( $provider );
    
    // if ok, update the user status
    $adapter->setUserStatus( ... );
    
} catch(Exception $e) {
    // handle this
}


function getConfig($provider, $url) {
    $key = strtolower($provider);
    return array(
        'base_url' => $url,
            'providers' => array (
                $provider => array (
                    'enabled' => true,
                    'keys' => array(
                        'id' => qa_opt("{$key}_app_id"),
                        'key' => qa_opt("{$key}_app_id"),
                        'secret' => qa_opt("{$key}_app_secret")
                    ),
                    'scope' => $provider == 'Facebook' ? 'email,user_about_me,user_location,user_website' : null, // might need to add more scopes here
                )
            ),
        'debug_mode' => false,
        'debug_file' => ''
    );
}

 

This piece of code should be put in a separate page. I hope this helps.

Alex

0 votes
by
This is also posible with the open-login plugin . What you have to do is , just create another plugin that handles the q_post and a_post , c_post events .

And update the same to social media websites when the event occurs . But for this you need some aditional settings to be done from the Facebook API panel . Read the HybridAuth Documentation for more information .

Some times you will also need to handle users those have previously loggin using Fb or Twitter , But currently they are doing activity with the Normal password login . For this you might do some tweaks in the openlogin plugin as well .

 

Hope this helps .
...