Skip to content

Commit 46eebb2

Browse files
committed
Merge branch 'release/1.1.3'
2 parents f100f12 + 9604c6c commit 46eebb2

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).
66

77

8+
## 1.1.3 - 2020-06-22
9+
### Added
10+
- Added the option to check for existing users by setting a custom field and Auth0 metadata key in the config file. Set `uniqueUserFieldHandle` to the field handle and `uniqueUserFieldMetaKey` to the metadata key that will be used to validate the check. This check runs before the email one and will only run if those two values are set in the config file.
11+
12+
813
## 1.1.2 - 2020-06-05
914
### Added
1015
- Added a second parmater to the silen login to allow for query params to act as a fallback if the referrer is not present. Use like so: `{% do craft.auth0.silentLogin(['someapp.com','api-someapp.com'], {'ref':'someapp','n':'123'}) %}` or `{% do craft.auth0.silentLogin(['someapp.com','api-someapp.com'], [{'ref':'someapp1','n':'123'},{'ref':'someapp2','n':'456'}]) %}`

src/config.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,7 @@
2828
'clientSecret' => null,
2929
'callbackUrl' => null,
3030
'userGroupHandle' => null,
31-
'logoutReturnUrl' => null
31+
'logoutReturnUrl' => null,
32+
'uniqueUserFieldHandle' => null,
33+
'uniqueUserFieldMetaKey' => null
3234
];

src/models/Settings.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,14 @@ class Settings extends Model
5454
* @var string|null
5555
*/
5656
public $logoutReturnUrl;
57+
58+
/**
59+
* @var string|null
60+
*/
61+
public $uniqueUserFieldHandle;
62+
63+
/**
64+
* @var string|null
65+
*/
66+
public $uniqueUserFieldMetaKey;
5767
}

src/services/Auth.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ public function logout()
126126
*/
127127
public function handleCallback()
128128
{
129+
$user = null;
129130
$auth0UserInfo = $this->getUser();
130131

131132
$users = Craft::$app->getUsers();
@@ -137,10 +138,19 @@ public function handleCallback()
137138
return null;
138139
}
139140

141+
// First try and get Craft user by custom field
142+
if ($this->_settings->uniqueUserFieldHandle && $this->_settings->uniqueUserFieldMetaKey && isset($auth0UserInfo[$this->_settings->uniqueUserFieldMetaKey]) && !empty($auth0UserInfo[$this->_settings->uniqueUserFieldMetaKey])) {
143+
$user = User::findOne([
144+
$this->_settings->uniqueUserFieldHandle => $auth0UserInfo[$this->_settings->uniqueUserFieldMetaKey]
145+
]);
146+
}
147+
140148
// Get the Craft user if we can
141-
$user = $users->getUserByUsernameOrEmail($auth0UserInfo['email']);
149+
if (!$user) {
150+
$user = $users->getUserByUsernameOrEmail($auth0UserInfo['email']);
151+
}
142152

143-
// There isn’t one, so create it first
153+
// There still isn’t one, so create it
144154
if (!$user) {
145155

146156
$user = new User();
@@ -289,6 +299,7 @@ public function silentLogin($referrerWhitelist = null, $queryParamWhitelist = nu
289299
}
290300
if ($passedParams === count($queryParamSet)) {
291301
$this->_auth0->login();
302+
break;
292303
}
293304
}
294305
}

0 commit comments

Comments
 (0)