diff --git a/migrations/Version20250413133131.php b/migrations/Version20250413133131.php new file mode 100644 index 000000000..4e805db07 --- /dev/null +++ b/migrations/Version20250413133131.php @@ -0,0 +1,32 @@ +getTable($this->getTable('user')); + + $this->skipIf($userTable->hasColumn('googleauthenticator'), 'It seems that you already played this migration.'); + + $userTable->addColumn('googleauthenticator', 'boolean', [ + 'default' => false, + 'notnull' => false, + ]); + } + + public function down(Schema $schema): void + { + $userTable = $schema->getTable($this->getTable('user')); + $userTable->dropColumn('googleauthenticator'); + } +} diff --git a/src/Controller/ConfigController.php b/src/Controller/ConfigController.php index 39b4e48ad..3224f8eed 100644 --- a/src/Controller/ConfigController.php +++ b/src/Controller/ConfigController.php @@ -312,7 +312,8 @@ class ConfigController extends AbstractController $user = $this->getUser(); - $user->setGoogleAuthenticatorSecret(''); + $user->setGoogleAuthenticatorSecret(null); + $user->setGoogleAuthenticator(false); $user->setBackupCodes(null); $this->userManager->updateUser($user); @@ -408,6 +409,9 @@ class ConfigController extends AbstractController 'notice', 'flashes.config.notice.otp_enabled' ); + $user->setGoogleAuthenticator(true); + $this->userManager->updateUser($user); + $this->entityManager->flush(); return $this->redirect($this->generateUrl('config') . '#set3'); } diff --git a/src/Entity/User.php b/src/Entity/User.php index fc48d8737..98d02e63e 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -147,6 +147,9 @@ class User extends BaseUser implements EmailTwoFactorInterface, GoogleTwoFactorI #[ORM\Column(name: 'googleAuthenticatorSecret', type: 'string', nullable: true)] private $googleAuthenticatorSecret; + #[ORM\Column(name: 'googleAuthenticator', type: 'boolean')] + private $googleAuthenticator; + /** * @var array */ @@ -264,6 +267,14 @@ class User extends BaseUser implements EmailTwoFactorInterface, GoogleTwoFactorI $this->emailTwoFactor = $emailTwoFactor; } + /** + * @param bool $googleAuthenticator + */ + public function setGoogleAuthenticator(bool $googleAuthenticator): void + { + $this->googleAuthenticator = $googleAuthenticator; + } + /** * Used in the user config form to be "like" the email option. */ @@ -294,7 +305,7 @@ class User extends BaseUser implements EmailTwoFactorInterface, GoogleTwoFactorI public function isGoogleAuthenticatorEnabled(): bool { - return $this->googleAuthenticatorSecret ? true : false; + return $this->googleAuthenticator; } public function getGoogleAuthenticatorUsername(): string