better form & mime type check
This commit is contained in:
1
.idea/sortir.iml
generated
1
.idea/sortir.iml
generated
@@ -3,7 +3,6 @@
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" packagePrefix="App\" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" packagePrefix="App\Tests\" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/composer" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/doctrine/cache" />
|
||||
|
||||
13
public/img/accept-user.svg
Normal file
13
public/img/accept-user.svg
Normal file
@@ -0,0 +1,13 @@
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
|
||||
<!-- Uploaded to: SVG Repo, www.svgrepo.com, Transformed by: SVG Repo Mixer Tools -->
|
||||
<svg width="64px" height="64px" viewBox="-0.08 0 60.031 60.031" data-name="add user" id="add_user" xmlns="http://www.w3.org/2000/svg" fill="#000000">
|
||||
|
||||
<g id="SVGRepo_bgCarrier" stroke-width="0"/>
|
||||
|
||||
<g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
|
||||
<g id="SVGRepo_iconCarrier">
|
||||
|
||||
<defs>
|
||||
|
||||
|
After Width: | Height: | Size: 1.6 KiB |
13
public/img/deny-user.svg
Normal file
13
public/img/deny-user.svg
Normal file
@@ -0,0 +1,13 @@
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
|
||||
<!-- Uploaded to: SVG Repo, www.svgrepo.com, Transformed by: SVG Repo Mixer Tools -->
|
||||
<svg width="64px" height="64px" viewBox="-0.08 0 60.031 60.031" data-name="remove user" id="remove_user" xmlns="http://www.w3.org/2000/svg" fill="#ffffff" stroke="#ffffff">
|
||||
|
||||
<g id="SVGRepo_bgCarrier" stroke-width="0"/>
|
||||
|
||||
<g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
|
||||
<g id="SVGRepo_iconCarrier">
|
||||
|
||||
<defs>
|
||||
|
||||
|
After Width: | Height: | Size: 1.6 KiB |
7
public/img/user-able.svg
Normal file
7
public/img/user-able.svg
Normal file
@@ -0,0 +1,7 @@
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
|
||||
<!-- Uploaded to: SVG Repo, www.svgrepo.com, Transformed by: SVG Repo Mixer Tools -->
|
||||
<svg width="64px" height="64px" viewBox="0 0 32 32" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sketch="http://www.bohemiancoding.com/sketch/ns" fill="#000000">
|
||||
|
||||
<g id="SVGRepo_bgCarrier" stroke-width="0"/>
|
||||
|
||||
|
After Width: | Height: | Size: 1.6 KiB |
7
public/img/user-delete.svg
Normal file
7
public/img/user-delete.svg
Normal file
@@ -0,0 +1,7 @@
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
|
||||
<!-- Uploaded to: SVG Repo, www.svgrepo.com, Transformed by: SVG Repo Mixer Tools -->
|
||||
<svg fill="#000000" height="64px" width="64px" version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 512 512" enable-background="new 0 0 512 512" xml:space="preserve">
|
||||
|
||||
<g id="SVGRepo_bgCarrier" stroke-width="0"/>
|
||||
|
||||
|
After Width: | Height: | Size: 1023 B |
7
public/img/user-disable.svg
Normal file
7
public/img/user-disable.svg
Normal file
@@ -0,0 +1,7 @@
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
|
||||
<!-- Uploaded to: SVG Repo, www.svgrepo.com, Transformed by: SVG Repo Mixer Tools -->
|
||||
<svg width="64px" height="64px" viewBox="0 0 32 32" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sketch="http://www.bohemiancoding.com/sketch/ns" fill="#000000">
|
||||
|
||||
<g id="SVGRepo_bgCarrier" stroke-width="0"/>
|
||||
|
||||
|
After Width: | Height: | Size: 1.4 KiB |
BIN
public/upload/image/profile/avatar-673f122734b9c.jpg
Normal file
BIN
public/upload/image/profile/avatar-673f122734b9c.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.5 KiB |
@@ -9,6 +9,7 @@ use App\Form\RegistrationFormType;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Mime\MimeTypes;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use App\Repository\ParticipantRepository;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||
@@ -51,6 +52,26 @@ class ProfileController extends AbstractController
|
||||
$form->handleRequest($request);
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$imageFile = $form->get('image')->getData();
|
||||
if ($imageFile) {
|
||||
if ($imageFile->getSize() > 1024 * 1024) { // 1MB
|
||||
$this->addFlash('error', 'Votre image est trop lourde');
|
||||
return $this->render('profile/edit.html.twig', [
|
||||
'profile' => $userConnect,
|
||||
'formProfile' => $form,
|
||||
]);
|
||||
}
|
||||
|
||||
$mimeTypes = new MimeTypes();
|
||||
$validMimeTypes = ['image/png', 'image/jpeg'];
|
||||
$fileMimeType = $mimeTypes->guessMimeType($imageFile->getRealPath());
|
||||
if (!in_array($fileMimeType, $validMimeTypes, true)) {
|
||||
$this->addFlash('error', "Veuillez insérer un type d'image valide (.jpg ou .png)");
|
||||
return $this->render('profile/edit.html.twig', [
|
||||
'profile' => $userConnect,
|
||||
'formProfile' => $form,
|
||||
]);
|
||||
}
|
||||
}
|
||||
if (($form->has('deleteImage') && $form['deleteImage']->getData()) || $imageFile) {
|
||||
$this->fileUploader->delete($profile->getFileName(), '/upload/image/profile');
|
||||
if ($imageFile) {
|
||||
|
||||
@@ -117,16 +117,6 @@ class ProfileFormType extends AbstractType
|
||||
'class' => 'w-full mb-4 px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:border-blue-500',
|
||||
],
|
||||
'label_attr' => ['class' => 'text-gray-700 font-bold'],
|
||||
'constraints' => [
|
||||
new File([
|
||||
'maxSize' => '1024k',
|
||||
'mimeTypes' => [
|
||||
'image/png',
|
||||
'image/jpeg',
|
||||
],
|
||||
'mimeTypesMessage' => 'Please upload a valid image',
|
||||
])
|
||||
],
|
||||
])
|
||||
->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
|
||||
$profile = $event->getData();
|
||||
|
||||
@@ -90,39 +90,6 @@ class RegistrationFormType extends AbstractType
|
||||
]),
|
||||
],
|
||||
])
|
||||
->add('image', FileType::class, [
|
||||
'label' => 'Image',
|
||||
'mapped' => false,
|
||||
'required' => false,
|
||||
'attr' => [
|
||||
'class' => 'w-full mb-4 px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:border-blue-500',
|
||||
],
|
||||
'label_attr' => ['class' => 'text-gray-700 font-bold'],
|
||||
'constraints' => [
|
||||
new File([
|
||||
'maxSize' => '1024k',
|
||||
'mimeTypes' => [
|
||||
'image/png',
|
||||
'image/jpeg',
|
||||
],
|
||||
'mimeTypesMessage' => 'Please upload a valid image',
|
||||
])
|
||||
],
|
||||
])
|
||||
->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
|
||||
$profile = $event->getData();
|
||||
if ($profile && $profile->getFileName()) {
|
||||
$form = $event->getForm();
|
||||
$form->add('deleteImage', CheckboxType::class, [
|
||||
'required' => false,
|
||||
'mapped' => false,
|
||||
'label' => 'Supprimer l\'image',
|
||||
'attr' => [
|
||||
'class' => 'w-4 h-4 mb-4 border-gray-300 rounded mx-2',
|
||||
], 'label_attr' => ['class' => 'text-gray-700 font-bold px-4']
|
||||
]);
|
||||
}
|
||||
})
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
@@ -77,11 +77,13 @@
|
||||
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">
|
||||
{{ participant.roles|join(', ') }}
|
||||
</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
|
||||
<a href="{{ path('app_adminUserDisable', {'id': participant.idParticipant}) }}" class="text-indigo-600 hover:text-indigo-900">
|
||||
{{ participant.actif ? '✔️' : '❌' }}
|
||||
<td class="flex flex-row px-6 py-4 whitespace-nowrap items-center font-medium">
|
||||
<a href="{{ path('app_adminUserDisable', {'id': participant.idParticipant}) }}" class="items-centerp pr-4">
|
||||
<img src="{{ participant.actif ? asset('img/user-able.svg') : asset('img/user-disable.svg') }}" alt="Logo" height="32px" width="32px">
|
||||
</a>
|
||||
<a href="{{ path('app_adminUserDelete', {'id': participant.idParticipant}) }}" class="items-center">
|
||||
<img src="{{ asset('img/user-delete.svg') }}" alt="Logo" height="32px" width="32px">
|
||||
</a>
|
||||
<a href="{{ path('app_adminUserDelete', {'id': participant.idParticipant}) }}" class="text-red-600 hover:text-red-900 ml-4">🗑️</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
@@ -132,10 +134,14 @@
|
||||
<label>
|
||||
<input type="hidden" name="id" value="{{ participant.idParticipant }}" />
|
||||
</label>
|
||||
<button type="submit"
|
||||
class="text-indigo-600 hover:text-indigo-900">👍</button>
|
||||
<a href="{{ path('app_denyUser', {'id': participant.idParticipant}) }}"
|
||||
class="text-red-600 hover:text-red-900 ml-4">👎</a>
|
||||
<button type="submit" class="px-4">
|
||||
<img src="{{ asset('img/accept-user.svg') }}" alt="Logo" height="32px" width="32px">
|
||||
</button>
|
||||
<button type="button">
|
||||
<a href="{{ path('app_denyUser', {'id': participant.idParticipant}) }}">
|
||||
<img src="{{ asset('img/deny-user.svg') }}" alt="Logo" height="32px" width="32px">
|
||||
</a>
|
||||
</button>
|
||||
</td>
|
||||
</form>
|
||||
</tr>
|
||||
|
||||
@@ -19,21 +19,21 @@
|
||||
{% if label == 'success' %}
|
||||
<div class="p-4 text-sm text-green-800 rounded-lg bg-green-50 dark:bg-gray-800 dark:text-green-400 text-center" role="alert">
|
||||
<span class="font-medium">
|
||||
{{ message }}
|
||||
✔️ {{ message }} ✔️
|
||||
</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if label == 'error' %}
|
||||
<div class="p-4 text-sm text-red-800 rounded-lg bg-red-50 dark:bg-gray-800 dark:text-red-400 text-center" role="alert">
|
||||
<span class="font-medium">
|
||||
{{ message }}
|
||||
⛔ {{ message }} ⛔
|
||||
</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if label == 'warning' %}
|
||||
<div class="p-4 text-sm text-yellow-800 rounded-lg bg-yellow-50 dark:bg-gray-800 dark:text-yellow-400 text-center" role="alert">
|
||||
<span class="font-medium">
|
||||
{{ message }}
|
||||
⚠️ {{ message }} ⚠️
|
||||
</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
Reference in New Issue
Block a user