mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-27 04:08:57 +02:00
Applied symplify rules to codebase.
This commit is contained in:
parent
2f20d90041
commit
388e847b17
136 changed files with 1370 additions and 789 deletions
|
@ -31,6 +31,7 @@ use App\Services\EntityExporter;
|
|||
use App\Services\EntityImporter;
|
||||
use App\Services\StructuralElementRecursionHelper;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
@ -49,7 +50,7 @@ class AttachmentTypeController extends BaseAdminController
|
|||
/**
|
||||
* @Route("/{id}", name="attachment_type_delete", methods={"DELETE"})
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function delete(Request $request, AttachmentType $entity, StructuralElementRecursionHelper $recursionHelper)
|
||||
{
|
||||
|
|
|
@ -36,6 +36,7 @@ use App\Services\EntityExporter;
|
|||
use App\Services\EntityImporter;
|
||||
use App\Services\StructuralElementRecursionHelper;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use InvalidArgumentException;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||
|
@ -61,11 +62,11 @@ abstract class BaseAdminController extends AbstractController
|
|||
AttachmentManager $attachmentHelper, AttachmentSubmitHandler $attachmentSubmitHandler)
|
||||
{
|
||||
if ('' === $this->entity_class || '' === $this->form_class || '' === $this->twig_template || '' === $this->route_base) {
|
||||
throw new \InvalidArgumentException('You have to override the $entity_class, $form_class, $route_base and $twig_template value in your subclasss!');
|
||||
throw new InvalidArgumentException('You have to override the $entity_class, $form_class, $route_base and $twig_template value in your subclasss!');
|
||||
}
|
||||
|
||||
if ('' === $this->attachment_class) {
|
||||
throw new \InvalidArgumentException('You have to override the $attachment_class value in your subclass!');
|
||||
throw new InvalidArgumentException('You have to override the $attachment_class value in your subclass!');
|
||||
}
|
||||
|
||||
$this->translator = $translator;
|
||||
|
@ -101,10 +102,10 @@ abstract class BaseAdminController extends AbstractController
|
|||
|
||||
try {
|
||||
$this->attachmentSubmitHandler->handleFormSubmit($attachment->getData(), $attachment['file']->getData(), $options);
|
||||
} catch (AttachmentDownloadException $ex) {
|
||||
} catch (AttachmentDownloadException $attachmentDownloadException) {
|
||||
$this->addFlash(
|
||||
'error',
|
||||
$this->translator->trans('attachment.download_failed').' '.$ex->getMessage()
|
||||
$this->translator->trans('attachment.download_failed').' '.$attachmentDownloadException->getMessage()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -158,10 +159,10 @@ abstract class BaseAdminController extends AbstractController
|
|||
|
||||
try {
|
||||
$this->attachmentSubmitHandler->handleFormSubmit($attachment->getData(), $attachment['file']->getData(), $options);
|
||||
} catch (AttachmentDownloadException $ex) {
|
||||
} catch (AttachmentDownloadException $attachmentDownloadException) {
|
||||
$this->addFlash(
|
||||
'error',
|
||||
$this->translator->trans('attachment.download_failed').' '.$ex->getMessage()
|
||||
$this->translator->trans('attachment.download_failed').' '.$attachmentDownloadException->getMessage()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -186,8 +187,12 @@ abstract class BaseAdminController extends AbstractController
|
|||
$file = $import_form['file']->getData();
|
||||
$data = $import_form->getData();
|
||||
|
||||
$options = ['parent' => $data['parent'], 'preserve_children' => $data['preserve_children'],
|
||||
'format' => $data['format'], 'csv_separator' => $data['csv_separator'], ];
|
||||
$options = [
|
||||
'parent' => $data['parent'],
|
||||
'preserve_children' => $data['preserve_children'],
|
||||
'format' => $data['format'],
|
||||
'csv_separator' => $data['csv_separator'],
|
||||
];
|
||||
|
||||
$errors = $importer->fileToDBEntities($file, $this->entity_class, $options);
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ use App\Services\EntityExporter;
|
|||
use App\Services\EntityImporter;
|
||||
use App\Services\StructuralElementRecursionHelper;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
@ -49,7 +50,7 @@ class CategoryController extends BaseAdminController
|
|||
/**
|
||||
* @Route("/{id}", name="category_delete", methods={"DELETE"})
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function delete(Request $request, Category $entity, StructuralElementRecursionHelper $recursionHelper)
|
||||
{
|
||||
|
|
|
@ -31,6 +31,7 @@ use App\Services\EntityExporter;
|
|||
use App\Services\EntityImporter;
|
||||
use App\Services\StructuralElementRecursionHelper;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
@ -51,7 +52,7 @@ class CurrencyController extends BaseAdminController
|
|||
/**
|
||||
* @Route("/{id}", name="currency_delete", methods={"DELETE"})
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function delete(Request $request, Currency $entity, StructuralElementRecursionHelper $recursionHelper)
|
||||
{
|
||||
|
|
|
@ -31,6 +31,7 @@ use App\Services\EntityExporter;
|
|||
use App\Services\EntityImporter;
|
||||
use App\Services\StructuralElementRecursionHelper;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
@ -49,7 +50,7 @@ class DeviceController extends BaseAdminController
|
|||
/**
|
||||
* @Route("/{id}", name="device_delete", methods={"DELETE"})
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function delete(Request $request, Device $entity, StructuralElementRecursionHelper $recursionHelper)
|
||||
{
|
||||
|
|
|
@ -28,10 +28,14 @@ use App\DataTables\AttachmentDataTable;
|
|||
use App\Entity\Attachments\Attachment;
|
||||
use App\Entity\Attachments\PartAttachment;
|
||||
use App\Services\Attachments\AttachmentManager;
|
||||
use Exception;
|
||||
use Omines\DataTablesBundle\DataTableFactory;
|
||||
use RuntimeException;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
|
@ -49,11 +53,11 @@ class AttachmentFileController extends AbstractController
|
|||
$this->denyAccessUnlessGranted('read', $attachment);
|
||||
|
||||
if ($attachment->isExternal()) {
|
||||
throw new \RuntimeException('You can not download external attachments!');
|
||||
throw new RuntimeException('You can not download external attachments!');
|
||||
}
|
||||
|
||||
if (! $helper->isFileExisting($attachment)) {
|
||||
throw new \RuntimeException('The file associated with the attachment is not existing!');
|
||||
throw new RuntimeException('The file associated with the attachment is not existing!');
|
||||
}
|
||||
|
||||
$file_path = $helper->toAbsoluteFilePath($attachment);
|
||||
|
@ -72,18 +76,18 @@ class AttachmentFileController extends AbstractController
|
|||
*
|
||||
* @return BinaryFileResponse
|
||||
*
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function view(Attachment $attachment, AttachmentManager $helper)
|
||||
{
|
||||
$this->denyAccessUnlessGranted('read', $attachment);
|
||||
|
||||
if ($attachment->isExternal()) {
|
||||
throw new \RuntimeException('You can not download external attachments!');
|
||||
throw new RuntimeException('You can not download external attachments!');
|
||||
}
|
||||
|
||||
if (! $helper->isFileExisting($attachment)) {
|
||||
throw new \RuntimeException('The file associated with the attachment is not existing!');
|
||||
throw new RuntimeException('The file associated with the attachment is not existing!');
|
||||
}
|
||||
|
||||
$file_path = $helper->toAbsoluteFilePath($attachment);
|
||||
|
@ -98,7 +102,7 @@ class AttachmentFileController extends AbstractController
|
|||
/**
|
||||
* @Route("/attachment/list", name="attachment_list")
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\Response
|
||||
* @return JsonResponse|Response
|
||||
*/
|
||||
public function attachmentsTable(DataTableFactory $dataTable, Request $request)
|
||||
{
|
||||
|
|
|
@ -32,6 +32,7 @@ use App\Services\EntityExporter;
|
|||
use App\Services\EntityImporter;
|
||||
use App\Services\StructuralElementRecursionHelper;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
@ -72,7 +73,7 @@ class GroupController extends BaseAdminController
|
|||
/**
|
||||
* @Route("/{id}", name="group_delete", methods={"DELETE"})
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function delete(Request $request, Group $entity, StructuralElementRecursionHelper $recursionHelper)
|
||||
{
|
||||
|
|
|
@ -25,6 +25,7 @@ declare(strict_types=1);
|
|||
namespace App\Controller;
|
||||
|
||||
use App\Services\GitVersionInfo;
|
||||
use const DIRECTORY_SEPARATOR;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
@ -46,7 +47,7 @@ class HomepageController extends AbstractController
|
|||
$banner = $this->getParameter('banner');
|
||||
if (empty($banner)) {
|
||||
$banner_path = $this->kernel->getProjectDir()
|
||||
.\DIRECTORY_SEPARATOR.'config'.\DIRECTORY_SEPARATOR.'banner.md';
|
||||
.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'banner.md';
|
||||
|
||||
return file_get_contents($banner_path);
|
||||
}
|
||||
|
|
|
@ -35,7 +35,9 @@ use App\Services\PricedetailHelper;
|
|||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
|
@ -48,7 +50,7 @@ class PartController extends AbstractController
|
|||
* @Route("/{id}/info", name="part_info")
|
||||
* @Route("/{id}", requirements={"id"="\d+"})
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
* @return Response
|
||||
*/
|
||||
public function show(Part $part, AttachmentManager $attachmentHelper, PricedetailHelper $pricedetailHelper, PartPreviewGenerator $previewGenerator)
|
||||
{
|
||||
|
@ -68,7 +70,7 @@ class PartController extends AbstractController
|
|||
/**
|
||||
* @Route("/{id}/edit", name="part_edit")
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
* @return Response
|
||||
*/
|
||||
public function edit(Part $part, Request $request, EntityManagerInterface $em, TranslatorInterface $translator,
|
||||
AttachmentManager $attachmentHelper, AttachmentSubmitHandler $attachmentSubmitHandler)
|
||||
|
@ -90,10 +92,10 @@ class PartController extends AbstractController
|
|||
|
||||
try {
|
||||
$attachmentSubmitHandler->handleFormSubmit($attachment->getData(), $attachment['file']->getData(), $options);
|
||||
} catch (AttachmentDownloadException $ex) {
|
||||
} catch (AttachmentDownloadException $attachmentDownloadException) {
|
||||
$this->addFlash(
|
||||
'error',
|
||||
$translator->trans('attachment.download_failed').' '.$ex->getMessage()
|
||||
$translator->trans('attachment.download_failed').' '.$attachmentDownloadException->getMessage()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -118,7 +120,7 @@ class PartController extends AbstractController
|
|||
/**
|
||||
* @Route("/{id}/delete", name="part_delete", methods={"DELETE"})
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function delete(Request $request, Part $part)
|
||||
{
|
||||
|
@ -142,7 +144,7 @@ class PartController extends AbstractController
|
|||
/**
|
||||
* @Route("/new", name="part_new")
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
* @return Response
|
||||
*/
|
||||
public function new(Request $request, EntityManagerInterface $em, TranslatorInterface $translator,
|
||||
AttachmentManager $attachmentHelper, AttachmentSubmitHandler $attachmentSubmitHandler)
|
||||
|
@ -174,10 +176,10 @@ class PartController extends AbstractController
|
|||
|
||||
try {
|
||||
$attachmentSubmitHandler->handleFormSubmit($attachment->getData(), $attachment['file']->getData(), $options);
|
||||
} catch (AttachmentDownloadException $ex) {
|
||||
} catch (AttachmentDownloadException $attachmentDownloadException) {
|
||||
$this->addFlash(
|
||||
'error',
|
||||
$translator->trans('attachment.download_failed').' '.$ex->getMessage()
|
||||
$translator->trans('attachment.download_failed').' '.$attachmentDownloadException->getMessage()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -204,7 +206,7 @@ class PartController extends AbstractController
|
|||
/**
|
||||
* @Route("/{id}/clone", name="part_clone")
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
|
||||
* @return RedirectResponse|Response
|
||||
*/
|
||||
public function clone(Part $part, Request $request, EntityManagerInterface $em, TranslatorInterface $translator)
|
||||
{
|
||||
|
|
|
@ -32,7 +32,9 @@ use App\Entity\Parts\Storelocation;
|
|||
use App\Entity\Parts\Supplier;
|
||||
use Omines\DataTablesBundle\DataTableFactory;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
class PartListsController extends AbstractController
|
||||
|
@ -40,7 +42,7 @@ class PartListsController extends AbstractController
|
|||
/**
|
||||
* @Route("/category/{id}/parts", name="part_list_category")
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\Response
|
||||
* @return JsonResponse|Response
|
||||
*/
|
||||
public function showCategory(Category $category, Request $request, DataTableFactory $dataTable)
|
||||
{
|
||||
|
@ -60,7 +62,7 @@ class PartListsController extends AbstractController
|
|||
/**
|
||||
* @Route("/footprint/{id}/parts", name="part_list_footprint")
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\Response
|
||||
* @return JsonResponse|Response
|
||||
*/
|
||||
public function showFootprint(Footprint $footprint, Request $request, DataTableFactory $dataTable)
|
||||
{
|
||||
|
@ -80,7 +82,7 @@ class PartListsController extends AbstractController
|
|||
/**
|
||||
* @Route("/manufacturer/{id}/parts", name="part_list_manufacturer")
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\Response
|
||||
* @return JsonResponse|Response
|
||||
*/
|
||||
public function showManufacturer(Manufacturer $manufacturer, Request $request, DataTableFactory $dataTable)
|
||||
{
|
||||
|
@ -100,7 +102,7 @@ class PartListsController extends AbstractController
|
|||
/**
|
||||
* @Route("/store_location/{id}/parts", name="part_list_store_location")
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\Response
|
||||
* @return JsonResponse|Response
|
||||
*/
|
||||
public function showStorelocation(Storelocation $storelocation, Request $request, DataTableFactory $dataTable)
|
||||
{
|
||||
|
@ -120,7 +122,7 @@ class PartListsController extends AbstractController
|
|||
/**
|
||||
* @Route("/supplier/{id}/parts", name="part_list_supplier")
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\Response
|
||||
* @return JsonResponse|Response
|
||||
*/
|
||||
public function showSupplier(Supplier $supplier, Request $request, DataTableFactory $dataTable)
|
||||
{
|
||||
|
@ -140,7 +142,7 @@ class PartListsController extends AbstractController
|
|||
/**
|
||||
* @Route("/parts/by_tag/{tag}", name="part_list_tags")
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\Response
|
||||
* @return JsonResponse|Response
|
||||
*/
|
||||
public function showTag(string $tag, Request $request, DataTableFactory $dataTable)
|
||||
{
|
||||
|
@ -180,7 +182,7 @@ class PartListsController extends AbstractController
|
|||
/**
|
||||
* @Route("/parts", name="parts_show_all")
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\Response
|
||||
* @return JsonResponse|Response
|
||||
*/
|
||||
public function showAll(Request $request, DataTableFactory $dataTable)
|
||||
{
|
||||
|
|
|
@ -25,7 +25,10 @@ declare(strict_types=1);
|
|||
namespace App\Controller;
|
||||
|
||||
use App\Entity\UserSystem\User;
|
||||
use function function_exists;
|
||||
use function in_array;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Session\SessionInterface;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
@ -49,7 +52,7 @@ class RedirectController extends AbstractController
|
|||
* This function is called whenever a route was not matching the localized routes.
|
||||
* The purpose is to redirect the user to the localized version of the page.
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function addLocalePart(Request $request)
|
||||
{
|
||||
|
@ -84,13 +87,13 @@ class RedirectController extends AbstractController
|
|||
*/
|
||||
public function checkIfModRewriteAvailable()
|
||||
{
|
||||
if (! \function_exists('apache_get_modules')) {
|
||||
if (! function_exists('apache_get_modules')) {
|
||||
//If we can not check for apache modules, we just hope for the best and assume url rewriting is available
|
||||
//If you want to enforce index.php versions of the url, you can override this via ENV vars.
|
||||
return true;
|
||||
}
|
||||
|
||||
//Check if the mod_rewrite module is loaded
|
||||
return \in_array('mod_rewrite', apache_get_modules(), false);
|
||||
return in_array('mod_rewrite', apache_get_modules(), false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ namespace App\Controller;
|
|||
|
||||
use App\Services\PasswordResetManager;
|
||||
use Gregwar\CaptchaBundle\Type\CaptchaType;
|
||||
use RuntimeException;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
|
||||
|
@ -122,7 +123,10 @@ class SecurityController extends AbstractController
|
|||
throw new AccessDeniedHttpException('You are already logged in, so you can not reset your password!');
|
||||
}
|
||||
|
||||
$data = ['username' => $user, 'token' => $token];
|
||||
$data = [
|
||||
'username' => $user,
|
||||
'token' => $token,
|
||||
];
|
||||
$builder = $this->createFormBuilder($data);
|
||||
$builder->add('username', TextType::class, [
|
||||
'label' => $this->translator->trans('pw_reset.username'),
|
||||
|
@ -132,8 +136,12 @@ class SecurityController extends AbstractController
|
|||
]);
|
||||
$builder->add('new_password', RepeatedType::class, [
|
||||
'type' => PasswordType::class,
|
||||
'first_options' => ['label' => 'user.settings.pw_new.label'],
|
||||
'second_options' => ['label' => 'user.settings.pw_confirm.label'],
|
||||
'first_options' => [
|
||||
'label' => 'user.settings.pw_new.label',
|
||||
],
|
||||
'second_options' => [
|
||||
'label' => 'user.settings.pw_confirm.label',
|
||||
],
|
||||
'invalid_message' => 'password_must_match',
|
||||
'constraints' => [new Length([
|
||||
'min' => 6,
|
||||
|
@ -171,6 +179,6 @@ class SecurityController extends AbstractController
|
|||
*/
|
||||
public function logout(): void
|
||||
{
|
||||
throw new \RuntimeException('Will be intercepted before getting here');
|
||||
throw new RuntimeException('Will be intercepted before getting here');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ use App\Services\EntityExporter;
|
|||
use App\Services\EntityImporter;
|
||||
use App\Services\StructuralElementRecursionHelper;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use InvalidArgumentException;
|
||||
use Symfony\Component\Asset\Packages;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
@ -99,7 +100,7 @@ class UserController extends AdminPages\BaseAdminController
|
|||
public function delete(Request $request, User $entity, StructuralElementRecursionHelper $recursionHelper)
|
||||
{
|
||||
if (User::ID_ANONYMOUS === $entity->getID()) {
|
||||
throw new \InvalidArgumentException('You can not delete the anonymous user! It is needed for permission checking without a logged in user');
|
||||
throw new InvalidArgumentException('You can not delete the anonymous user! It is needed for permission checking without a logged in user');
|
||||
}
|
||||
|
||||
return $this->_delete($request, $entity, $recursionHelper);
|
||||
|
|
|
@ -30,12 +30,14 @@ use App\Form\TFAGoogleSettingsType;
|
|||
use App\Form\UserSettingsType;
|
||||
use App\Services\TFA\BackupCodeManager;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use RuntimeException;
|
||||
use Scheb\TwoFactorBundle\Security\TwoFactor\Provider\Google\GoogleAuthenticator;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
|
||||
|
@ -65,13 +67,13 @@ class UserSettingsController extends AbstractController
|
|||
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
|
||||
|
||||
if (! $user instanceof User) {
|
||||
return new \RuntimeException('This controller only works only for Part-DB User objects!');
|
||||
return new RuntimeException('This controller only works only for Part-DB User objects!');
|
||||
}
|
||||
|
||||
if (empty($user->getBackupCodes())) {
|
||||
$this->addFlash('error', 'tfa_backup.no_codes_enabled');
|
||||
|
||||
throw new \RuntimeException('You do not have any backup codes enabled, therefore you can not view them!');
|
||||
throw new RuntimeException('You do not have any backup codes enabled, therefore you can not view them!');
|
||||
}
|
||||
|
||||
return $this->render('Users/backup_codes.html.twig', [
|
||||
|
@ -82,12 +84,12 @@ class UserSettingsController extends AbstractController
|
|||
/**
|
||||
* @Route("/u2f_delete", name="u2f_delete", methods={"DELETE"})
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function removeU2FToken(Request $request, EntityManagerInterface $entityManager, BackupCodeManager $backupCodeManager)
|
||||
{
|
||||
if ($this->demo_mode) {
|
||||
throw new \RuntimeException('You can not do 2FA things in demo mode');
|
||||
throw new RuntimeException('You can not do 2FA things in demo mode');
|
||||
}
|
||||
|
||||
$user = $this->getUser();
|
||||
|
@ -96,7 +98,7 @@ class UserSettingsController extends AbstractController
|
|||
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
|
||||
|
||||
if (! $user instanceof User) {
|
||||
throw new \RuntimeException('This controller only works only for Part-DB User objects!');
|
||||
throw new RuntimeException('This controller only works only for Part-DB User objects!');
|
||||
}
|
||||
|
||||
if ($this->isCsrfTokenValid('delete'.$user->getId(), $request->request->get('_token'))) {
|
||||
|
@ -108,14 +110,14 @@ class UserSettingsController extends AbstractController
|
|||
if (null === $u2f) {
|
||||
$this->addFlash('danger', 'tfa_u2f.u2f_delete.not_existing');
|
||||
|
||||
throw new \RuntimeException('Key not existing!');
|
||||
throw new RuntimeException('Key not existing!');
|
||||
}
|
||||
|
||||
//User can only delete its own U2F keys
|
||||
if ($u2f->getUser() !== $user) {
|
||||
$this->addFlash('danger', 'tfa_u2f.u2f_delete.access_denied');
|
||||
|
||||
throw new \RuntimeException('You can only delete your own U2F keys!');
|
||||
throw new RuntimeException('You can only delete your own U2F keys!');
|
||||
}
|
||||
|
||||
$backupCodeManager->disableBackupCodesIfUnused($user);
|
||||
|
@ -136,7 +138,7 @@ class UserSettingsController extends AbstractController
|
|||
public function resetTrustedDevices(Request $request, EntityManagerInterface $entityManager)
|
||||
{
|
||||
if ($this->demo_mode) {
|
||||
throw new \RuntimeException('You can not do 2FA things in demo mode');
|
||||
throw new RuntimeException('You can not do 2FA things in demo mode');
|
||||
}
|
||||
|
||||
$user = $this->getUser();
|
||||
|
@ -145,7 +147,7 @@ class UserSettingsController extends AbstractController
|
|||
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
|
||||
|
||||
if (! $user instanceof User) {
|
||||
return new \RuntimeException('This controller only works only for Part-DB User objects!');
|
||||
return new RuntimeException('This controller only works only for Part-DB User objects!');
|
||||
}
|
||||
|
||||
if ($this->isCsrfTokenValid('devices_reset'.$user->getId(), $request->request->get('_token'))) {
|
||||
|
@ -173,7 +175,7 @@ class UserSettingsController extends AbstractController
|
|||
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
|
||||
|
||||
if (! $user instanceof User) {
|
||||
throw new \RuntimeException('This controller only works only for Part-DB User objects!');
|
||||
throw new RuntimeException('This controller only works only for Part-DB User objects!');
|
||||
}
|
||||
|
||||
/***************************
|
||||
|
@ -202,23 +204,36 @@ class UserSettingsController extends AbstractController
|
|||
//Username field for autocomplete
|
||||
->add('username', TextType::class, [
|
||||
'data' => $user->getName(),
|
||||
'attr' => ['autocomplete' => 'username'],
|
||||
'attr' => [
|
||||
'autocomplete' => 'username',
|
||||
],
|
||||
'disabled' => true,
|
||||
'row_attr' => ['class' => 'd-none'],
|
||||
'row_attr' => [
|
||||
'class' => 'd-none',
|
||||
],
|
||||
])
|
||||
->add('old_password', PasswordType::class, [
|
||||
'label' => 'user.settings.pw_old.label',
|
||||
'disabled' => $this->demo_mode,
|
||||
'attr' => ['autocomplete' => 'current-password'],
|
||||
'constraints' => [new UserPassword()], ]) //This constraint checks, if the current user pw was inputted.
|
||||
'attr' => [
|
||||
'autocomplete' => 'current-password',
|
||||
],
|
||||
'constraints' => [new UserPassword()],
|
||||
]) //This constraint checks, if the current user pw was inputted.
|
||||
->add('new_password', RepeatedType::class, [
|
||||
'disabled' => $this->demo_mode,
|
||||
'type' => PasswordType::class,
|
||||
'first_options' => ['label' => 'user.settings.pw_new.label'],
|
||||
'second_options' => ['label' => 'user.settings.pw_confirm.label'],
|
||||
'first_options' => [
|
||||
'label' => 'user.settings.pw_new.label',
|
||||
],
|
||||
'second_options' => [
|
||||
'label' => 'user.settings.pw_confirm.label',
|
||||
],
|
||||
'invalid_message' => 'password_must_match',
|
||||
'options' => [
|
||||
'attr' => ['autocomplete' => 'new-password'],
|
||||
'attr' => [
|
||||
'autocomplete' => 'new-password',
|
||||
],
|
||||
],
|
||||
'constraints' => [new Length([
|
||||
'min' => 6,
|
||||
|
@ -276,7 +291,9 @@ class UserSettingsController extends AbstractController
|
|||
|
||||
$backup_form = $this->get('form.factory')->createNamedBuilder('backup_codes')->add('reset_codes', SubmitType::class, [
|
||||
'label' => 'tfa_backup.regenerate_codes',
|
||||
'attr' => ['class' => 'btn-danger'],
|
||||
'attr' => [
|
||||
'class' => 'btn-danger',
|
||||
],
|
||||
'disabled' => empty($user->getBackupCodes()),
|
||||
])->getForm();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue