Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/Model/Behavior/SocialBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Cake\Core\Configure;
use Cake\Datasource\EntityInterface;
use Cake\Event\EventDispatcherTrait;
use Cake\Log\Log;
use Cake\ORM\Query;
use Cake\Utility\Hash;
use CakeDC\Users\Exception\AccountNotActiveException;
Expand Down Expand Up @@ -77,13 +78,17 @@ public function initialize(array $config): void
public function socialLogin(array $data, array $options)
{
$reference = $data['id'] ?? null;
$existingAccount = $this->_table->SocialAccounts->find()
$existingAccount = null;

if ($reference) {
$existingAccount = $this->_table->SocialAccounts->find()
->where([
'SocialAccounts.reference' => $reference,
'SocialAccounts.provider' => $data['provider'] ?? null,
])
->contain(['Users'])
->first();
}
if (empty($existingAccount->user)) {
$user = $this->_createSocialUser($data, $options);
if (!empty($user->social_accounts[0])) {
Expand Down Expand Up @@ -159,7 +164,12 @@ protected function _createSocialUser($data, $options = [])

$this->_table->isValidateEmail = $validateEmail;

return $this->_table->save($user);
$savedUser = $this->_table->save($user);
if (!$savedUser) {
Log::debug('Unable save user. Errors: ' . json_encode($user->getErrors()));
}

return $savedUser;
}

/**
Expand Down
Loading