Skip to content

Commit

Permalink
Merge pull request #1098 from CakeDC/issue/1096-bug-in-social-behavio…
Browse files Browse the repository at this point in the history
…r-cake4

#1096: fixed `findExistingForSocialLogin` finder
  • Loading branch information
steinkel authored Sep 5, 2024
2 parents a4b213c + 7c27286 commit f8c1876
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 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\ORM\Query;
use Cake\Utility\Hash;
use CakeDC\Users\Exception\AccountNotActiveException;
use CakeDC\Users\Exception\MissingEmailException;
Expand Down Expand Up @@ -138,7 +139,6 @@ protected function _createSocialUser($data, $options = [])
$useEmail = $options['use_email'] ?? null;
$validateEmail = $options['validate_email'] ?? null;
$tokenExpiration = $options['token_expiration'] ?? null;
$existingUser = null;
$email = $data['email'] ?? null;
if ($useEmail && empty($email)) {
throw new MissingEmailException(__d('cake_d_c/users', 'Email not present'));
Expand Down Expand Up @@ -276,8 +276,15 @@ public function generateUniqueUsername($username)
* @param array $options Find options with email key.
* @return \Cake\ORM\Query
*/
public function findExistingForSocialLogin(\Cake\ORM\Query $query, array $options)
public function findExistingForSocialLogin(Query $query, array $options)
{
if (!array_key_exists('email', $options)) {
throw new MissingEmailException(__d('cake_d_c/users', 'Missing `email` option in options array'));
}
if (!$options['email']) {
return $query->where('1 != 1');
}

return $query->where([
$this->_table->aliasField('email') => $options['email'],
]);
Expand Down

0 comments on commit f8c1876

Please sign in to comment.