Skip to content

Commit

Permalink
#1096: fixed findExistingForSocialLogin finder
Browse files Browse the repository at this point in the history
  • Loading branch information
arusinowski committed Sep 4, 2024
1 parent f538426 commit fb20239
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/Model/Behavior/SocialBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
namespace CakeDC\Users\Model\Behavior;

use Cake\Core\Configure;
use Cake\Database\Expression\QueryExpression;
use Cake\Datasource\EntityInterface;
use Cake\Event\EventDispatcherTrait;
use Cake\ORM\Query\SelectQuery;
use Cake\Utility\Hash;
use CakeDC\Users\Exception\AccountNotActiveException;
use CakeDC\Users\Exception\MissingEmailException;
Expand Down Expand Up @@ -138,7 +140,6 @@ protected function _createSocialUser($data, $options = [])
$useEmail = $options['use_email'] ?? null;
$validateEmail = (bool)($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,19 +277,17 @@ public function generateUniqueUsername($username)
* Prepare a query to retrieve existing entity for social login
*
* @param \Cake\ORM\Query\SelectQuery $query The base query.
* @param array $options Find options with email key.
* @param mixed $email Find options with email key.
* @return \Cake\ORM\Query\SelectQuery
*/
public function findExistingForSocialLogin(\Cake\ORM\Query\SelectQuery $query, array $options)
public function findExistingForSocialLogin(SelectQuery $query, mixed $email): SelectQuery
{
$email = $options['email'] ?? null;
if (!$email) {
return $query->where('1 != 1');
}

return $query->where([
$this->_table->aliasField('email') => $email,
]);
return $query->where(
fn(QueryExpression $expression) => $expression->eq(
$this->_table->aliasField('email'),
$email
)
);
}

/**
Expand Down

0 comments on commit fb20239

Please sign in to comment.