Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
dmeroff committed Mar 27, 2016
1 parent 3115734 commit bcc68fb
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions docs/social-auth.md
Expand Up @@ -140,4 +140,36 @@ The following config allows to log in using 3 networks (Twitter, Facebook and Go
],
],
],
```

## How to access social network attributes

You can fill user's profile with data provided by social network, here is quick example of how to fill profile name
with the name provided via facebook:

```php
// plase this code somewhere in your config files (bootstrap.php in case of using advanced app template, web.php in case
// of using basic app template

use dektrium\user\controllers\SecurityController;

Event::on(SecurityController::class, SecurityController::EVENT_AFTER_AUTHENTICATE, function (AuthEvent $e) {
// if user account was not created we should not continue
if ($e->account->user === null) {
return;
}

// we are using switch here, because all networks provide different sets of data
switch ($e->client->getName()) {
case 'facebook':
$e->account->user->profile->updateAttributes([
'name' => $e->client->getUserAttributes()['name'],
]);
case 'vkontakte':
// some different logic
}

// after saving all user attributes will be stored under account model
// Yii::$app->identity->user->accounts['facebook']->decodedData
});
```

0 comments on commit bcc68fb

Please sign in to comment.