better form & mime type check
This commit is contained in:
Generated
-1
@@ -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" />
|
||||
|
||||
@@ -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>
|
||||
␍<style> .cls-1 { fill: #d9b78b; } .cls-1, .cls-2 { fill-rule: evenodd; } .cls-2 { fill: #699f4c; } </style>
|
||||
␍</defs>
|
||||
␍<path class="cls-1" d="M673.732,711.059c-0.515,2.6-1.1,5.991-2.857,5.991a1.622,1.622,0,0,1-.568-0.122c-0.594,1.447-1.291,4.5-2.08,5.969a17.955,17.955,0,0,0-3.618,27.1H630s1.523-8.425,4.2-8.986c16.79-3.523,17.786-12.908,17.786-12.908v-4.839c-0.875-1.261-1.643-4.763-2.289-6.338a1.627,1.627,0,0,1-.568.122c-1.759,0-2.342-3.389-2.857-5.991a6.631,6.631,0,0,1-.02-3.266c0-.123-0.021-0.248-0.021-0.37,0-9.285,3.642-16.34,11.773-17.321,0,0,1.306-.069,1.906-0.107,0.44,0.036,2.094.107,2.094,0.107,8.131,0.981,11.773,8.036,11.773,17.321,0,0.122-.019.247-0.021,0.37A6.631,6.631,0,0,1,673.732,711.059ZM660,689.974h0a0.672,0.672,0,1,1-.094.021C659.754,689.983,659.745,689.974,660,689.974Z" data-name="user copy" id="user_copy" transform="translate(-630 -689.969)"/>
|
||||
␍<path class="cls-2" d="M677.875,726a12,12,0,1,1-12,12A12,12,0,0,1,677.875,726ZM672,740h4v4a2,2,0,0,0,4,0v-4h4a2,2,0,0,0,0-4h-4v-4a2,2,0,0,0-4,0v4h-4A2,2,0,0,0,672,740Z" id="add" transform="translate(-630 -689.969)"/>
|
||||
␍</g>
|
||||
␍</svg>
|
||||
|
After Width: | Height: | Size: 1.6 KiB |
@@ -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>
|
||||
␍<style> .cls-1 { fill: #d9b78b; } .cls-1, .cls-2 { fill-rule: evenodd; } .cls-2 { fill: #9f4c4c; } </style>
|
||||
␍</defs>
|
||||
␍<path class="cls-1" d="M813.732,711.059c-0.515,2.6-1.1,5.991-2.857,5.991a1.622,1.622,0,0,1-.568-0.122c-0.594,1.447-1.291,4.5-2.08,5.969a17.955,17.955,0,0,0-3.618,27.1H770s1.522-8.425,4.2-8.986c16.79-3.523,17.786-12.908,17.786-12.908v-4.839c-0.875-1.261-1.643-4.763-2.289-6.338a1.622,1.622,0,0,1-.568.122c-1.759,0-2.342-3.389-2.857-5.991a6.631,6.631,0,0,1-.02-3.266c0-.123-0.021-0.248-0.021-0.37,0-9.285,3.642-16.34,11.773-17.321,0,0,1.306-.069,1.906-0.107,0.44,0.036,2.094.107,2.094,0.107,8.131,0.981,11.773,8.036,11.773,17.321,0,0.122-.019.247-0.021,0.37A6.631,6.631,0,0,1,813.732,711.059ZM800,689.974h0a0.672,0.672,0,1,1-.094.021C799.755,689.983,799.745,689.974,800,689.974Z" data-name="user copy" id="user_copy" transform="translate(-770 -689.969)"/>
|
||||
␍<path class="cls-2" d="M817.875,726a12,12,0,1,1-12,12A12,12,0,0,1,817.875,726ZM812,740h12a2,2,0,0,0,0-4H812A2,2,0,0,0,812,740Z" id="remove" transform="translate(-770 -689.969)"/>
|
||||
␍</g>
|
||||
␍</svg>
|
||||
|
After Width: | Height: | Size: 1.6 KiB |
@@ -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"/>
|
||||
␍<g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
␍<g id="SVGRepo_iconCarrier"> <title>plus-circle</title> <desc>Created with Sketch Beta.</desc> <defs> </defs> <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" sketch:type="MSPage"> <g id="Icon-Set" sketch:type="MSLayerGroup" transform="translate(-464.000000, -1087.000000)" fill="#00c203"> <path d="M480,1117 C472.268,1117 466,1110.73 466,1103 C466,1095.27 472.268,1089 480,1089 C487.732,1089 494,1095.27 494,1103 C494,1110.73 487.732,1117 480,1117 L480,1117 Z M480,1087 C471.163,1087 464,1094.16 464,1103 C464,1111.84 471.163,1119 480,1119 C488.837,1119 496,1111.84 496,1103 C496,1094.16 488.837,1087 480,1087 L480,1087 Z M486,1102 L481,1102 L481,1097 C481,1096.45 480.553,1096 480,1096 C479.447,1096 479,1096.45 479,1097 L479,1102 L474,1102 C473.447,1102 473,1102.45 473,1103 C473,1103.55 473.447,1104 474,1104 L479,1104 L479,1109 C479,1109.55 479.447,1110 480,1110 C480.553,1110 481,1109.55 481,1109 L481,1104 L486,1104 C486.553,1104 487,1103.55 487,1103 C487,1102.45 486.553,1102 486,1102 L486,1102 Z" id="plus-circle" sketch:type="MSShapeGroup"> </path> </g> </g> </g>
|
||||
␍</svg>
|
||||
|
After Width: | Height: | Size: 1.6 KiB |
@@ -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"/>
|
||||
␍<g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
␍<g id="SVGRepo_iconCarrier"> <path d="M42.7,469.3c0,23.5,19.1,42.7,42.7,42.7h341.3c23.5,0,42.7-19.1,42.7-42.7V192H42.7V469.3z M362.7,256h42.7v192h-42.7V256z M234.7,256h42.7v192h-42.7V256z M106.7,256h42.7v192h-42.7V256z M490.7,85.3h-128V42.7C362.7,19.1,343.5,0,320,0H192 c-23.5,0-42.7,19.1-42.7,42.7v42.7h-128C9.5,85.3,0,94.9,0,106.7V128c0,11.8,9.5,21.3,21.3,21.3h469.3c11.8,0,21.3-9.5,21.3-21.3 v-21.3C512,94.9,502.5,85.3,490.7,85.3z M320,85.3H192V42.7h128V85.3z"/> </g>
|
||||
␍</svg>
|
||||
|
After Width: | Height: | Size: 1023 B |
@@ -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"/>
|
||||
␍<g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
␍<g id="SVGRepo_iconCarrier"> <title>minus-circle</title> <desc>Created with Sketch Beta.</desc> <defs> </defs> <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" sketch:type="MSPage"> <g id="Icon-Set" sketch:type="MSLayerGroup" transform="translate(-516.000000, -1087.000000)" fill="#ff0000"> <path d="M532,1117 C524.268,1117 518,1110.73 518,1103 C518,1095.27 524.268,1089 532,1089 C539.732,1089 546,1095.27 546,1103 C546,1110.73 539.732,1117 532,1117 L532,1117 Z M532,1087 C523.163,1087 516,1094.16 516,1103 C516,1111.84 523.163,1119 532,1119 C540.837,1119 548,1111.84 548,1103 C548,1094.16 540.837,1087 532,1087 L532,1087 Z M538,1102 L526,1102 C525.447,1102 525,1102.45 525,1103 C525,1103.55 525.447,1104 526,1104 L538,1104 C538.553,1104 539,1103.55 539,1103 C539,1102.45 538.553,1102 538,1102 L538,1102 Z" id="minus-circle" sketch:type="MSShapeGroup"> </path> </g> </g> </g>
|
||||
␍</svg>
|
||||
|
After Width: | Height: | Size: 1.4 KiB |
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