1010namespace OxidEsales \SecurityModule \Authentication \TwoFactorAuth \Infrastructure \Repository ;
1111
1212use DateTime ;
13+ use DateTimeImmutable ;
1314use Doctrine \DBAL \Result ;
1415use OxidEsales \EshopCommunity \Internal \Framework \Database \QueryBuilderFactoryInterface ;
16+ use OxidEsales \SecurityModule \Authentication \TwoFactorAuth \DTO \UserInterface ;
1517use OxidEsales \SecurityModule \Authentication \TwoFactorAuth \DTO \User as UserDTO ;
1618use OxidEsales \SecurityModule \Authentication \TwoFactorAuth \Exception \UserNotFoundException ;
1719use OxidEsales \SecurityModule \Authentication \TwoFactorAuth \Infrastructure \Factory \UserFactoryInterface ;
@@ -24,14 +26,15 @@ public function __construct(
2426 ) {
2527 }
2628
27- public function getUserOTPData (string $ userName ): UserDTO
29+ public function getUserOTPData (string $ userName ): UserInterface
2830 {
2931 $ builder = $ this ->queryBuilderFactory ->create ();
3032 $ builder ->select ([
3133 'OXID ' ,
3234 'OESMOTPCODE ' ,
3335 'OESMOTPATTEMPTS ' ,
34- 'OESMOTPEXPTIME '
36+ 'OESMOTPEXPTIME ' ,
37+ 'OESMOTPLASTSENT ' ,
3538 ])
3639 ->from ('oxuser ' )
3740 ->where ('oxusername = :userName ' )
@@ -48,7 +51,8 @@ public function getUserOTPData(string $userName): UserDTO
4851 $ userData ['OXID ' ],
4952 $ userData ['OESMOTPATTEMPTS ' ],
5053 $ userData ['OESMOTPCODE ' ],
51- $ userData ['OESMOTPEXPTIME ' ] ? new DateTime ($ userData ['OESMOTPEXPTIME ' ]) : null
54+ $ userData ['OESMOTPEXPTIME ' ] ? new DateTime ($ userData ['OESMOTPEXPTIME ' ]) : null ,
55+ $ userData ['OESMOTPLASTSENT ' ] ? new DateTime ($ userData ['OESMOTPLASTSENT ' ]) : null ,
5256 );
5357 }
5458
@@ -81,9 +85,10 @@ public function resetCodeFields(string $userId): void
8185 $ userModel = $ this ->userFactory ->create ();
8286 $ userModel ->load ($ userId );
8387 $ userModel ->assign ([
84- 'OESMOTPCODE ' => '' ,
85- 'OESMOTPEXPTIME ' => 0 ,
88+ 'OESMOTPCODE ' => null ,
89+ 'OESMOTPEXPTIME ' => null ,
8690 'OESMOTPATTEMPTS ' => 0 ,
91+ 'OESMOTPLASTSENT ' => null ,
8792 ]);
8893 $ userModel ->save ();
8994 }
@@ -102,4 +107,14 @@ public function getUserPasswordHash(string $userName): ?string
102107
103108 return $ userPass ?: null ;
104109 }
110+
111+ public function markOtpAsSent (string $ userId ): void
112+ {
113+ $ userModel = $ this ->userFactory ->create ();
114+ $ userModel ->load ($ userId );
115+ $ userModel ->assign ([
116+ 'OESMOTPLASTSENT ' => (new DateTimeImmutable ())->format ('Y-m-d H:i:s ' )
117+ ]);
118+ $ userModel ->save ();
119+ }
105120}
0 commit comments