WIP
This commit is contained in:
@@ -4,8 +4,8 @@ namespace App\Security;
|
||||
|
||||
use App\BusProNet\ApiClient;
|
||||
use App\BusProNet\ApiClientException;
|
||||
use App\BusProNet\Model\ErrorResponse;
|
||||
use App\BusProNet\Model\Profile;
|
||||
use App\BusProNet\Model\CrmAttributesResponse;
|
||||
use App\BusProNet\Model\ProfileResponse;
|
||||
use App\Entity\User;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
@@ -53,7 +53,7 @@ class BpnAuthenticator extends AbstractLoginFormAuthenticator implements Authent
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($response instanceof ErrorResponse) {
|
||||
if (false === $response instanceof ProfileResponse) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ class BpnAuthenticator extends AbstractLoginFormAuthenticator implements Authent
|
||||
return new RedirectResponse($url);
|
||||
}
|
||||
|
||||
private function getOrCreateLocalUser(Profile $profile, string $email, string $password): User
|
||||
private function getOrCreateLocalUser(ProfileResponse $profile, string $email, string $password): ?User
|
||||
{
|
||||
$repository = $this->entityManager->getRepository(User::class);
|
||||
|
||||
@@ -95,20 +95,25 @@ class BpnAuthenticator extends AbstractLoginFormAuthenticator implements Authent
|
||||
}
|
||||
|
||||
try {
|
||||
$response = $this->apiClient->getCrmSelection($email, $password);
|
||||
/** @var CrmAttributesResponse $crmAttributes */
|
||||
$crmAttributes = $this->apiClient->getCrmAttributes($email, $password);
|
||||
} catch (ApiClientException $e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$user = new User();
|
||||
$user
|
||||
->setBusProAddressId($profile->getAddressId())
|
||||
->setBusProPersonId($profile->getPersonId())
|
||||
->setRole('ROLE_FOO')
|
||||
->setEmail($profile->getCommunication()->getEmail())
|
||||
->setFirstName($profile->getFirstName())
|
||||
->setLastName($profile->getName())
|
||||
;
|
||||
|
||||
if ($crmAttributes->isTeamer()) {
|
||||
$user->setRole('ROLE_TEAMER');
|
||||
}
|
||||
|
||||
$this->entityManager->persist($user);
|
||||
$this->entityManager->flush();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user