diff --git a/src/Model/Behavior/SocialBehavior.php b/src/Model/Behavior/SocialBehavior.php index 763be8c9..097955fa 100644 --- a/src/Model/Behavior/SocialBehavior.php +++ b/src/Model/Behavior/SocialBehavior.php @@ -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; @@ -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')); @@ -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'], ]);