mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-27 04:08:57 +02:00
Fixed code style.
This commit is contained in:
parent
1aed1d1d26
commit
9a7223a301
142 changed files with 534 additions and 716 deletions
|
@ -40,7 +40,6 @@ class AttachmentFileController extends AbstractController
|
|||
* @Route("/attachment/{id}/download", name="attachment_download")
|
||||
*
|
||||
* @return BinaryFileResponse
|
||||
*
|
||||
*/
|
||||
public function download(Attachment $attachment, AttachmentManager $helper)
|
||||
{
|
||||
|
|
|
@ -151,7 +151,7 @@ class PartController extends AbstractController
|
|||
$cid = $request->get('cid', 1);
|
||||
|
||||
$category = $em->find(Category::class, $cid);
|
||||
if($category !== null) {
|
||||
if (null !== $category) {
|
||||
$new_part->setCategory($category);
|
||||
}
|
||||
|
||||
|
|
|
@ -80,7 +80,7 @@ class SecurityController extends AbstractController
|
|||
$builder = $this->createFormBuilder();
|
||||
$builder->add('user', TextType::class, [
|
||||
'label' => $this->translator->trans('pw_reset.user_or_email'),
|
||||
'constraints' => [new NotBlank()]
|
||||
'constraints' => [new NotBlank()],
|
||||
]);
|
||||
$builder->add('captcha', CaptchaType::class, [
|
||||
'width' => 200,
|
||||
|
@ -88,7 +88,7 @@ class SecurityController extends AbstractController
|
|||
'length' => 6,
|
||||
]);
|
||||
$builder->add('submit', SubmitType::class, [
|
||||
'label' => 'pw_reset.submit'
|
||||
'label' => 'pw_reset.submit',
|
||||
]);
|
||||
|
||||
$form = $builder->getForm();
|
||||
|
@ -97,11 +97,12 @@ class SecurityController extends AbstractController
|
|||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$passwordReset->request($form->getData()['user']);
|
||||
$this->addFlash('success', 'pw_reset.request.success');
|
||||
|
||||
return $this->redirectToRoute('login');
|
||||
}
|
||||
|
||||
return $this->render('security/pw_reset_request.html.twig', [
|
||||
'form' => $form->createView()
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -121,10 +122,10 @@ class SecurityController extends AbstractController
|
|||
$data = ['username' => $user, 'token' => $token];
|
||||
$builder = $this->createFormBuilder($data);
|
||||
$builder->add('username', TextType::class, [
|
||||
'label' => $this->translator->trans('pw_reset.username')
|
||||
'label' => $this->translator->trans('pw_reset.username'),
|
||||
]);
|
||||
$builder->add('token', TextType::class, [
|
||||
'label' => $this->translator->trans('pw_reset.token')
|
||||
'label' => $this->translator->trans('pw_reset.token'),
|
||||
]);
|
||||
$builder->add('new_password', RepeatedType::class, [
|
||||
'type' => PasswordType::class,
|
||||
|
@ -138,7 +139,7 @@ class SecurityController extends AbstractController
|
|||
]);
|
||||
|
||||
$builder->add('submit', SubmitType::class, [
|
||||
'label' => 'pw_reset.submit'
|
||||
'label' => 'pw_reset.submit',
|
||||
]);
|
||||
|
||||
$form = $builder->getForm();
|
||||
|
@ -152,13 +153,13 @@ class SecurityController extends AbstractController
|
|||
$this->addFlash('error', 'pw_reset.new_pw.error');
|
||||
} else {
|
||||
$this->addFlash('success', 'pw_reset.new_pw.success');
|
||||
|
||||
return $this->redirectToRoute('login');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $this->render('security/pw_reset_new_pw.html.twig', [
|
||||
'form' => $form->createView()
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@ use Symfony\Component\Routing\Annotation\Route;
|
|||
|
||||
/**
|
||||
* This controller has the purpose to provide the data for all treeviews.
|
||||
*
|
||||
* @Route("/tree")
|
||||
*/
|
||||
class TreeController extends AbstractController
|
||||
|
@ -52,6 +53,7 @@ class TreeController extends AbstractController
|
|||
public function tools(ToolsTreeBuilder $builder)
|
||||
{
|
||||
$tree = $builder->getTree();
|
||||
|
||||
return new JsonResponse($tree);
|
||||
}
|
||||
|
||||
|
@ -62,6 +64,7 @@ class TreeController extends AbstractController
|
|||
public function categoryTree(Category $category = null)
|
||||
{
|
||||
$tree = $this->treeGenerator->getTreeView(Category::class, $category);
|
||||
|
||||
return new JsonResponse($tree);
|
||||
}
|
||||
|
||||
|
@ -72,6 +75,7 @@ class TreeController extends AbstractController
|
|||
public function footprintTree(Footprint $footprint = null)
|
||||
{
|
||||
$tree = $this->treeGenerator->getTreeView(Footprint::class, $footprint);
|
||||
|
||||
return new JsonResponse($tree);
|
||||
}
|
||||
|
||||
|
@ -82,6 +86,7 @@ class TreeController extends AbstractController
|
|||
public function locationTree(Storelocation $location = null)
|
||||
{
|
||||
$tree = $this->treeGenerator->getTreeView(Storelocation::class, $location);
|
||||
|
||||
return new JsonResponse($tree);
|
||||
}
|
||||
|
||||
|
@ -92,6 +97,7 @@ class TreeController extends AbstractController
|
|||
public function manufacturerTree(Manufacturer $manufacturer = null)
|
||||
{
|
||||
$tree = $this->treeGenerator->getTreeView(Manufacturer::class, $manufacturer);
|
||||
|
||||
return new JsonResponse($tree);
|
||||
}
|
||||
|
||||
|
@ -102,6 +108,7 @@ class TreeController extends AbstractController
|
|||
public function supplierTree(Supplier $supplier = null)
|
||||
{
|
||||
$tree = $this->treeGenerator->getTreeView(Supplier::class, $supplier);
|
||||
|
||||
return new JsonResponse($tree);
|
||||
}
|
||||
|
||||
|
@ -112,6 +119,7 @@ class TreeController extends AbstractController
|
|||
public function deviceTree(Device $device = null)
|
||||
{
|
||||
$tree = $this->treeGenerator->getTreeView(Device::class, $device, '');
|
||||
|
||||
return new JsonResponse($tree);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ class UserController extends AdminPages\BaseAdminController
|
|||
{
|
||||
//Handle 2FA disabling
|
||||
|
||||
if($request->request->has('reset_2fa')) {
|
||||
if ($request->request->has('reset_2fa')) {
|
||||
//Check if the admin has the needed permissions
|
||||
$this->denyAccessUnlessGranted('set_password', $entity);
|
||||
if ($this->isCsrfTokenValid('reset_2fa'.$entity->getId(), $request->request->get('_token'))) {
|
||||
|
@ -64,7 +64,7 @@ class UserController extends AdminPages\BaseAdminController
|
|||
$entity->setGoogleAuthenticatorSecret(null);
|
||||
$entity->setBackupCodes([]);
|
||||
//Remove all U2F keys
|
||||
foreach($entity->getU2FKeys() as $key) {
|
||||
foreach ($entity->getU2FKeys() as $key) {
|
||||
$em->remove($key);
|
||||
}
|
||||
//Invalidate trusted devices
|
||||
|
@ -136,7 +136,6 @@ class UserController extends AdminPages\BaseAdminController
|
|||
//If no user id was passed, then we show info about the current user
|
||||
if (null === $user) {
|
||||
$user = $this->getUser();
|
||||
|
||||
} else {
|
||||
//Else we must check, if the current user is allowed to access $user
|
||||
$this->denyAccessUnlessGranted('read', $user);
|
||||
|
|
|
@ -21,14 +21,12 @@
|
|||
|
||||
namespace App\Controller;
|
||||
|
||||
|
||||
use App\Entity\UserSystem\U2FKey;
|
||||
use App\Entity\UserSystem\User;
|
||||
use App\Form\TFAGoogleSettingsType;
|
||||
use App\Form\UserSettingsType;
|
||||
use App\Services\TFA\BackupCodeManager;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Exception;
|
||||
use Scheb\TwoFactorBundle\Security\TwoFactor\Provider\Google\GoogleAuthenticator;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
|
||||
|
@ -43,7 +41,6 @@ use Symfony\Component\Validator\Constraints\Length;
|
|||
|
||||
/**
|
||||
* @Route("/user")
|
||||
* @package App\Controller
|
||||
*/
|
||||
class UserSettingsController extends AbstractController
|
||||
{
|
||||
|
@ -74,7 +71,7 @@ class UserSettingsController extends AbstractController
|
|||
}
|
||||
|
||||
return $this->render('Users/backup_codes.html.twig', [
|
||||
'user' => $user
|
||||
'user' => $user,
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -85,7 +82,7 @@ class UserSettingsController extends AbstractController
|
|||
*/
|
||||
public function removeU2FToken(Request $request, EntityManagerInterface $entityManager, BackupCodeManager $backupCodeManager)
|
||||
{
|
||||
if($this->demo_mode) {
|
||||
if ($this->demo_mode) {
|
||||
throw new \RuntimeException('You can not do 2FA things in demo mode');
|
||||
}
|
||||
|
||||
|
@ -98,15 +95,14 @@ class UserSettingsController extends AbstractController
|
|||
throw new \RuntimeException('This controller only works only for Part-DB User objects!');
|
||||
}
|
||||
|
||||
|
||||
if ($this->isCsrfTokenValid('delete'.$user->getId(), $request->request->get('_token'))) {
|
||||
if($request->request->has('key_id')) {
|
||||
if ($request->request->has('key_id')) {
|
||||
$key_id = $request->request->get('key_id');
|
||||
$key_repo = $entityManager->getRepository(U2FKey::class);
|
||||
/** @var U2FKey|null $u2f */
|
||||
$u2f = $key_repo->find($key_id);
|
||||
if($u2f === null) {
|
||||
$this->addFlash('danger','tfa_u2f.u2f_delete.not_existing');
|
||||
if (null === $u2f) {
|
||||
$this->addFlash('danger', 'tfa_u2f.u2f_delete.not_existing');
|
||||
throw new \RuntimeException('Key not existing!');
|
||||
}
|
||||
|
||||
|
@ -122,7 +118,7 @@ class UserSettingsController extends AbstractController
|
|||
$this->addFlash('success', 'tfa.u2f.u2f_delete.success');
|
||||
}
|
||||
} else {
|
||||
$this->addFlash('error','csfr_invalid');
|
||||
$this->addFlash('error', 'csfr_invalid');
|
||||
}
|
||||
|
||||
return $this->redirectToRoute('user_settings');
|
||||
|
@ -133,7 +129,7 @@ class UserSettingsController extends AbstractController
|
|||
*/
|
||||
public function resetTrustedDevices(Request $request, EntityManagerInterface $entityManager)
|
||||
{
|
||||
if($this->demo_mode) {
|
||||
if ($this->demo_mode) {
|
||||
throw new \RuntimeException('You can not do 2FA things in demo mode');
|
||||
}
|
||||
|
||||
|
@ -146,13 +142,12 @@ class UserSettingsController extends AbstractController
|
|||
return new \RuntimeException('This controller only works only for Part-DB User objects!');
|
||||
}
|
||||
|
||||
|
||||
if ($this->isCsrfTokenValid('devices_reset'.$user->getId(), $request->request->get('_token'))) {
|
||||
$user->invalidateTrustedDeviceTokens();
|
||||
$entityManager->flush();
|
||||
$this->addFlash('success', 'tfa_trustedDevice.invalidate.success');
|
||||
} else {
|
||||
$this->addFlash('error','csfr_invalid');
|
||||
$this->addFlash('error', 'csfr_invalid');
|
||||
}
|
||||
|
||||
return $this->redirectToRoute('user_settings');
|
||||
|
@ -205,7 +200,7 @@ class UserSettingsController extends AbstractController
|
|||
'data' => $user->getName(),
|
||||
'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',
|
||||
|
@ -219,7 +214,7 @@ class UserSettingsController extends AbstractController
|
|||
'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,
|
||||
|
@ -260,6 +255,7 @@ class UserSettingsController extends AbstractController
|
|||
$backupCodeManager->enableBackupCodes($user);
|
||||
$em->flush();
|
||||
$this->addFlash('success', 'user.settings.2fa.google.activated');
|
||||
|
||||
return $this->redirectToRoute('user_settings');
|
||||
}
|
||||
|
||||
|
@ -269,14 +265,15 @@ class UserSettingsController extends AbstractController
|
|||
$backupCodeManager->disableBackupCodesIfUnused($user);
|
||||
$em->flush();
|
||||
$this->addFlash('success', 'user.settings.2fa.google.disabled');
|
||||
|
||||
return $this->redirectToRoute('user_settings');
|
||||
}
|
||||
}
|
||||
|
||||
$backup_form = $this->get('form.factory')->createNamedBuilder('backup_codes')->add('reset_codes', SubmitType::class,[
|
||||
$backup_form = $this->get('form.factory')->createNamedBuilder('backup_codes')->add('reset_codes', SubmitType::class, [
|
||||
'label' => 'tfa_backup.regenerate_codes',
|
||||
'attr' => ['class' => 'btn-danger'],
|
||||
'disabled' => empty($user->getBackupCodes())
|
||||
'disabled' => empty($user->getBackupCodes()),
|
||||
])->getForm();
|
||||
|
||||
$backup_form->handleRequest($request);
|
||||
|
@ -286,7 +283,6 @@ class UserSettingsController extends AbstractController
|
|||
$this->addFlash('success', 'user.settings.2fa.backup_codes.regenerated');
|
||||
}
|
||||
|
||||
|
||||
/******************************
|
||||
* Output both forms
|
||||
*****************************/
|
||||
|
@ -303,8 +299,8 @@ class UserSettingsController extends AbstractController
|
|||
'enabled' => $google_enabled,
|
||||
'qrContent' => $googleAuthenticator->getQRContent($user),
|
||||
'secret' => $user->getGoogleAuthenticatorSecret(),
|
||||
'username' => $user->getGoogleAuthenticatorUsername()
|
||||
]
|
||||
'username' => $user->getGoogleAuthenticatorUsername(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue