Skip to content

Commit 86377a4

Browse files
committed
OXDEV-9927 Add target url to session
1 parent 6473b82 commit 86377a4

4 files changed

Lines changed: 15 additions & 11 deletions

File tree

src/Authentication/TwoFactorAuth/Service/AuthorizeService.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class AuthorizeService implements AuthorizeServiceInterface
1515
{
1616
public const USER_SESSION_KEY = 'pending_authorized_user';
1717

18+
public const OTP_TARGET_URL = 'otp_target_url';
19+
1820
public function __construct(
1921
private ModuleSettingsServiceInterface $moduleSettings,
2022
private VerificationCollectorServiceInterface $verificationCollectorService,

src/Authentication/TwoFactorAuth/Service/UserService.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Service;
1111

12+
use OxidEsales\Eshop\Core\Registry;
1213
use OxidEsales\EshopCommunity\Internal\Domain\Authentication\Bridge\PasswordServiceBridgeInterface;
1314
use OxidEsales\EshopCommunity\Internal\Framework\Session\SessionInterface;
1415
use OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Infrastructure\Repository\UserRepositoryInterface;
@@ -26,20 +27,24 @@ public function __construct(
2627
public function handleLogin($userName): void
2728
{
2829
$this->session->set(AuthorizeService::USER_SESSION_KEY, $userName);
30+
$this->session->set(
31+
AuthorizeService::OTP_TARGET_URL,
32+
//todo: bind registry
33+
Registry::getRequest()->getRequestUrl()
34+
);
2935

3036
$this->authorizeService->generate();
31-
// redirect to controller and rende template
32-
// use template renderer to render the template
37+
38+
//todo: return full url
39+
$redirectUrl = $this->authorizeService->getVerificationUrl();
40+
Registry::getUtils()->redirect(Registry::getConfig()->getShopHomeUrl() . 'cl=' . $redirectUrl);
3341
}
3442

3543
public function checkPassword(string $userName, string $password): bool
3644
{
37-
// $userModel = $this->userFactory->create();
38-
// $userModel->load($userId);
39-
4045
//todo: got exception if user not found
4146
$userPasswordHash = $this->userRepository->getUserPasswordHash($userName);
42-
// var_dump($userPasswordHash);
47+
4348
return $this->passwordServiceBridge
4449
->verifyPassword($password, $userPasswordHash);
4550
}

src/Authentication/TwoFactorAuth/Service/Verificator/OTP/OTPVerificator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Service\Verificator\OTP;
1111

12+
use OxidEsales\Eshop\Core\Registry;
1213
use OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Exception\InvalidCodeException;
1314
use OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Infrastructure\Repository\UserRepositoryInterface;
1415
use OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Service\Verificator\OTP\Generator\OTPGeneratorInterface;
@@ -62,7 +63,6 @@ public function generate(string $userName): string
6263

6364
public function getVerificationUrl(): string
6465
{
65-
//todo: this should be called from User Model or AuthorizeService
6666
return 'twofactorauth';
6767
}
6868
}

src/Shared/Model/User.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ public function login($userName, $password, $setSessionCookie = false): bool
6565
if (!$this->isCaptchaEnabled()) {
6666
// return parent::login($userName, $password, $setSessionCookie);
6767
}
68-
6968
if (!$this->isAdmin()) {
7069
$captchaService = $this->getService(CaptchaServiceInterface::class);
7170

@@ -84,14 +83,12 @@ public function login($userName, $password, $setSessionCookie = false): bool
8483

8584
$userService = $this->getService(UserServiceInterface::class);
8685
if (!$userService->checkPassword($userName, $password)) {
86+
//todo: log invalid login attempt and throw exception
8787
return false; // invalid login
8888
}
8989

9090
$userService->handleLogin($userName);
9191

92-
//todo: redirect to correct page decided by verificator method? (otp: otp page, TOTP: totp page, etc)
93-
Registry::getUtils()->redirect(Registry::getConfig()->getShopHomeUrl() . 'cl=twofactorauth');
94-
9592
return false;
9693
}
9794

0 commit comments

Comments
 (0)