77use CodedMonkey \Dirigent \Form \AccountFormType ;
88use CodedMonkey \Dirigent \Form \ChangePasswordFormType ;
99use EasyCorp \Bundle \EasyAdminBundle \Router \AdminUrlGenerator ;
10+ use Scheb \TwoFactorBundle \Security \TwoFactor \Provider \Totp \TotpAuthenticatorInterface ;
1011use Symfony \Bundle \FrameworkBundle \Controller \AbstractController ;
1112use Symfony \Component \Form \FormError ;
1213use Symfony \Component \HttpFoundation \Request ;
@@ -28,6 +29,7 @@ public static function getSubscribedServices(): array
2829 public function __construct (
2930 private readonly UserRepository $ userRepository ,
3031 private readonly UserPasswordHasherInterface $ passwordHasher ,
32+ private readonly TotpAuthenticatorInterface $ totpAuthenticator ,
3133 ) {
3234 }
3335
@@ -36,8 +38,6 @@ public function __construct(
3638 public function account (Request $ request , #[CurrentUser] User $ user ): Response
3739 {
3840 $ accountForm = $ this ->createForm (AccountFormType::class, $ user );
39- $ passwordForm = $ this ->createForm (ChangePasswordFormType::class);
40-
4141 $ accountForm ->handleRequest ($ request );
4242
4343 if ($ accountForm ->isSubmitted () && $ accountForm ->isValid ()) {
@@ -50,6 +50,7 @@ public function account(Request $request, #[CurrentUser] User $user): Response
5050 return $ this ->redirect ($ url );
5151 }
5252
53+ $ passwordForm = $ this ->createForm (ChangePasswordFormType::class);
5354 $ passwordForm ->handleRequest ($ request );
5455
5556 if ($ passwordForm ->isSubmitted ()) {
@@ -72,9 +73,17 @@ public function account(Request $request, #[CurrentUser] User $user): Response
7273 }
7374 }
7475
76+ $ totpSecret = $ this ->totpAuthenticator ->generateSecret ();
77+
78+ $ mfaForm = $ this ->createForm (MfaFormType::class, ['secret ' => $ totpSecret ]);
79+ $ mfaForm ->handleRequest ($ request );
80+
81+ $ oneTimePassword = $ this ->totpAuthenticator ->checkCode ()
82+
7583 return $ this ->render ('dashboard/account.html.twig ' , [
7684 'accountForm ' => $ accountForm ,
7785 'passwordForm ' => $ passwordForm ,
86+ 'totpSecret ' => $ totpSecret ,
7887 ]);
7988 }
8089}
0 commit comments