feat: extended oauth2 user info and refactored authenticator
This commit is contained in:
@@ -4,7 +4,6 @@ namespace App\Security;
|
||||
|
||||
use App\BusProNet\ApiClient;
|
||||
use App\BusProNet\Exception\ApiClientException;
|
||||
use App\BusProNet\Model\CrmAttributes;
|
||||
use App\BusProNet\Model\PersonalData;
|
||||
use App\Entity\User;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
@@ -79,7 +78,9 @@ class BpnAuthenticator extends AbstractLoginFormAuthenticator implements Authent
|
||||
throw new CustomUserMessageAuthenticationException($e->getMessage());
|
||||
}
|
||||
|
||||
$roles = $this->collectRoles($crmAttributes);
|
||||
$roles = $crmAttributes->roles;
|
||||
$hotelCodes = $crmAttributes->hotelCodes;
|
||||
|
||||
$encryptedPassword = $this->crypt->encrypt($password);
|
||||
|
||||
$userRepository = $this->entityManager->getRepository(User::class);
|
||||
@@ -94,6 +95,7 @@ class BpnAuthenticator extends AbstractLoginFormAuthenticator implements Authent
|
||||
->setPersonId($personId)
|
||||
->setAddressId($addressId)
|
||||
->setRoles($roles)
|
||||
->setHotelCodes($hotelCodes)
|
||||
->setLastLoginAt(new \DateTimeImmutable())
|
||||
;
|
||||
|
||||
@@ -114,28 +116,4 @@ class BpnAuthenticator extends AbstractLoginFormAuthenticator implements Authent
|
||||
|
||||
return new RedirectResponse($this->urlGenerator->generate('app_account'));
|
||||
}
|
||||
|
||||
private function collectRoles(CrmAttributes $crmAttributes): array
|
||||
{
|
||||
// All users inherit the default role 'customer'
|
||||
$roles = [
|
||||
'ROLE_CUSTOMER',
|
||||
];
|
||||
|
||||
// Get user's base role from CRM attributes
|
||||
if ($crmAttributes->admin) {
|
||||
$roles[] = 'ROLE_ADMIN';
|
||||
} elseif ($crmAttributes->manager) {
|
||||
$roles[] = 'ROLE_MANAGER';
|
||||
} elseif ($crmAttributes->houseManager) {
|
||||
$roles[] = 'ROLE_HOUSE_MANAGER';
|
||||
}
|
||||
|
||||
// All users can have role 'teamer' additionally
|
||||
if ($crmAttributes->teamer) {
|
||||
$roles[] = 'ROLE_TEAMER';
|
||||
}
|
||||
|
||||
return $roles;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user