diff --git a/.env b/.env index a7fd998..142902e 100755 --- a/.env +++ b/.env @@ -40,4 +40,5 @@ MESSENGER_TRANSPORT_DSN=doctrine://default?auto_setup=0 MAILER_DSN=null://null ###< symfony/mailer ### -BASE_PREFIX=kumora \ No newline at end of file +BASE_PREFIX=kumora +DEFAULT_IMAGE=https://camelia-studio.org/v5/images/camelia_studio.png \ No newline at end of file diff --git a/config/services.yaml b/config/services.yaml index 974cf96..08f36df 100755 --- a/config/services.yaml +++ b/config/services.yaml @@ -5,13 +5,15 @@ # https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration parameters: base.prefix: '%env(BASE_PREFIX)%' + default.image: '%env(DEFAULT_IMAGE)%' services: # default configuration for services in *this* file _defaults: autowire: true # Automatically injects dependencies in your services. autoconfigure: true # Automatically registers your services as commands, event subscribers, etc. - + bind: + string $defaultImage: '%default.image%' # makes classes in src/ available to be used as services # this creates a service per class whose id is the fully-qualified class name App\: diff --git a/migrations/Version20250122192521.php b/migrations/Version20250122192521.php new file mode 100644 index 0000000..a5fecd7 --- /dev/null +++ b/migrations/Version20250122192521.php @@ -0,0 +1,36 @@ +addSql('ALTER TABLE user ADD COLUMN fullname VARCHAR(255) NOT NULL'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('CREATE TEMPORARY TABLE __temp__user AS SELECT id, email, roles, password, folder_role FROM "user"'); + $this->addSql('DROP TABLE "user"'); + $this->addSql('CREATE TABLE "user" (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, email VARCHAR(255) NOT NULL, roles CLOB NOT NULL, password VARCHAR(255) NOT NULL, folder_role VARCHAR(255) NOT NULL)'); + $this->addSql('INSERT INTO "user" (id, email, roles, password, folder_role) SELECT id, email, roles, password, folder_role FROM __temp__user'); + $this->addSql('DROP TABLE __temp__user'); + $this->addSql('CREATE UNIQUE INDEX UNIQ_IDENTIFIER_EMAIL ON "user" (email)'); + } +} diff --git a/src/Command/CreateUserCommand.php b/src/Command/CreateUserCommand.php index 4de1627..c5e6bfd 100755 --- a/src/Command/CreateUserCommand.php +++ b/src/Command/CreateUserCommand.php @@ -34,6 +34,7 @@ class CreateUserCommand extends Command protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); + $fullname = $io->ask('Nom de l\'utilisateur'); $email = $io->ask('Email de l\'utilisateur'); $password = $io->askHidden('Mot de passe de l\'utilisateur'); $isAdmin = $io->confirm('Est-ce un administrateur ?'); @@ -46,6 +47,7 @@ class CreateUserCommand extends Command return Command::FAILURE; } $user = new User(); + $user->setFullname($fullname); $user->setEmail($email); $user->setPassword($this->passwordHasher->hashPassword($user, $password)); $user->setRoles($isAdmin ? ['ROLE_ADMIN'] : ['ROLE_USER']); diff --git a/src/Controller/ProfileController.php b/src/Controller/ProfileController.php index fa4ef5f..f11892a 100644 --- a/src/Controller/ProfileController.php +++ b/src/Controller/ProfileController.php @@ -4,8 +4,23 @@ declare(strict_types=1); namespace App\Controller; +use App\Entity\User; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\Routing\Attribute\Route; +use Symfony\Component\Security\Http\Attribute\IsGranted; class ProfileController extends AbstractController { + #[Route('/profile', name: 'app_profile')] + #[IsGranted('ROLE_USER')] + public function index() + { + /** + * @var User $user + */ + $user = $this->getUser(); + return $this->render('profile/index.html.twig', [ + 'user' => $user, + ]); + } } diff --git a/src/Entity/User.php b/src/Entity/User.php index 087726f..a408e1d 100755 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -41,6 +41,9 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface #[ORM\Column(enumType: RoleEnum::class)] private ?RoleEnum $folder_role = null; + #[ORM\Column(length: 255)] + private ?string $fullname = null; + public function getId(): ?int { return $this->id; @@ -127,4 +130,16 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface return $this; } + + public function getFullname(): ?string + { + return $this->fullname; + } + + public function setFullname(string $fullname): static + { + $this->fullname = $fullname; + + return $this; + } } diff --git a/src/Twig/Extension/GravatarExtension.php b/src/Twig/Extension/GravatarExtension.php new file mode 100644 index 0000000..ec835a9 --- /dev/null +++ b/src/Twig/Extension/GravatarExtension.php @@ -0,0 +1,20 @@ +defaultImage); + } +} diff --git a/templates/partials/navbar.html.twig b/templates/partials/navbar.html.twig index bf0d190..bc69837 100755 --- a/templates/partials/navbar.html.twig +++ b/templates/partials/navbar.html.twig @@ -28,6 +28,9 @@ Administration {% endif %} +
  • + Profil +
  • Se déconnecter
  • diff --git a/templates/profile/index.html.twig b/templates/profile/index.html.twig new file mode 100644 index 0000000..b8616f1 --- /dev/null +++ b/templates/profile/index.html.twig @@ -0,0 +1,35 @@ +{% extends 'base.html.twig' %} + +{% block title %}Le cloud de Camélia-Studio{% endblock %} + +{% block body %} +
    +
    +
    +
    + Avatar de l'utilisateur +
    +
    + {{ user.fullname }} +
    +
    + + Email : + {{ user.email }} +
    +
    + + Rôle : + {{ user.roles[0] == 'ROLE_ADMIN' ? 'Administrateur' : 'Utilisateur' }} +
    +
    + + Rôle de dossier : + {{ user.folderRole.value }} +
    +
    + +
    +
    + +{% endblock %} \ No newline at end of file