Skip to content

Commit 3dd64e8

Browse files
committed
Merge branch 'b-7.4.x-change-oauth-pass-OXDEV-10116' into b-7.4.x-2fa-OXDEV-9078
2 parents 26a1ceb + 89a3075 commit 3dd64e8

18 files changed

Lines changed: 461 additions & 158 deletions

File tree

metadata.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
'email' => 'info@oxid-esales.com',
3535
'extend' => [
3636
\OxidEsales\Eshop\Application\Controller\NewsletterController::class => \OxidEsales\SecurityModule\Captcha\Shop\NewsletterController::class,
37-
\OxidEsales\Eshop\Application\Controller\ForgotPasswordController::class => \OxidEsales\SecurityModule\Captcha\Shop\ForgotPasswordController::class,
37+
\OxidEsales\Eshop\Application\Controller\ForgotPasswordController::class => \OxidEsales\SecurityModule\Shared\Controller\ForgotPasswordController::class,
3838
\OxidEsales\Eshop\Application\Model\User::class => \OxidEsales\SecurityModule\Shared\Model\User::class,
3939
\OxidEsales\Eshop\Core\InputValidator::class => \OxidEsales\SecurityModule\Shared\Core\InputValidator::class,
4040
\OxidEsales\Eshop\Core\ViewConfig::class => \OxidEsales\SecurityModule\Shared\Core\ViewConfig::class

migration/data/Version20251128093245.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public function up(Schema $schema): void
1919
$this->addSql('ALTER TABLE `oxuser` ADD column `OESMOTPCODE` VARCHAR(128) default NULL COMMENT "OTP code"');
2020
$this->addSql('ALTER TABLE `oxuser` ADD column `OESMOTPEXPTIME` DATETIME default NULL COMMENT "OTP code expiration time"');
2121
$this->addSql('ALTER TABLE `oxuser` ADD column `OESMOTPATTEMPTS` INT NOT NULL default 0 COMMENT "OTP code attempts"');
22+
$this->addSql('ALTER TABLE `oxuser` ADD column `OESMOTPLASTSENT` DATETIME default NULL COMMENT "Last OTP sent timestamp"');
23+
$this->addSql('ALTER TABLE `oxuser` ADD column `OESMEXTERNALAUTH` TINYINT(1) NOT NULL default 0 COMMENT "User registered via external authentication"');
2224
}
2325

2426
public function down(Schema $schema): void

migration/data/Version20260114104913.php

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/Authentication/OAuth2/Infrastructure/Repository/UserRepository.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,26 @@ public function getUserByEmail(string $username): UserDTOInterface
3737
return $this->userDTOFactory->createFromModel($userModel);
3838
}
3939

40+
public function removeExternalAuthFlag(string $userId): void
41+
{
42+
$userModel = $this->userFactory->create();
43+
44+
if (!$userModel->load($userId)) {
45+
throw new UserNotFoundException();
46+
}
47+
48+
$userModel->assign(['OESMEXTERNALAUTH' => 0]);
49+
$userModel->save();
50+
}
51+
4052
public function createUser(OAuth2UserDTOInterface $userDTO): UserDTOInterface
4153
{
4254
$userModel = $this->userFactory->create();
4355
$userModel->assign([
44-
'OXFNAME' => $userDTO->getFirstName(),
45-
'OXLNAME' => $userDTO->getLastName(),
46-
'OXUSERNAME' => $userDTO->getEmail(),
56+
'OXFNAME' => $userDTO->getFirstName(),
57+
'OXLNAME' => $userDTO->getLastName(),
58+
'OXUSERNAME' => $userDTO->getEmail(),
59+
'OESMEXTERNALAUTH' => 1,
4760
]);
4861
$userModel->setPassword($this->passwordGenerator->generatePasswordForOAuthUser());
4962
$userModel->createUser();

src/Authentication/OAuth2/Infrastructure/Repository/UserRepositoryInterface.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,10 @@ interface UserRepositoryInterface
1818
*/
1919
public function getUserByEmail(string $username): UserDTOInterface;
2020

21+
/**
22+
* @throws UserNotFoundException
23+
*/
24+
public function removeExternalAuthFlag(string $userId): void;
25+
2126
public function createUser(OAuth2UserDTOInterface $userDTO): UserDTOInterface;
2227
}

src/Authentication/OAuth2/Service/UserService.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,12 @@ public function login(OAuth2UserDTOInterface $auth2UserDTO): void
4242

4343
$this->session->set('usr', $userDTO->getId());
4444
}
45+
46+
public function removeExternalAuthFlag(): void
47+
{
48+
$userId = $this->session->get('usr');
49+
if ($userId) {
50+
$this->userRepository->removeExternalAuthFlag((string)$userId);
51+
}
52+
}
4553
}

src/Authentication/OAuth2/Service/UserServiceInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,6 @@ interface UserServiceInterface
1818
* @throws UserBlockedException If the user is blocked.
1919
*/
2020
public function login(OAuth2UserDTOInterface $auth2UserDTO): void;
21+
22+
public function removeExternalAuthFlag(): void;
2123
}

src/Captcha/Shop/ForgotPasswordController.php renamed to src/Shared/Controller/ForgotPasswordController.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,18 @@
77

88
declare(strict_types=1);
99

10-
namespace OxidEsales\SecurityModule\Captcha\Shop;
10+
namespace OxidEsales\SecurityModule\Shared\Controller;
1111

1212
use OxidEsales\Eshop\Core\Exception\StandardException;
1313
use OxidEsales\Eshop\Core\Registry;
14+
use OxidEsales\SecurityModule\Authentication\OAuth2\Service\UserServiceInterface;
1415
use OxidEsales\SecurityModule\Captcha\Service\CaptchaServiceInterface;
1516
use OxidEsales\SecurityModule\Captcha\Service\ModuleSettingsServiceInterface;
1617

18+
/**
19+
* @mixin \OxidEsales\Eshop\Application\Controller\ForgotPasswordController
20+
* @eshopExtension
21+
*/
1722
class ForgotPasswordController extends ForgotPasswordController_parent
1823
{
1924
public function forgotPassword(): ?bool
@@ -36,4 +41,16 @@ public function forgotPassword(): ?bool
3641

3742
return parent::forgotPassword();
3843
}
44+
45+
public function updatePassword()
46+
{
47+
$result = parent::updatePassword();
48+
49+
if ($result === 'forgotpwd?success=1') {
50+
$this->getService(UserServiceInterface::class)
51+
->removeExternalAuthFlag();
52+
}
53+
54+
return $result;
55+
}
3956
}

src/Shared/Core/ViewConfig.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,11 @@ public function getRemainingAttempts(): int
6464
{
6565
return $this->getService(AuthorizeServiceInterface::class)->getRemainingAttempts();
6666
}
67+
68+
public function isExternalAuthUser(): bool
69+
{
70+
$user = $this->getUser();
71+
72+
return $user && (bool) $user->getFieldData('oesmexternalauth');
73+
}
6774
}

tests/Integration/Captcha/Shop/ForgotPasswordControllerTest.php

Lines changed: 0 additions & 124 deletions
This file was deleted.

0 commit comments

Comments
 (0)