WIP
This commit is contained in:
@@ -17,6 +17,9 @@ security:
|
||||
provider: bpn_user_provider
|
||||
custom_authenticators:
|
||||
- App\Security\BpnAuthenticator
|
||||
logout:
|
||||
path: app_security_logout
|
||||
target: app_security_login
|
||||
access_control:
|
||||
- { path: ^/profile, roles: ROLE_USER }
|
||||
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20230902154310 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE user ADD roles LONGTEXT NOT NULL COMMENT \'(DC2Type:json)\', DROP role');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE user ADD role VARCHAR(255) NOT NULL, DROP roles');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20230902155910 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE user ADD address_street VARCHAR(255) DEFAULT NULL, ADD address_post_code VARCHAR(255) DEFAULT NULL, ADD address_city VARCHAR(255) DEFAULT NULL, ADD address_country VARCHAR(255) DEFAULT NULL');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE user DROP address_street, DROP address_post_code, DROP address_city, DROP address_country');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20230902163321 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE user ADD profile_bus_pro_address_id INT NOT NULL, ADD profile_bus_pro_person_id INT NOT NULL, ADD profile_title VARCHAR(255) NOT NULL, ADD profile_salutation VARCHAR(255) NOT NULL, ADD profile_first_name VARCHAR(255) NOT NULL, ADD profile_last_name VARCHAR(255) NOT NULL, ADD profile_gender VARCHAR(1) DEFAULT NULL, ADD profile_date_of_birth DATE DEFAULT NULL COMMENT \'(DC2Type:date_immutable)\', ADD profile_street VARCHAR(255) DEFAULT NULL, ADD profile_post_code VARCHAR(255) DEFAULT NULL, ADD profile_city VARCHAR(255) DEFAULT NULL, ADD profile_country VARCHAR(255) DEFAULT NULL, ADD profile_phone VARCHAR(255) DEFAULT NULL, ADD profile_mobile VARCHAR(255) DEFAULT NULL, DROP bus_pro_address_id, DROP first_name, DROP last_name, DROP bus_pro_person_id, DROP address_street, DROP address_post_code, DROP address_city, DROP address_country');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE user ADD bus_pro_address_id INT NOT NULL, ADD first_name VARCHAR(255) NOT NULL, ADD last_name VARCHAR(255) NOT NULL, ADD bus_pro_person_id INT NOT NULL, ADD address_street VARCHAR(255) DEFAULT NULL, ADD address_post_code VARCHAR(255) DEFAULT NULL, ADD address_city VARCHAR(255) DEFAULT NULL, ADD address_country VARCHAR(255) DEFAULT NULL, DROP profile_bus_pro_address_id, DROP profile_bus_pro_person_id, DROP profile_title, DROP profile_salutation, DROP profile_first_name, DROP profile_last_name, DROP profile_gender, DROP profile_date_of_birth, DROP profile_street, DROP profile_post_code, DROP profile_city, DROP profile_country, DROP profile_phone, DROP profile_mobile');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20230902164055 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE user ADD address_street VARCHAR(255) DEFAULT NULL, ADD address_post_code VARCHAR(255) DEFAULT NULL, ADD address_city VARCHAR(255) DEFAULT NULL, ADD address_country VARCHAR(255) DEFAULT NULL, ADD communication_phone VARCHAR(255) DEFAULT NULL, ADD communication_mobile VARCHAR(255) DEFAULT NULL, ADD communication_email VARCHAR(255) DEFAULT NULL, DROP profile_phone, DROP profile_mobile');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE user ADD profile_phone VARCHAR(255) DEFAULT NULL, ADD profile_mobile VARCHAR(255) DEFAULT NULL, DROP address_street, DROP address_post_code, DROP address_city, DROP address_country, DROP communication_phone, DROP communication_mobile, DROP communication_email');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20230902164150 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE user DROP profile_street, DROP profile_post_code, DROP profile_city, DROP profile_country');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE user ADD profile_street VARCHAR(255) DEFAULT NULL, ADD profile_post_code VARCHAR(255) DEFAULT NULL, ADD profile_city VARCHAR(255) DEFAULT NULL, ADD profile_country VARCHAR(255) DEFAULT NULL');
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,10 @@ namespace App\BusProNet\Model;
|
||||
|
||||
class CrmAttribute
|
||||
{
|
||||
public const ATTR_ID_ADMIN = 1071;
|
||||
public const ATTR_ID_MANAGER = 1072;
|
||||
public const ATTR_ID_TEAMER = 1070;
|
||||
|
||||
private ?int $id = null;
|
||||
private ?string $label = null;
|
||||
private bool $selected = false;
|
||||
|
||||
@@ -5,6 +5,8 @@ namespace App\BusProNet\Model;
|
||||
class CrmAttributesResponse extends BaseResponse
|
||||
{
|
||||
private ?array $attributeGroups = null;
|
||||
private bool $admin = false;
|
||||
private bool $manager = false;
|
||||
private bool $teamer = false;
|
||||
|
||||
public function getAttributeGroups(): ?array
|
||||
@@ -29,4 +31,28 @@ class CrmAttributesResponse extends BaseResponse
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isAdmin(): bool
|
||||
{
|
||||
return $this->admin;
|
||||
}
|
||||
|
||||
public function setAdmin(bool $admin): static
|
||||
{
|
||||
$this->admin = $admin;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isManager(): bool
|
||||
{
|
||||
return $this->manager;
|
||||
}
|
||||
|
||||
public function setManager(bool $manager): static
|
||||
{
|
||||
$this->manager = $manager;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -12,8 +12,6 @@ use App\BusProNet\Model\BaseResponse;
|
||||
|
||||
class ResponseParser
|
||||
{
|
||||
public const ATTR_ID_TEAMER = 1070;
|
||||
|
||||
/**
|
||||
* @throws ResponseParserException
|
||||
*/
|
||||
@@ -108,7 +106,7 @@ class ResponseParser
|
||||
public function createCrmAttributesResponse(\SimpleXMLElement $xml): CrmAttributesResponse
|
||||
{
|
||||
$groups = [];
|
||||
$isTeam = false;
|
||||
$isAdmin = $isManager = $isTeamer = false;
|
||||
|
||||
foreach ($xml->xpath('selektionsmerkmale/selektionsgruppe') as $item) {
|
||||
$group = new CrmAttributeGroup();
|
||||
@@ -124,8 +122,14 @@ class ResponseParser
|
||||
;
|
||||
$attributes[] = $attribute;
|
||||
|
||||
if (static::ATTR_ID_TEAMER === $attribute->getId() && true === $attribute->isSelected()) {
|
||||
$isTeam = true;
|
||||
if (CrmAttribute::ATTR_ID_ADMIN === $attribute->getId() && true === $attribute->isSelected()) {
|
||||
$isAdmin = true;
|
||||
}
|
||||
if (CrmAttribute::ATTR_ID_MANAGER === $attribute->getId() && true === $attribute->isSelected()) {
|
||||
$isManager = true;
|
||||
}
|
||||
if (CrmAttribute::ATTR_ID_TEAMER === $attribute->getId() && true === $attribute->isSelected()) {
|
||||
$isTeamer = true;
|
||||
}
|
||||
}
|
||||
$group->setAttributes($attributes);
|
||||
@@ -135,7 +139,9 @@ class ResponseParser
|
||||
$response = new CrmAttributesResponse();
|
||||
$response
|
||||
->setAttributeGroups($groups)
|
||||
->setTeamer($isTeam)
|
||||
->setAdmin($isAdmin)
|
||||
->setManager($isManager)
|
||||
->setTeamer($isTeamer)
|
||||
;
|
||||
|
||||
return $response;
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Admin;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
class IndexController extends AbstractController
|
||||
{
|
||||
#[Route('/admin', name: 'app_admin_index')]
|
||||
#[IsGranted('ROLE_ADMIN')]
|
||||
public function index(): Response
|
||||
{
|
||||
return $this->render('admin/index.html.twig');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Manager;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
class IndexController extends AbstractController
|
||||
{
|
||||
#[Route('/manager', name: 'app_manager_index')]
|
||||
#[IsGranted('ROLE_MANAGER')]
|
||||
public function index(): Response
|
||||
{
|
||||
return $this->render('manager/index.html.twig');
|
||||
}
|
||||
}
|
||||
@@ -23,4 +23,8 @@ class LoginController extends AbstractController
|
||||
'error' => $error,
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/logout', name: 'app_security_logout')]
|
||||
public function logout(): void
|
||||
{}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Teamer;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
class IndexController extends AbstractController
|
||||
{
|
||||
#[Route('/teamer', name: 'app_teamer_index')]
|
||||
#[IsGranted('ROLE_TEAMER')]
|
||||
public function index(): Response
|
||||
{
|
||||
return $this->render('teamer/index.html.twig');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity\Embeddable;
|
||||
|
||||
use App\BusProNet\Model\Address as BpnAddress;
|
||||
use App\BusProNet\Model\ProfileResponse;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
#[ORM\Embeddable]
|
||||
class Address
|
||||
{
|
||||
#[ORM\Column(type: 'string', nullable: true)]
|
||||
#[Assert\NotBlank(message: 'required_input')]
|
||||
protected ?string $street = null;
|
||||
|
||||
#[ORM\Column(type: 'string', nullable: true)]
|
||||
#[Assert\NotBlank(message: 'required_input')]
|
||||
protected ?string $postCode = null;
|
||||
|
||||
#[ORM\Column(type: 'string', nullable: true)]
|
||||
#[Assert\NotBlank(message: 'required_input')]
|
||||
protected ?string $city = null;
|
||||
|
||||
#[ORM\Column(type: 'string', nullable: true)]
|
||||
protected ?string $country = null;
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'street' => $this->getStreet(),
|
||||
'post_code' => $this->getPostCode(),
|
||||
'city' => $this->getCity(),
|
||||
'country' => $this->getCountry(),
|
||||
];
|
||||
}
|
||||
|
||||
public static function fromApiResponse(ProfileResponse $profileResponse): static
|
||||
{
|
||||
$address = $profileResponse->getAddress();
|
||||
|
||||
$instance = new static();
|
||||
$instance
|
||||
->setStreet($address->getStreet())
|
||||
->setPostCode($address->getPostCode())
|
||||
->setCity($address->getCity())
|
||||
->setCountry($address->getCountry() ?? 'DE')
|
||||
;
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
public function getStreet(): ?string
|
||||
{
|
||||
return $this->street;
|
||||
}
|
||||
|
||||
public function setStreet(?string $street): static
|
||||
{
|
||||
$this->street = $street;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPostCode(): ?string
|
||||
{
|
||||
return $this->postCode;
|
||||
}
|
||||
|
||||
public function setPostCode(?string $postCode): static
|
||||
{
|
||||
$this->postCode = $postCode;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCity(): ?string
|
||||
{
|
||||
return $this->city;
|
||||
}
|
||||
|
||||
public function setCity(?string $city): static
|
||||
{
|
||||
$this->city = $city;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCountry(): ?string
|
||||
{
|
||||
return $this->country;
|
||||
}
|
||||
|
||||
public function setCountry(?string $country): static
|
||||
{
|
||||
$this->country = $country;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity\Embeddable;
|
||||
|
||||
use App\BusProNet\Model\ProfileResponse;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
#[ORM\Embeddable]
|
||||
class Communication
|
||||
{
|
||||
#[ORM\Column(type: 'string', nullable: true)]
|
||||
protected ?string $phone = null;
|
||||
|
||||
#[ORM\Column(type: 'string', nullable: true)]
|
||||
protected ?string $mobile = null;
|
||||
|
||||
#[ORM\Column(type: 'string', nullable: true)]
|
||||
#[Assert\Email(mode: 'strict')]
|
||||
protected ?string $email = null;
|
||||
|
||||
public static function fromApiResponse(ProfileResponse $profileResponse): static
|
||||
{
|
||||
$communication = $profileResponse->getCommunication();
|
||||
|
||||
$instance = new static();
|
||||
$instance
|
||||
->setPhone($communication->getPhone())
|
||||
->setMobile($communication->getMobile())
|
||||
->setEmail($communication->getEmail())
|
||||
;
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
public function getPhone(): ?string
|
||||
{
|
||||
return $this->phone;
|
||||
}
|
||||
|
||||
public function setPhone(?string $phone): static
|
||||
{
|
||||
$this->phone = $phone;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getMobile(): ?string
|
||||
{
|
||||
return $this->mobile;
|
||||
}
|
||||
|
||||
public function setMobile(?string $mobile): static
|
||||
{
|
||||
$this->mobile = $mobile;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getEmail(): ?string
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
public function setEmail(?string $email): static
|
||||
{
|
||||
$this->email = $email;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity\Embeddable;
|
||||
|
||||
use App\BusProNet\Model\ProfileResponse;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Embeddable]
|
||||
class Profile
|
||||
{
|
||||
#[ORM\Column]
|
||||
private ?int $busProAddressId = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private ?int $busProPersonId = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $title = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $salutation = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $firstName = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $lastName = null;
|
||||
|
||||
#[ORM\Column(length: 1, nullable: true)]
|
||||
private ?string $gender = null;
|
||||
|
||||
#[ORM\Column(type: 'date_immutable', nullable: true)]
|
||||
private ?\DateTimeImmutable $dateOfBirth = null;
|
||||
|
||||
public static function fromApiResponse(ProfileResponse $profileResponse): static
|
||||
{
|
||||
$instance = new static();
|
||||
|
||||
$instance
|
||||
->setBusProAddressId($profileResponse->getAddressId())
|
||||
->setBusProPersonId($profileResponse->getPersonId())
|
||||
->setTitle($profileResponse->getTitle())
|
||||
->setSalutation($profileResponse->getSalutation())
|
||||
->setFirstName($profileResponse->getFirstName())
|
||||
->setLastName($profileResponse->getName())
|
||||
->setGender($profileResponse->getGender())
|
||||
->setDateOfBirth($profileResponse->getDateOfBirth())
|
||||
;
|
||||
|
||||
return $instance;
|
||||
|
||||
}
|
||||
|
||||
public function getBusProAddressId(): ?int
|
||||
{
|
||||
return $this->busProAddressId;
|
||||
}
|
||||
|
||||
public function setBusProAddressId(int $busProAddressId): static
|
||||
{
|
||||
$this->busProAddressId = $busProAddressId;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getBusProPersonId(): ?int
|
||||
{
|
||||
return $this->busProPersonId;
|
||||
}
|
||||
|
||||
public function setBusProPersonId(int $busProPersonId): static
|
||||
{
|
||||
$this->busProPersonId = $busProPersonId;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getSalutation(): ?string
|
||||
{
|
||||
return $this->salutation;
|
||||
}
|
||||
|
||||
public function setSalutation(?string $salutation): static
|
||||
{
|
||||
$this->salutation = $salutation;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTitle(): ?string
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
public function setTitle(?string $title): static
|
||||
{
|
||||
$this->title = $title;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getFirstName(): ?string
|
||||
{
|
||||
return $this->firstName;
|
||||
}
|
||||
|
||||
public function setFirstName(string $firstName): static
|
||||
{
|
||||
$this->firstName = $firstName;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getLastName(): ?string
|
||||
{
|
||||
return $this->lastName;
|
||||
}
|
||||
|
||||
public function setLastName(string $lastName): static
|
||||
{
|
||||
$this->lastName = $lastName;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getGender(): ?string
|
||||
{
|
||||
return $this->gender;
|
||||
}
|
||||
|
||||
public function setGender(?string $gender): static
|
||||
{
|
||||
$this->gender = $gender;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDateOfBirth(): ?\DateTimeImmutable
|
||||
{
|
||||
return $this->dateOfBirth;
|
||||
}
|
||||
|
||||
public function setDateOfBirth(?\DateTimeImmutable $dateOfBirth): static
|
||||
{
|
||||
$this->dateOfBirth = $dateOfBirth;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
+54
-55
@@ -2,10 +2,13 @@
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Entity\Embeddable\Address;
|
||||
use App\Entity\Embeddable\Communication;
|
||||
use App\Entity\Embeddable\Profile;
|
||||
use App\Repository\UserRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
#[ORM\Entity(repositoryClass: UserRepository::class)]
|
||||
class User implements UserInterface
|
||||
@@ -15,23 +18,23 @@ class User implements UserInterface
|
||||
#[ORM\Column]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private ?int $busProAddressId = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private ?int $busProPersonId = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $email = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $firstName = null;
|
||||
#[ORM\Embedded(class: Profile::class)]
|
||||
#[Assert\Valid()]
|
||||
private ?Profile $profile = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $lastName = null;
|
||||
#[ORM\Embedded(class: Address::class)]
|
||||
#[Assert\Valid()]
|
||||
private ?Address $address = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $role = null;
|
||||
#[ORM\Embedded(class: Communication::class)]
|
||||
#[Assert\Valid()]
|
||||
private ?Communication $communication = null;
|
||||
|
||||
#[ORM\Column(type: 'json')]
|
||||
private array $roles = [];
|
||||
|
||||
#[ORM\Column(nullable: true)]
|
||||
private ?\DateTimeImmutable $lastLoginAt = null;
|
||||
@@ -41,30 +44,6 @@ class User implements UserInterface
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getBusProAddressId(): ?int
|
||||
{
|
||||
return $this->busProAddressId;
|
||||
}
|
||||
|
||||
public function setBusProAddressId(int $busProAddressId): static
|
||||
{
|
||||
$this->busProAddressId = $busProAddressId;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getBusProPersonId(): ?int
|
||||
{
|
||||
return $this->busProPersonId;
|
||||
}
|
||||
|
||||
public function setBusProPersonId(int $busProPersonId): static
|
||||
{
|
||||
$this->busProPersonId = $busProPersonId;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getEmail(): ?string
|
||||
{
|
||||
return $this->email;
|
||||
@@ -77,42 +56,61 @@ class User implements UserInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getFirstName(): ?string
|
||||
public function getProfile(): ?Profile
|
||||
{
|
||||
return $this->firstName;
|
||||
return $this->profile;
|
||||
}
|
||||
|
||||
public function setFirstName(string $firstName): static
|
||||
public function setProfile(?Profile $profile): static
|
||||
{
|
||||
$this->firstName = $firstName;
|
||||
$this->profile = $profile;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getLastName(): ?string
|
||||
public function getAddress(): ?Address
|
||||
{
|
||||
return $this->lastName;
|
||||
return $this->address;
|
||||
}
|
||||
|
||||
public function setLastName(string $lastName): static
|
||||
public function setAddress(?Address $address): static
|
||||
{
|
||||
$this->lastName = $lastName;
|
||||
$this->address = $address;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getRole(): ?string
|
||||
public function getCommunication(): ?Communication
|
||||
{
|
||||
return $this->role;
|
||||
return $this->communication;
|
||||
}
|
||||
|
||||
public function setRole(string $role): static
|
||||
public function setCommunication(?Communication $communication): static
|
||||
{
|
||||
$this->role = $role;
|
||||
$this->communication = $communication;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getRoles(): array
|
||||
{
|
||||
$roles = ['ROLE_USER', ...$this->roles];
|
||||
|
||||
return array_unique($roles);
|
||||
}
|
||||
|
||||
public function setRoles(array $roles): static
|
||||
{
|
||||
$this->roles = $roles;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function hasRole(string $role): bool
|
||||
{
|
||||
return in_array($role, $this->getRoles());
|
||||
}
|
||||
|
||||
public function getLastLoginAt(): ?\DateTimeImmutable
|
||||
{
|
||||
return $this->lastLoginAt;
|
||||
@@ -127,12 +125,13 @@ class User implements UserInterface
|
||||
|
||||
public function getDefaultRoute(): string
|
||||
{
|
||||
return 'app_index';
|
||||
}
|
||||
|
||||
public function getRoles(): array
|
||||
{
|
||||
return ['ROLE_USER', $this->getRole()];
|
||||
if ($this->hasRole('ROLE_ADMIN')) {
|
||||
return 'app_admin_index';
|
||||
} elseif ($this->hasRole('ROLE_MANAGER')) {
|
||||
return 'app_manager_index';
|
||||
} else {
|
||||
return 'app_teamer_index';
|
||||
}
|
||||
}
|
||||
|
||||
public function eraseCredentials(): void
|
||||
|
||||
@@ -6,6 +6,9 @@ use App\BusProNet\ApiClient;
|
||||
use App\BusProNet\ApiClientException;
|
||||
use App\BusProNet\Model\CrmAttributesResponse;
|
||||
use App\BusProNet\Model\ProfileResponse;
|
||||
use App\Entity\Embeddable\Address;
|
||||
use App\Entity\Embeddable\Communication;
|
||||
use App\Entity\Embeddable\Profile;
|
||||
use App\Entity\User;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
@@ -81,19 +84,9 @@ class BpnAuthenticator extends AbstractLoginFormAuthenticator implements Authent
|
||||
return new RedirectResponse($url);
|
||||
}
|
||||
|
||||
private function getOrCreateLocalUser(ProfileResponse $profile, string $email, string $password): ?User
|
||||
private function getOrCreateLocalUser(ProfileResponse $profileResponse, string $email, string $password): ?User
|
||||
{
|
||||
$repository = $this->entityManager->getRepository(User::class);
|
||||
|
||||
$user = $repository->findOneBy([
|
||||
'busProAddressId' => $profile->getAddressId(),
|
||||
'busProPersonId' => $profile->getPersonId(),
|
||||
]);
|
||||
|
||||
if (null !== $user) {
|
||||
return $user;
|
||||
}
|
||||
|
||||
// Fetch CRM attributes, early return in case of an API arror
|
||||
try {
|
||||
/** @var CrmAttributesResponse $crmAttributes */
|
||||
$crmAttributes = $this->apiClient->getCrmAttributes($email, $password);
|
||||
@@ -101,19 +94,54 @@ class BpnAuthenticator extends AbstractLoginFormAuthenticator implements Authent
|
||||
return null;
|
||||
}
|
||||
|
||||
// Collect user's roles from CRM attributes
|
||||
$roles = [];
|
||||
|
||||
if ($crmAttributes->isAdmin()) {
|
||||
$roles[] = 'ROLE_ADMIN';
|
||||
}
|
||||
if ($crmAttributes->isManager()) {
|
||||
$roles[] = 'ROLE_MANAGER';
|
||||
}
|
||||
if ($crmAttributes->isTeamer()) {
|
||||
$roles[] = 'ROLE_TEAMER';
|
||||
}
|
||||
|
||||
// Get profile data from API response
|
||||
$profile = Profile::fromApiResponse($profileResponse);
|
||||
$address = Address::fromApiResponse($profileResponse);
|
||||
$communication = Communication::fromApiResponse($profileResponse);
|
||||
|
||||
// Check if user is already present in local database
|
||||
$repository = $this->entityManager->getRepository(User::class);
|
||||
|
||||
$user = $repository->findOneBy([
|
||||
'profile.busProAddressId' => $profileResponse->getAddressId(),
|
||||
'profile.busProPersonId' => $profileResponse->getPersonId(),
|
||||
]);
|
||||
|
||||
// Update existing user's roles and address and return it
|
||||
if (null !== $user) {
|
||||
$user
|
||||
->setProfile($profile)
|
||||
->setAddress($address)
|
||||
->setCommunication($communication)
|
||||
->setRoles($roles)
|
||||
;
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
// Create new user entity to persist locally otherwise
|
||||
$user = new User();
|
||||
$user
|
||||
->setBusProAddressId($profile->getAddressId())
|
||||
->setBusProPersonId($profile->getPersonId())
|
||||
->setEmail($profile->getCommunication()->getEmail())
|
||||
->setFirstName($profile->getFirstName())
|
||||
->setLastName($profile->getName())
|
||||
->setEmail($profileResponse->getCommunication()->getEmail())
|
||||
->setProfile($profile)
|
||||
->setAddress($address)
|
||||
->setCommunication($communication)
|
||||
->setRoles($roles)
|
||||
;
|
||||
|
||||
if ($crmAttributes->isTeamer()) {
|
||||
$user->setRole('ROLE_TEAMER');
|
||||
}
|
||||
|
||||
$this->entityManager->persist($user);
|
||||
$this->entityManager->flush();
|
||||
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
{% extends 'base.html.twig' %}
|
||||
|
||||
{% block body %}
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,4 @@
|
||||
{% extends 'base.html.twig' %}
|
||||
|
||||
{% block body %}
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,4 @@
|
||||
{% extends 'base.html.twig' %}
|
||||
|
||||
{% block body %}
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user