Include relationships in login response
dyb-tech.com/LaLiga-BackEnd/pipeline/head This commit looks good

This commit is contained in:
Daniel Guzman
2024-06-16 02:35:44 +02:00
parent 4eca9ab832
commit 887f1b47a5
780 changed files with 36283 additions and 3 deletions
+1
View File
@@ -4,6 +4,7 @@ namespace DMD\LaLigaApi\Controller;
use DMD\LaLigaApi\Repository\UserRepository;
use DMD\LaLigaApi\Service\User\Handlers\delete\HandleDeleteUser;
use DMD\LaLigaApi\Service\User\Handlers\getRelationships\HandleGetUserRelationships;
use DMD\LaLigaApi\Service\User\Handlers\update\HandleUpdateUser;
use DMD\LaLigaApi\Service\User\Handlers\register\HandleRegistration;
use Doctrine\ORM\EntityManagerInterface;
+17
View File
@@ -16,6 +16,7 @@ class UserDto
public string $profilePicture;
public \DateTimeInterface $birthday;
public array $noteList;
public bool $privacyPolicy;
public bool $active;
public array $receivedNotificationDtoList;
public array $validationErrors;
@@ -91,6 +92,10 @@ class UserDto
{
$this->phone = $userObj->getPhone();
}
if ($userObj->isPrivacyPolicy() !== null)
{
$this->privacyPolicy = $userObj->isPrivacyPolicy();
}
if ($userObj->getProfilePicture() !== null)
{
$this->profilePicture = $userObj->getProfilePicture();
@@ -156,6 +161,10 @@ class UserDto
{
$this->active = $dataList['active'];
}
if (isset($dataList['privacyPolicy']))
{
$this->privacyPolicy = $dataList['privacyPolicy'];
}
}
public function validate(): void
@@ -176,6 +185,14 @@ class UserDto
{
$this->validationErrors[] = 'El apellido no puede estar vacío';
}
if (empty($this->privacyPolicy))
{
$this->validationErrors[] = 'No puedes crear cuenta sin aceptar los términos y condiciones';
}
if (!$this->privacyPolicy)
{
$this->validationErrors[] = 'No puedes crear cuenta sin aceptar los términos y condiciones';
}
if (strlen($this->phone) !== 9)
{
$this->validationErrors[] = 'El número de teléfono debe tener 9 dígitos.';
+15
View File
@@ -64,6 +64,9 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
#[ORM\OneToMany(mappedBy: 'userToNotify', targetEntity: Notification::class, orphanRemoval: true)]
private Collection $receivedNotifications;
#[ORM\Column(nullable: true)]
private ?bool $privacyPolicy = null;
public function __construct()
{
@@ -349,4 +352,16 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
return $this;
}
public function isPrivacyPolicy(): ?bool
{
return $this->privacyPolicy;
}
public function setPrivacyPolicy(?bool $privacyPolicy): static
{
$this->privacyPolicy = $privacyPolicy;
return $this;
}
}
@@ -5,9 +5,9 @@ namespace DMD\LaLigaApi\Service\User\Handlers\login;
use DMD\LaLigaApi\Dto\NotificationDto;
use DMD\LaLigaApi\Dto\UserDto;
use DMD\LaLigaApi\Entity\User;
use DMD\LaLigaApi\Repository\CustomRoleRepository;
use Lexik\Bundle\JWTAuthenticationBundle\Event\AuthenticationSuccessEvent;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\Security\Core\User\UserInterface;
class AuthenticationSuccessListener
{
@@ -37,6 +37,19 @@ class AuthenticationSuccessListener
$data['expirationDateTime'] = $expirationDateTime->format('Y-m-d H:i:s');
$data['user'] = $userDto->toLoginArray();
$customRoleCollection = $user->getCustomRoles();
$relationshipArray = [];
if (!is_null($customRoleCollection))
{
foreach ($customRoleCollection as $customRoleEntity)
{
$relationshipArray[] = [
'role' => $customRoleEntity->getName(),
'entityId' => $customRoleEntity->getEntityId()
];
}
}
$data['relationships'] = $relationshipArray;
$event->setData($data);
}
}