-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
842 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
/** | ||
* Copyright © OpenGento, All rights reserved. | ||
* See LICENSE bundled with this library for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Opengento\PasswordLessLogin\Controller\Adminhtml\Pwl; | ||
|
||
use Magento\Framework\App\Action\HttpGetActionInterface; | ||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use Magento\Framework\App\RequestInterface; | ||
use Magento\Framework\Controller\Result\RedirectFactory; | ||
use Magento\Framework\Message\Manager as MessageManager; | ||
use Opengento\PasswordLessLogin\Api\RequestLoginRepositoryInterface; | ||
use Opengento\PasswordLessLogin\Enum\Config; | ||
use Opengento\PasswordLessLogin\Exception\RequestException; | ||
use Opengento\PasswordLessLogin\Service\Admin\Login as LoginService; | ||
use Opengento\PasswordLessLogin\Service\Request\Encryption as EncryptionService; | ||
|
||
class ProcessLogin implements HttpGetActionInterface | ||
{ | ||
/** | ||
* @param \Opengento\PasswordLessLogin\Api\RequestLoginRepositoryInterface $loginRequestRepository | ||
* @param \Opengento\PasswordLessLogin\Service\Admin\Login $adminLoginService | ||
* @param \Opengento\PasswordLessLogin\Service\Request\Encryption $encryptionService | ||
* @param \Magento\Framework\App\RequestInterface $request | ||
* @param \Magento\Framework\Controller\Result\RedirectFactory $redirectFactory | ||
* @param \Magento\Framework\Message\Manager $messageManager | ||
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig | ||
*/ | ||
public function __construct( | ||
protected readonly RequestLoginRepositoryInterface $loginRequestRepository, | ||
protected readonly LoginService $adminLoginService, | ||
protected readonly EncryptionService $encryptionService, | ||
protected readonly RequestInterface $request, | ||
protected readonly RedirectFactory $redirectFactory, | ||
protected readonly MessageManager $messageManager, | ||
protected readonly ScopeConfigInterface $scopeConfig, | ||
) { | ||
} | ||
|
||
/** | ||
* @return \Magento\Framework\Controller\Result\Redirect | ||
*/ | ||
public function execute() | ||
{ | ||
$redirect = $this->redirectFactory->create(); | ||
$params = $this->request->getParams(); | ||
if ($params) { | ||
try { | ||
if (isset($params['request'])) { | ||
$secretKey = $this->scopeConfig->getValue(Config::XML_PATH_PASSWORDLESSLOGIN_SECRET_KEY->value); | ||
$decryptedData = $this->encryptionService->decrypt($params['request'], $secretKey); | ||
$params = explode("/", $decryptedData); | ||
$params = array_chunk($params, 2); | ||
$params = array_combine(array_column($params, 0), array_column($params, 1)); | ||
if (isset($params['email']) && isset($params['token'])) { | ||
$loginRequest = $this->loginRequestRepository->get($params['email']); | ||
if ($loginRequest->getToken() === $params['token']) { | ||
if ($loginRequest->hasBeenUsed() || $loginRequest->hasExpired()) { | ||
$this->messageManager->addErrorMessage(__('Unable to execute request. Please try again.')); | ||
return $redirect->setPath('*'); | ||
} | ||
$this->loginRequestRepository->lock($loginRequest); | ||
$this->request->setParams(['email' => $params['email']]); | ||
$this->adminLoginService->perform($this->request); | ||
$this->loginRequestRepository->delete($loginRequest); | ||
} else { | ||
throw new RequestException(_('Invalid request. Please try again.')); | ||
} | ||
} else { | ||
throw new RequestException(_('Invalid request. Please try again.')); | ||
} | ||
} else { | ||
throw new RequestException(_('Invalid request. Please try again.')); | ||
} | ||
} catch (\Exception $e) { | ||
$this->messageManager->addErrorMessage($e->getMessage()); | ||
} | ||
} | ||
return $redirect->setPath('*'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
/** | ||
* Copyright © OpenGento, All rights reserved. | ||
* See LICENSE bundled with this library for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Opengento\PasswordLessLogin\Controller\Adminhtml\Pwl; | ||
|
||
use Magento\Backend\Block\Admin\Formkey; | ||
use Magento\Framework\App\Action\HttpPostActionInterface; | ||
use Magento\Framework\App\RequestInterface; | ||
use Magento\Framework\Controller\Result\RedirectFactory; | ||
use Magento\Framework\Message\Manager as MessageManager; | ||
use Opengento\PasswordLessLogin\Service\Queue; | ||
|
||
class RequestLogin implements HttpPostActionInterface | ||
{ | ||
/** | ||
* @param \Magento\Framework\App\RequestInterface $request | ||
* @param \Magento\Framework\Controller\Result\RedirectFactory $redirectFactory | ||
* @param \Magento\Framework\Message\Manager $messageManager | ||
* @param \Magento\Backend\Block\Admin\Formkey $formKey | ||
* @param \Opengento\PasswordLessLogin\Service\Queue $queueService | ||
*/ | ||
public function __construct( | ||
protected readonly RequestInterface $request, | ||
protected readonly RedirectFactory $redirectFactory, | ||
protected readonly MessageManager $messageManager, | ||
protected readonly FormKey $formKey, | ||
protected readonly Queue $queueService | ||
) { | ||
} | ||
|
||
/** | ||
* @return \Magento\Framework\Controller\Result\Redirect | ||
*/ | ||
public function execute() | ||
{ | ||
$redirect = $this->redirectFactory->create(); | ||
|
||
$params = $this->request->getParams(); | ||
if ($params) { | ||
$isFormKey = $this->formKey->isEmpty(); | ||
if ($isFormKey) { | ||
$this->messageManager->addErrorMessage(__('Invalid Form Key. Please refresh the page.')); | ||
return $redirect->setPath('*/*'); | ||
} | ||
if (!isset($params['login']['username'])) { | ||
$this->messageManager->addErrorMessage(__('You must enter a valid email address.')); | ||
return $redirect->setPath('*/*'); | ||
} else { | ||
try { | ||
$this->queueService->add($params, 'admin'); | ||
$this->messageManager->addSuccessMessage(__('If an account exists, you will receive an email to proceed with your request.')); | ||
} catch (\Exception $e) { | ||
$this->messageManager->addErrorMessage($e->getMessage()); | ||
return $redirect->setPath('*/*'); | ||
} | ||
} | ||
} | ||
|
||
return $redirect->setPath('*/*'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?php | ||
/** | ||
* Copyright © OpenGento, All rights reserved. | ||
* See LICENSE bundled with this library for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Opengento\PasswordLessLogin\Model\Admin; | ||
|
||
use Magento\Framework\App\DeploymentConfig; | ||
use Magento\Framework\Serialize\Serializer\Json; | ||
use Magento\User\Model\Spi\NotificatorInterface; | ||
use Magento\User\Model\UserValidationRules; | ||
|
||
class User extends \Magento\User\Model\User | ||
{ | ||
protected $serializer; | ||
|
||
/** | ||
* @param \Opengento\PasswordLessLogin\Model\ResourceModel\Admin\User $resourceModel | ||
* @param \Magento\Framework\Model\Context $context | ||
* @param \Magento\Framework\Registry $registry | ||
* @param \Magento\User\Helper\Data $userData | ||
* @param \Magento\Backend\App\ConfigInterface $config | ||
* @param \Magento\Framework\Validator\DataObjectFactory $validatorObjectFactory | ||
* @param \Magento\Authorization\Model\RoleFactory $roleFactory | ||
* @param \Magento\Framework\Mail\Template\TransportBuilder $transportBuilder | ||
* @param \Magento\Framework\Encryption\EncryptorInterface $encryptor | ||
* @param \Magento\Store\Model\StoreManagerInterface $storeManager | ||
* @param \Magento\User\Model\UserValidationRules $validationRules | ||
* @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource | ||
* @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection | ||
* @param array $data | ||
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer | ||
* @param \Magento\Framework\App\DeploymentConfig|null $deploymentConfig | ||
* @param \Magento\User\Model\Spi\NotificatorInterface|null $notificator | ||
*/ | ||
public function __construct( | ||
protected readonly \Opengento\PasswordLessLogin\Model\ResourceModel\Admin\User $resourceModel, | ||
\Magento\Framework\Model\Context $context, | ||
\Magento\Framework\Registry $registry, | ||
\Magento\User\Helper\Data $userData, | ||
\Magento\Backend\App\ConfigInterface $config, | ||
\Magento\Framework\Validator\DataObjectFactory $validatorObjectFactory, | ||
\Magento\Authorization\Model\RoleFactory $roleFactory, | ||
\Magento\Framework\Mail\Template\TransportBuilder $transportBuilder, | ||
\Magento\Framework\Encryption\EncryptorInterface $encryptor, | ||
\Magento\Store\Model\StoreManagerInterface $storeManager, | ||
UserValidationRules $validationRules, | ||
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, | ||
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, | ||
array $data = [], | ||
Json $serializer = null, | ||
DeploymentConfig $deploymentConfig = null, | ||
?NotificatorInterface $notificator = null | ||
) { | ||
parent::__construct( | ||
$context, | ||
$registry, | ||
$userData, | ||
$config, | ||
$validatorObjectFactory, | ||
$roleFactory, | ||
$transportBuilder, | ||
$encryptor, | ||
$storeManager, | ||
$validationRules, | ||
$resource, | ||
$resourceCollection, | ||
$data, | ||
$serializer, | ||
$deploymentConfig, | ||
$notificator | ||
); | ||
} | ||
|
||
/** | ||
* @throws \Magento\Framework\Exception\LocalizedException | ||
*/ | ||
public function loadByEmail(string $email): static | ||
{ | ||
$data = $this->resourceModel->loadByEmail($email); | ||
if ($data !== false) { | ||
$this->setData($data); | ||
$this->setOrigData(); | ||
} | ||
return $this; | ||
} | ||
} |
Oops, something went wrong.