@@ -54,7 +54,7 @@ |
||
| 54 | 54 | { |
| 55 | 55 | $user = new User(); |
| 56 | 56 | $user->setGoogleAuthenticatorSecret($secret); |
| 57 | - $this->assertSame($expected ,$user->isGoogleAuthenticatorEnabled()); |
|
| 57 | + $this->assertSame($expected, $user->isGoogleAuthenticatorEnabled()); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | /** |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | { |
| 70 | 70 | //Handle 2FA disabling |
| 71 | 71 | |
| 72 | - if($request->request->has('reset_2fa')) { |
|
| 72 | + if ($request->request->has('reset_2fa')) { |
|
| 73 | 73 | //Check if the admin has the needed permissions |
| 74 | 74 | $this->denyAccessUnlessGranted('set_password', $entity); |
| 75 | 75 | if ($this->isCsrfTokenValid('reset_2fa'.$entity->getId(), $request->request->get('_token'))) { |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | $entity->setGoogleAuthenticatorSecret(null); |
| 78 | 78 | $entity->setBackupCodes([]); |
| 79 | 79 | //Remove all U2F keys |
| 80 | - foreach($entity->getU2FKeys() as $key) { |
|
| 80 | + foreach ($entity->getU2FKeys() as $key) { |
|
| 81 | 81 | $em->remove($key); |
| 82 | 82 | } |
| 83 | 83 | //Invalidate trusted devices |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | */ |
| 86 | 86 | public function removeU2FToken(Request $request, EntityManagerInterface $entityManager, BackupCodeManager $backupCodeManager) |
| 87 | 87 | { |
| 88 | - if($this->demo_mode) { |
|
| 88 | + if ($this->demo_mode) { |
|
| 89 | 89 | throw new \RuntimeException('You can not do 2FA things in demo mode'); |
| 90 | 90 | } |
| 91 | 91 | |
@@ -100,13 +100,13 @@ discard block |
||
| 100 | 100 | |
| 101 | 101 | |
| 102 | 102 | if ($this->isCsrfTokenValid('delete'.$user->getId(), $request->request->get('_token'))) { |
| 103 | - if($request->request->has('key_id')) { |
|
| 103 | + if ($request->request->has('key_id')) { |
|
| 104 | 104 | $key_id = $request->request->get('key_id'); |
| 105 | 105 | $key_repo = $entityManager->getRepository(U2FKey::class); |
| 106 | 106 | /** @var U2FKey|null $u2f */ |
| 107 | 107 | $u2f = $key_repo->find($key_id); |
| 108 | - if($u2f === null) { |
|
| 109 | - $this->addFlash('danger','tfa_u2f.u2f_delete.not_existing'); |
|
| 108 | + if ($u2f === null) { |
|
| 109 | + $this->addFlash('danger', 'tfa_u2f.u2f_delete.not_existing'); |
|
| 110 | 110 | throw new \RuntimeException('Key not existing!'); |
| 111 | 111 | } |
| 112 | 112 | |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | $this->addFlash('success', 'tfa.u2f.u2f_delete.success'); |
| 123 | 123 | } |
| 124 | 124 | } else { |
| 125 | - $this->addFlash('error','csfr_invalid'); |
|
| 125 | + $this->addFlash('error', 'csfr_invalid'); |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | return $this->redirectToRoute('user_settings'); |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | */ |
| 134 | 134 | public function resetTrustedDevices(Request $request, EntityManagerInterface $entityManager) |
| 135 | 135 | { |
| 136 | - if($this->demo_mode) { |
|
| 136 | + if ($this->demo_mode) { |
|
| 137 | 137 | throw new \RuntimeException('You can not do 2FA things in demo mode'); |
| 138 | 138 | } |
| 139 | 139 | |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | $entityManager->flush(); |
| 153 | 153 | $this->addFlash('success', 'tfa_trustedDevice.invalidate.success'); |
| 154 | 154 | } else { |
| 155 | - $this->addFlash('error','csfr_invalid'); |
|
| 155 | + $this->addFlash('error', 'csfr_invalid'); |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | return $this->redirectToRoute('user_settings'); |
@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | } |
| 254 | 254 | $google_form->handleRequest($request); |
| 255 | 255 | |
| 256 | - if($google_form->isSubmitted() && $google_form->isValid() && !$this->demo_mode) { |
|
| 256 | + if ($google_form->isSubmitted() && $google_form->isValid() && !$this->demo_mode) { |
|
| 257 | 257 | if (!$google_enabled) { |
| 258 | 258 | //Save 2FA settings (save secrets) |
| 259 | 259 | $user->setGoogleAuthenticatorSecret($google_form->get('googleAuthenticatorSecret')->getData()); |
@@ -271,7 +271,7 @@ discard block |
||
| 271 | 271 | } |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | - $backup_form = $this->get('form.factory')->createNamedBuilder('backup_codes')->add('reset_codes', SubmitType::class,[ |
|
| 274 | + $backup_form = $this->get('form.factory')->createNamedBuilder('backup_codes')->add('reset_codes', SubmitType::class, [ |
|
| 275 | 275 | 'label' => 'tfa_backup.regenerate_codes', |
| 276 | 276 | 'attr' => ['class' => 'btn-danger'], |
| 277 | 277 | 'disabled' => empty($user->getBackupCodes()) |
@@ -52,7 +52,7 @@ |
||
| 52 | 52 | $user = $event->getData(); |
| 53 | 53 | |
| 54 | 54 | //Only show setup fields, when google authenticator is not enabled |
| 55 | - if(!$user->isGoogleAuthenticatorEnabled()) { |
|
| 55 | + if (!$user->isGoogleAuthenticatorEnabled()) { |
|
| 56 | 56 | $form->add( |
| 57 | 57 | 'google_confirmation', |
| 58 | 58 | TextType::class, |
@@ -58,23 +58,23 @@ |
||
| 58 | 58 | throw new UnexpectedValueException($value, 'string'); |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | - if(!ctype_digit($value)) { |
|
| 61 | + if (!ctype_digit($value)) { |
|
| 62 | 62 | $this->context->addViolation('validator.google_code.only_digits_allowed'); |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | //Number must have 6 digits |
| 66 | - if(strlen($value) !== 6) { |
|
| 66 | + if (strlen($value) !== 6) { |
|
| 67 | 67 | $this->context->addViolation('validator.google_code.wrong_digit_count'); |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | //Try to retrieve the user we want to check |
| 71 | - if($this->context->getObject() instanceof FormInterface && |
|
| 71 | + if ($this->context->getObject() instanceof FormInterface && |
|
| 72 | 72 | $this->context->getObject()->getParent() instanceof FormInterface |
| 73 | 73 | && $this->context->getObject()->getParent()->getData() instanceof User) { |
| 74 | 74 | $user = $this->context->getObject()->getParent()->getData(); |
| 75 | 75 | |
| 76 | 76 | //Check if the given code is valid |
| 77 | - if(!$this->googleAuthenticator->checkCode($user, $value)) { |
|
| 77 | + if (!$this->googleAuthenticator->checkCode($user, $value)) { |
|
| 78 | 78 | $this->context->addViolation('validator.google_code.wrong_code'); |
| 79 | 79 | } |
| 80 | 80 | |
@@ -76,10 +76,10 @@ discard block |
||
| 76 | 76 | $user = $this->security->getUser(); |
| 77 | 77 | $request = $event->getRequest(); |
| 78 | 78 | |
| 79 | - if(!$event->isMasterRequest()) { |
|
| 79 | + if (!$event->isMasterRequest()) { |
|
| 80 | 80 | return; |
| 81 | 81 | } |
| 82 | - if(!$user instanceof User) { |
|
| 82 | + if (!$user instanceof User) { |
|
| 83 | 83 | return; |
| 84 | 84 | } |
| 85 | 85 | |
@@ -98,16 +98,16 @@ discard block |
||
| 98 | 98 | |
| 99 | 99 | /* Dont redirect tree endpoints, as this would cause trouble and creates multiple flash |
| 100 | 100 | warnigs for one page reload */ |
| 101 | - if(strpos($request->getUri(), '/tree/') !== false) { |
|
| 101 | + if (strpos($request->getUri(), '/tree/') !== false) { |
|
| 102 | 102 | return; |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | //Show appropriate message to user about the reason he was redirected |
| 106 | - if($user->isNeedPwChange()) { |
|
| 106 | + if ($user->isNeedPwChange()) { |
|
| 107 | 107 | $this->flashBag->add('warning', 'user.pw_change_needed.flash'); |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - if(static::TFARedirectNeeded($user)) { |
|
| 110 | + if (static::TFARedirectNeeded($user)) { |
|
| 111 | 111 | $this->flashBag->add('warning', 'user.2fa_needed.flash'); |
| 112 | 112 | } |
| 113 | 113 | |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | */ |
| 45 | 45 | public function enableBackupCodes(User $user) |
| 46 | 46 | { |
| 47 | - if(empty($user->getBackupCodes())) { |
|
| 47 | + if (empty($user->getBackupCodes())) { |
|
| 48 | 48 | $this->regenerateBackupCodes($user); |
| 49 | 49 | } |
| 50 | 50 | } |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | */ |
| 56 | 56 | public function disableBackupCodesIfUnused(User $user) |
| 57 | 57 | { |
| 58 | - if($user->isGoogleAuthenticatorEnabled()) { |
|
| 58 | + if ($user->isGoogleAuthenticatorEnabled()) { |
|
| 59 | 59 | return; |
| 60 | 60 | } |
| 61 | 61 | |
@@ -68,7 +68,7 @@ |
||
| 68 | 68 | public function generateCodeSet() : array |
| 69 | 69 | { |
| 70 | 70 | $array = []; |
| 71 | - for($n=0; $n<$this->code_count; $n++) { |
|
| 71 | + for ($n = 0; $n < $this->code_count; $n++) { |
|
| 72 | 72 | $array[] = $this->generateSingleCode(); |
| 73 | 73 | } |
| 74 | 74 | |
@@ -205,8 +205,8 @@ |
||
| 205 | 205 | protected $trustedDeviceCookieVersion = 0; |
| 206 | 206 | |
| 207 | 207 | /** @var Collection<TwoFactorKeyInterface> |
| 208 | - * @ORM\OneToMany(targetEntity="App\Entity\UserSystem\U2FKey", mappedBy="user", cascade={"REMOVE"}, orphanRemoval=true) |
|
| 209 | - */ |
|
| 208 | + * @ORM\OneToMany(targetEntity="App\Entity\UserSystem\U2FKey", mappedBy="user", cascade={"REMOVE"}, orphanRemoval=true) |
|
| 209 | + */ |
|
| 210 | 210 | protected $u2fKeys; |
| 211 | 211 | |
| 212 | 212 | /** |
@@ -754,7 +754,7 @@ discard block |
||
| 754 | 754 | public function invalidateBackupCode(string $code): void |
| 755 | 755 | { |
| 756 | 756 | $key = array_search($code, $this->backupCodes); |
| 757 | - if ($key !== false){ |
|
| 757 | + if ($key !== false) { |
|
| 758 | 758 | unset($this->backupCodes[$key]); |
| 759 | 759 | } |
| 760 | 760 | } |
@@ -776,7 +776,7 @@ discard block |
||
| 776 | 776 | public function setBackupCodes(array $codes) : self |
| 777 | 777 | { |
| 778 | 778 | $this->backupCodes = $codes; |
| 779 | - if(empty($codes)) { |
|
| 779 | + if (empty($codes)) { |
|
| 780 | 780 | $this->backupCodesGenerationDate = null; |
| 781 | 781 | } else { |
| 782 | 782 | $this->backupCodesGenerationDate = new \DateTime(); |
@@ -853,7 +853,7 @@ discard block |
||
| 853 | 853 | public function getPreferredTwoFactorProvider(): ?string |
| 854 | 854 | { |
| 855 | 855 | //If U2F is available then prefer it |
| 856 | - if($this->isU2FAuthEnabled()) { |
|
| 856 | + if ($this->isU2FAuthEnabled()) { |
|
| 857 | 857 | return 'u2f_two_factor'; |
| 858 | 858 | } |
| 859 | 859 | |