feat: set preferred role on login via get parameter
This commit is contained in:
@@ -63,8 +63,9 @@ class BpnAuthenticator extends AbstractLoginFormAuthenticator implements Authent
|
||||
return null;
|
||||
}
|
||||
|
||||
// Finale checks and local user loading/creation
|
||||
$user = $this->getOrCreateLocalUser($response, $email, $password);
|
||||
// Final checks and local user loading/creation
|
||||
$preferredRole = $request->request->get('_role');
|
||||
$user = $this->getOrCreateLocalUser($response, $email, $password, $preferredRole);
|
||||
|
||||
if (null === $user) {
|
||||
return null;
|
||||
@@ -98,8 +99,12 @@ class BpnAuthenticator extends AbstractLoginFormAuthenticator implements Authent
|
||||
return new RedirectResponse($url);
|
||||
}
|
||||
|
||||
private function getOrCreateLocalUser(ProfileResponse $profileResponse, string $email, string $password): ?User
|
||||
{
|
||||
private function getOrCreateLocalUser(
|
||||
ProfileResponse $profileResponse,
|
||||
string $email,
|
||||
string $password,
|
||||
?string $preferredRole
|
||||
): ?User {
|
||||
// Fetch CRM attributes, early return in case of an API error
|
||||
try {
|
||||
/** @var CrmAttributesResponse $crmAttributes */
|
||||
@@ -111,7 +116,7 @@ class BpnAuthenticator extends AbstractLoginFormAuthenticator implements Authent
|
||||
// Collect user's roles from CRM attributes
|
||||
$roles = $this
|
||||
->userDataHandler
|
||||
->collectRoles($crmAttributes)
|
||||
->collectRoles($crmAttributes, $preferredRole)
|
||||
;
|
||||
|
||||
// User is expected to have at least one role
|
||||
|
||||
Reference in New Issue
Block a user