|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * Copyright © OXID eSales AG. All rights reserved. |
| 5 | + * See LICENSE file for license details. |
| 6 | + */ |
| 7 | + |
| 8 | +declare(strict_types=1); |
| 9 | + |
| 10 | +namespace OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Controller; |
| 11 | + |
| 12 | +use OxidEsales\Eshop\Application\Controller\FrontendController; |
| 13 | +use OxidEsales\Eshop\Core\Registry; |
| 14 | +use OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Service\AuthorizeServiceInterface; |
| 15 | +use OxidEsales\SecurityModule\Authentication\TwoFactorAuth\Transput\AuthCodeRequestInterface; |
| 16 | + |
| 17 | +class TwoFactorAuthController extends FrontendController |
| 18 | +{ |
| 19 | + /** |
| 20 | + * Current view template |
| 21 | + * |
| 22 | + * @var string |
| 23 | + * @SuppressWarnings("PHPMD.CamelCasePropertyName") |
| 24 | + */ |
| 25 | + protected $_sThisTemplate = '@oe_security_module/templates/two_factor_auth'; |
| 26 | + |
| 27 | + public function handleOTP(): void |
| 28 | + { |
| 29 | + $OTPRequest = $this->getService(AuthCodeRequestInterface::class); |
| 30 | + |
| 31 | + //todo: catch only OTP exception that will be shown to user, maybe some abstract OTP exception? |
| 32 | + try { |
| 33 | + $authorizeService = $this->getService(AuthorizeServiceInterface::class); |
| 34 | + $authorizeService->validate( |
| 35 | + $OTPRequest->getCode() |
| 36 | + ); |
| 37 | + |
| 38 | + //todo: redirect to originally requested page after successful OTP validation |
| 39 | + //todo: create correct session for logged in user (from service, handleLogin?) |
| 40 | + } catch (\Exception $e) { |
| 41 | + //todo: display translated error message to user |
| 42 | + Registry::getUtilsView()->addErrorToDisplay($e->getMessage()); |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + public function generate(): void |
| 47 | + { |
| 48 | + //todo: stop execution if not ajax |
| 49 | + //todo: prevent spam by rate limiting |
| 50 | + //todo: should return json response with success or error message |
| 51 | + $authorizeService = $this->getService(AuthorizeServiceInterface::class); |
| 52 | + $authorizeService->generate(); |
| 53 | + } |
| 54 | +} |
0 commit comments