Skip to content

Commit

Permalink
Allow profiles table's foreign key field to be configurable.
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed May 14, 2016
1 parent bc007f6 commit 8cdfc51
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,17 @@ required authentication handler. You would have something like this in your
$this->loadComponent('Auth', [
'authenticate' => [
'Form',
'ADmad/HybridAuth.HybridAuth'
'ADmad/HybridAuth.HybridAuth' => [
// All keys shown below are defaults
'fields' => [
'provider' => 'provider',
'openid_identifier' => 'openid_identifier',
'email' => 'email'
],
'profileModel' => 'ADmad/HybridAuth.SocialProfiles',
'profileModelFkField' => 'user_id',
'hauth_return_to' => null
]
]
]);
```
Expand Down
3 changes: 2 additions & 1 deletion src/Auth/HybridAuthAuthenticate.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public function __construct(ComponentRegistry $registry, $config)
'email' => 'email'
],
'profileModel' => 'ADmad/HybridAuth.SocialProfiles',
'profileModelFkField' => 'user_id',
'hauth_return_to' => null
]);

Expand Down Expand Up @@ -285,7 +286,7 @@ protected function _getUser($adapter)
$user = $event->result;
}

$profile->user_id = $user->id;
$profile->{$config['profileModelFkField']} = $user->{$UsersTable->primaryKey()};
$profile = TableRegistry::get($config['profileModel'])->save($profile);
if (!$profile) {
throw new \RuntimeException('Unable to save social profile.');
Expand Down

0 comments on commit 8cdfc51

Please sign in to comment.