Skip to content

Commit f8c1876

Browse files
authored
Merge pull request #1098 from CakeDC/issue/1096-bug-in-social-behavior-cake4
#1096: fixed `findExistingForSocialLogin` finder
2 parents a4b213c + 7c27286 commit f8c1876

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/Model/Behavior/SocialBehavior.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Cake\Core\Configure;
1717
use Cake\Datasource\EntityInterface;
1818
use Cake\Event\EventDispatcherTrait;
19+
use Cake\ORM\Query;
1920
use Cake\Utility\Hash;
2021
use CakeDC\Users\Exception\AccountNotActiveException;
2122
use CakeDC\Users\Exception\MissingEmailException;
@@ -138,7 +139,6 @@ protected function _createSocialUser($data, $options = [])
138139
$useEmail = $options['use_email'] ?? null;
139140
$validateEmail = $options['validate_email'] ?? null;
140141
$tokenExpiration = $options['token_expiration'] ?? null;
141-
$existingUser = null;
142142
$email = $data['email'] ?? null;
143143
if ($useEmail && empty($email)) {
144144
throw new MissingEmailException(__d('cake_d_c/users', 'Email not present'));
@@ -276,8 +276,15 @@ public function generateUniqueUsername($username)
276276
* @param array $options Find options with email key.
277277
* @return \Cake\ORM\Query
278278
*/
279-
public function findExistingForSocialLogin(\Cake\ORM\Query $query, array $options)
279+
public function findExistingForSocialLogin(Query $query, array $options)
280280
{
281+
if (!array_key_exists('email', $options)) {
282+
throw new MissingEmailException(__d('cake_d_c/users', 'Missing `email` option in options array'));
283+
}
284+
if (!$options['email']) {
285+
return $query->where('1 != 1');
286+
}
287+
281288
return $query->where([
282289
$this->_table->aliasField('email') => $options['email'],
283290
]);

0 commit comments

Comments
 (0)