Social Network Connect Events

The following is the list of the social network connection events and where they happen:

On Controllers

How to Work With Social Network Connect Events

This event when triggered will contain a Da\User\Model\User model instance and also a Da\User\Model\SocialNetworkAccount instance. For example:

<?php 
// events.php file

use Da\User\Controller\RegistrationController;
use Da\User\Controller\SecurityController;
use Da\User\Event\SocialNetworkConnectEvent;
use Da\User\Event\SocialNetworkAuthEvent;
use yii\base\Event;

// on RegistrationController

Event::on(
    RegistrationController::class, 
    SocialNetworkConnectEvent::EVENT_BEFORE_CONNECT, 
    function (SocialNetworkConnectEvent $event) {

        $user = $event->getUser(); // $token is a Da\User\Model\User instance
        $account = $event->getAccount(); // $account is a Da\User\Model\SocialNetworkAccount

        // ... your logic here
    });

// on SecurityController

Event::on(
    SecurityController::class, 
    SocialNetworkAuthEvent::EVENT_BEFORE_AUTHENTICATE, 
    function (SocialNetworkAuthEvent $event) {

        $client = $event->getClient();
        $account = $event->getAccount(); // $account is a Da\User\Model\SocialNetworkAccount

        // ... your logic here
    });

© 2amigos 2013-2019