Added S3 bucket for users
This commit is contained in:
parent
ead3666a4f
commit
0222274a17
|
|
@ -0,0 +1,32 @@
|
|||
<?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 Version20251013133256 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" ALTER picture_url DROP NOT NULL');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('CREATE SCHEMA public');
|
||||
$this->addSql('ALTER TABLE "user" ALTER picture_url SET NOT NULL');
|
||||
}
|
||||
}
|
||||
|
|
@ -10,6 +10,7 @@ use App\Entity\UserOrganizatonApp;
|
|||
use App\Entity\UsersOrganizations;
|
||||
use App\Form\UserForm;
|
||||
use App\Service\ActionService;
|
||||
use App\Service\AwsService;
|
||||
use App\Service\UserOrganizationAppService;
|
||||
use App\Service\UserOrganizationService;
|
||||
use App\Service\UserService;
|
||||
|
|
@ -30,7 +31,9 @@ class UserController extends AbstractController
|
|||
public function __construct(
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly UserService $userService,
|
||||
private readonly ActionService $actionService, private readonly UserOrganizationAppService $userOrganizationAppService, private readonly UserOrganizationService $userOrganizationService,
|
||||
private readonly ActionService $actionService,
|
||||
private readonly UserOrganizationAppService $userOrganizationAppService,
|
||||
private readonly UserOrganizationService $userOrganizationService,
|
||||
)
|
||||
{
|
||||
}
|
||||
|
|
@ -172,9 +175,10 @@ class UserController extends AbstractController
|
|||
|
||||
if ($picture) {
|
||||
$this->userService->handleProfilePicture($user, $picture);
|
||||
} else {
|
||||
$user->setPictureUrl("");
|
||||
}
|
||||
// else {
|
||||
// $user->setPictureUrl("");
|
||||
// }
|
||||
//FOR TEST PURPOSES, SETTING A DEFAULT RANDOM PASSWORD
|
||||
$user->setPassword($this->userService->generateRandomPassword());
|
||||
if ($orgId) {
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
|
|||
#[ORM\Column(options: ['default' => 'CURRENT_TIMESTAMP'])]
|
||||
private ?\DateTimeImmutable $createdAt = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $pictureUrl = null;
|
||||
|
||||
#[ORM\Column(options: ['default' => 'CURRENT_TIMESTAMP'])]
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ use App\Entity\Roles;
|
|||
use App\Entity\User;
|
||||
use App\Entity\UserOrganizatonApp;
|
||||
use App\Entity\UsersOrganizations;
|
||||
use App\Service\AwsService;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\EntityNotFoundException;
|
||||
|
|
@ -26,7 +27,7 @@ class UserService
|
|||
|
||||
public function __construct(private readonly EntityManagerInterface $entityManager,
|
||||
private readonly Security $security,
|
||||
string $profileDirectory
|
||||
string $profileDirectory, private readonly AwsService $awsService
|
||||
)
|
||||
{
|
||||
$this->profileDirectory = $profileDirectory;
|
||||
|
|
@ -246,25 +247,32 @@ class UserService
|
|||
|
||||
// Create custom filename: userNameUserSurname_ddmmyyhhmmss
|
||||
$customFilename = $user->getName() . $user->getSurname() . '_' . date('dmyHis') . '.' . $extension;
|
||||
try{
|
||||
$this->awsService->PutDocObj($_ENV['S3_PORTAL_BUCKET'], $picture, $customFilename , $extension, 'profile/');
|
||||
|
||||
// Define upload directory
|
||||
$uploadDirectory = $this->profileDirectory;
|
||||
// Create directory if it doesn't exist
|
||||
if (!is_dir($uploadDirectory) && !mkdir($uploadDirectory, 0755, true) && !is_dir($uploadDirectory)) {
|
||||
throw new DirectoryCouldNotBeCreatedException(sprintf('Directory "%s" was not created', $uploadDirectory));
|
||||
}
|
||||
try {
|
||||
|
||||
// Move the file to the upload directory
|
||||
$picture->move($uploadDirectory, $customFilename);
|
||||
|
||||
// Update user entity with the file path (relative to public directory)
|
||||
$user->setPictureUrl('uploads/profile/' . $customFilename);
|
||||
|
||||
$user->setPictureUrl('profile/'.$customFilename);
|
||||
} catch (FileException $e) {
|
||||
// Handle upload error
|
||||
throw new FileException('File upload failed: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
|
||||
|
||||
// // Define upload directory
|
||||
// $uploadDirectory = $this->profileDirectory;
|
||||
// // Create directory if it doesn't exist
|
||||
// if (!is_dir($uploadDirectory) && !mkdir($uploadDirectory, 0755, true) && !is_dir($uploadDirectory)) {
|
||||
// throw new DirectoryCouldNotBeCreatedException(sprintf('Directory "%s" was not created', $uploadDirectory));
|
||||
// }
|
||||
// try {
|
||||
//
|
||||
// // Move the file to the upload directory
|
||||
// $picture->move($uploadDirectory, $customFilename);
|
||||
//
|
||||
// // Update user entity with the file path (relative to public directory)
|
||||
// $user->setPictureUrl('uploads/profile/' . $customFilename);
|
||||
//
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -64,7 +64,12 @@
|
|||
<a id="profileDropdown" class="nav-link count-indicator dropdown-toggle m-auto" href="#" data-bs-toggle="dropdown">
|
||||
<div id="profil" class="rounded-circle bg-secondary d-flex">
|
||||
{% if app.user %}
|
||||
<p class="text-light m-auto">{{ app.user.email|first|capitalize }}</p>
|
||||
{# {% if app.user.pictureUrl is defined %}#}
|
||||
{# <img src="{{ aws_url ~ app.user.pictureUrl }}" alt="User profile pic"#}
|
||||
{# class="rounded-circle" style="width:40px; height:40px;">#}
|
||||
{# {% else %}#}
|
||||
<p class="text-light m-auto">{{ app.user.email|first|capitalize }}</p>
|
||||
{# {% endif %}#}
|
||||
{% endif %}
|
||||
</div>
|
||||
</a>
|
||||
|
|
@ -88,7 +93,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<a class="dropdown-item" style="padding-left: 8px;" href="{{ path('sso_logout') }}">
|
||||
<i class="me-2">{{ ux_icon('material-symbols:logout', {height: '20px', width: '20px'}) }}</i>
|
||||
<i class="me-2">{{ ux_icon('material-symbols:logout', {height: '20px', width: '20px'}) }}</i>
|
||||
Deconnexion
|
||||
</a>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -3,8 +3,10 @@
|
|||
<div class="card border-0">
|
||||
<div class="card-title shadow-sm p-3 d-flex justify-content-between align-items-center">
|
||||
<div class="d-flex">
|
||||
<img src="{{ asset(user.pictureUrl) }}" alt="user" class="me-3 rounded-circle"
|
||||
style="width: 50px; height: 50px;">
|
||||
{% if user.pictureUrl is not empty %}
|
||||
<img src="{{ aws_url ~ user.pictureUrl }}" alt="user" class="me-3 rounded-circle">
|
||||
{% endif %}
|
||||
|
||||
<h2>{{ user.surname|capitalize }} {{ user.name|capitalize }}</h2>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@
|
|||
<tr>
|
||||
<td>
|
||||
{% if user.entity.pictureUrl %}
|
||||
<img src="{{ asset(user.entity.pictureUrl) }}" alt="User profile pic"
|
||||
<img src="{{ aws_url ~ user.entity.pictureUrl }}" alt="User profile pic"
|
||||
class="rounded-circle"
|
||||
style="width:40px; height:40px;">
|
||||
{% else %}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
<tr>
|
||||
<td>
|
||||
{% if user.pictureUrl %}
|
||||
<img src="{{ asset(user.pictureUrl) }}" alt="User profile pic"
|
||||
<img src="{{ aws_url ~ user.pictureUrl }}" alt="User profile pic"
|
||||
class="rounded-circle" style="width:40px; height:40px;">
|
||||
{% endif %}
|
||||
</td>
|
||||
|
|
|
|||
Loading…
Reference in New Issue