Skip to content

Commit 3e3d492

Browse files
authored
Merge pull request #34 from sandstorm/feature/add-creation-date-to-second-factor-and-default-sorting-in-backend-module
2 parents c5c4792 + 0b2458c commit 3e3d492

File tree

6 files changed

+76
-0
lines changed

6 files changed

+76
-0
lines changed

Classes/Domain/Model/SecondFactor.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Sandstorm\NeosTwoFactorAuthentication\Domain\Model;
44

5+
use DateTime;
56
use Neos\Flow\Http\InvalidArgumentException;
67
use Neos\Flow\Security\Account;
78
use Doctrine\ORM\Mapping as ORM;
@@ -38,6 +39,15 @@ class SecondFactor
3839
*/
3940
protected string $secret;
4041

42+
/**
43+
* Introduced with version 1.4.0
44+
* Nullable for backwards compatibility. Null values will be shown as '-' in backend module.
45+
*
46+
* @var DateTime|null
47+
* @ORM\Column(type="datetime", nullable=true)
48+
*/
49+
protected DateTime|null $creationDate;
50+
4151
/**
4252
* @return Account
4353
*/
@@ -94,6 +104,16 @@ public function setSecret(string $secret): void
94104
$this->secret = $secret;
95105
}
96106

107+
public function getCreationDate(): DateTime|null
108+
{
109+
return $this->creationDate;
110+
}
111+
112+
public function setCreationDate(DateTime $creationDate): void
113+
{
114+
$this->creationDate = $creationDate;
115+
}
116+
97117
public function __toString(): string
98118
{
99119
return $this->account->getAccountIdentifier() . " with " . self::typeToString($this->type);

Classes/Domain/Repository/SecondFactorRepository.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
*/
1717
class SecondFactorRepository extends Repository
1818
{
19+
protected $defaultOrderings = [
20+
'account' => 'ASC',
21+
'creationDate' => 'DESC'
22+
];
23+
1924
/**
2025
* @throws IllegalObjectTypeException
2126
*/
@@ -25,6 +30,7 @@ public function createSecondFactorForAccount(string $secret, Account $account):
2530
$secondFactor->setAccount($account);
2631
$secondFactor->setSecret($secret);
2732
$secondFactor->setType(SecondFactor::TYPE_TOTP);
33+
$secondFactor->setCreationDate(new \DateTime());
2834
$this->add($secondFactor);
2935
$this->persistenceManager->persistAll();
3036
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Neos\Flow\Persistence\Doctrine\Migrations;
6+
7+
use Doctrine\DBAL\Schema\Schema;
8+
use Doctrine\Migrations\AbstractMigration;
9+
10+
/**
11+
* Auto-generated Migration: Please modify to your needs!
12+
*/
13+
final class Version20240812091514 extends AbstractMigration
14+
{
15+
public function getDescription(): string
16+
{
17+
return '';
18+
}
19+
20+
public function up(Schema $schema): void
21+
{
22+
// this up() migration is auto-generated, please modify it to your needs
23+
$this->abortIf(
24+
!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\MySqlPlatform,
25+
"Migration can only be executed safely on '\Doctrine\DBAL\Platforms\MySqlPlatform,'."
26+
);
27+
28+
$this->addSql('ALTER TABLE sandstorm_neostwofactorauthentication_domain_model_secondfactor ADD creationdate DATETIME DEFAULT NULL');
29+
}
30+
31+
public function down(Schema $schema): void
32+
{
33+
// this down() migration is auto-generated, please modify it to your needs
34+
$this->abortIf(
35+
!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\MySqlPlatform,
36+
"Migration can only be executed safely on '\Doctrine\DBAL\Platforms\MySqlPlatform,'."
37+
);
38+
39+
$this->addSql('ALTER TABLE sandstorm_neostwofactorauthentication_domain_model_secondfactor DROP creationdate');
40+
}
41+
}

Resources/Private/Fusion/Presentation/Components/SecondFactorList.fusion

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ prototype(Sandstorm.NeosTwoFactorAuthentication:Component.SecondFactorList) < pr
77
<tr>
88
<th>{I18n.id('module.index.list.header.name').package('Sandstorm.NeosTwoFactorAuthentication').source('Backend').translate()}</th>
99
<th>{I18n.id('module.index.list.header.type').package('Sandstorm.NeosTwoFactorAuthentication').source('Backend').translate()}</th>
10+
<th>{I18n.id('module.index.list.header.creationDate').package('Sandstorm.NeosTwoFactorAuthentication').source('Backend').translate()}</th>
1011
<th>&nbsp;</th>
1112
</tr>
1213
</thead>
@@ -42,6 +43,7 @@ prototype(Sandstorm.NeosTwoFactorAuthentication:Component.SecondFactorList.Entry
4243
<tr>
4344
<td>{props.factorAndPerson.user.name.fullName} ({props.factorAndPerson.secondFactor.account.accountIdentifier})</td>
4445
<td>{props.factorAndPerson.secondFactor.typeAsName}</td>
46+
<td>{props.factorAndPerson.secondFactor.creationDate == null ? '-' : Date.format(props.factorAndPerson.secondFactor.creationDate, 'Y-m-d H:i')}</td>
4547
<td>
4648
<button class="neos-button neos-button-danger" data-toggle="modal"
4749
href={'#user-' + props.iterator.index} title={I18n.id('module.index.list.action.delete').package('Sandstorm.NeosTwoFactorAuthentication').source('Backend').translate()} data-neos-toggle="tooltip">

Resources/Private/Translations/de/Backend.xlf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
<source>Type</source>
2424
<target>Typ</target>
2525
</trans-unit>
26+
<trans-unit id="module.index.list.header.creationDate" xml:space="preserve">
27+
<source>Creation Date</source>
28+
<target>Erstellungsdatum</target>
29+
</trans-unit>
2630
<trans-unit id="module.index.list.action.delete" xml:space="preserve">
2731
<source>Delete second factor</source>
2832
<target>Zweiten Faktor löschen</target>

Resources/Private/Translations/en/Backend.xlf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
<trans-unit id="module.index.list.header.type" xml:space="preserve">
1919
<source>Type</source>
2020
</trans-unit>
21+
<trans-unit id="module.index.list.header.creationDate" xml:space="preserve">
22+
<source>Creation Date</source>
23+
</trans-unit>
2124
<trans-unit id="module.index.list.action.delete" xml:space="preserve">
2225
<source>Delete second factor</source>
2326
</trans-unit>

0 commit comments

Comments
 (0)