From 4a63ec1e337a8a41f5d6ed98ad34a34212157274 Mon Sep 17 00:00:00 2001 From: Robert Baruck Date: Mon, 12 Aug 2024 15:09:36 +0200 Subject: [PATCH 1/3] FEATURE: Add creationDate to SecondFactor and ordering to second factor list in backend --- Classes/Domain/Model/SecondFactor.php | 16 ++++++++ .../Repository/SecondFactorRepository.php | 6 +++ Migrations/Mysql/Version20240812091514.php | 41 +++++++++++++++++++ .../Components/SecondFactorList.fusion | 2 + Resources/Private/Translations/de/Backend.xlf | 4 ++ Resources/Private/Translations/en/Backend.xlf | 3 ++ 6 files changed, 72 insertions(+) create mode 100644 Migrations/Mysql/Version20240812091514.php diff --git a/Classes/Domain/Model/SecondFactor.php b/Classes/Domain/Model/SecondFactor.php index 036cf86..150366a 100644 --- a/Classes/Domain/Model/SecondFactor.php +++ b/Classes/Domain/Model/SecondFactor.php @@ -38,6 +38,12 @@ class SecondFactor */ protected string $secret; + /** + * @var \DateTime + * @ORM\Column(type="datetime", nullable=false) + */ + protected \DateTime $creationDate; + /** * @return Account */ @@ -94,6 +100,16 @@ public function setSecret(string $secret): void $this->secret = $secret; } + public function getCreationDate(): \DateTime + { + return $this->creationDate; + } + + public function setCreationDate(\DateTime $creationDate): void + { + $this->creationDate = $creationDate; + } + public function __toString(): string { return $this->account->getAccountIdentifier() . " with " . self::typeToString($this->type); diff --git a/Classes/Domain/Repository/SecondFactorRepository.php b/Classes/Domain/Repository/SecondFactorRepository.php index b166d21..da3b984 100644 --- a/Classes/Domain/Repository/SecondFactorRepository.php +++ b/Classes/Domain/Repository/SecondFactorRepository.php @@ -16,6 +16,11 @@ */ class SecondFactorRepository extends Repository { + protected $defaultOrderings = [ + 'account' => 'DESC', + 'creationDate' => 'DESC' + ]; + /** * @throws IllegalObjectTypeException */ @@ -25,6 +30,7 @@ public function createSecondFactorForAccount(string $secret, Account $account): $secondFactor->setAccount($account); $secondFactor->setSecret($secret); $secondFactor->setType(SecondFactor::TYPE_TOTP); + $secondFactor->setCreationDate(new \DateTime()); $this->add($secondFactor); $this->persistenceManager->persistAll(); } diff --git a/Migrations/Mysql/Version20240812091514.php b/Migrations/Mysql/Version20240812091514.php new file mode 100644 index 0000000..79fa08e --- /dev/null +++ b/Migrations/Mysql/Version20240812091514.php @@ -0,0 +1,41 @@ +abortIf( + !$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\MySqlPlatform, + "Migration can only be executed safely on '\Doctrine\DBAL\Platforms\MySqlPlatform,'." + ); + + $this->addSql('ALTER TABLE sandstorm_neostwofactorauthentication_domain_model_secondfactor ADD creationdate DATETIME NOT NULL'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->abortIf( + !$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\MySqlPlatform, + "Migration can only be executed safely on '\Doctrine\DBAL\Platforms\MySqlPlatform,'." + ); + + $this->addSql('ALTER TABLE sandstorm_neostwofactorauthentication_domain_model_secondfactor DROP creationdate'); + } +} diff --git a/Resources/Private/Fusion/Presentation/Components/SecondFactorList.fusion b/Resources/Private/Fusion/Presentation/Components/SecondFactorList.fusion index 6c2e3b9..4e1c17f 100644 --- a/Resources/Private/Fusion/Presentation/Components/SecondFactorList.fusion +++ b/Resources/Private/Fusion/Presentation/Components/SecondFactorList.fusion @@ -7,6 +7,7 @@ prototype(Sandstorm.NeosTwoFactorAuthentication:Component.SecondFactorList) < pr {I18n.id('module.index.list.header.name').package('Sandstorm.NeosTwoFactorAuthentication').source('Backend').translate()} {I18n.id('module.index.list.header.type').package('Sandstorm.NeosTwoFactorAuthentication').source('Backend').translate()} + {I18n.id('module.index.list.header.creationDate').package('Sandstorm.NeosTwoFactorAuthentication').source('Backend').translate()}   @@ -42,6 +43,7 @@ prototype(Sandstorm.NeosTwoFactorAuthentication:Component.SecondFactorList.Entry {props.factorAndPerson.user.name.fullName} ({props.factorAndPerson.secondFactor.account.accountIdentifier}) {props.factorAndPerson.secondFactor.typeAsName} + {Date.format(props.factorAndPerson.secondFactor.creationDate, 'U') < 0 ? '-' : Date.format(props.factorAndPerson.secondFactor.creationDate, 'Y-m-d H:i')}