Skip to content

Commit

Permalink
phpcs
Browse files Browse the repository at this point in the history
  • Loading branch information
ronangr1 committed Aug 6, 2024
1 parent 671b4df commit 02e6cff
Show file tree
Hide file tree
Showing 45 changed files with 359 additions and 168 deletions.
10 changes: 10 additions & 0 deletions Api/RequestLoginRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,40 @@
interface RequestLoginRepositoryInterface
{
/**
* Get Login Request
*
* @param string $email
* @return LoginRequest
*/
public function get(string $email): LoginRequest;

/**
* Get Login Request By Id
*
* @param string $id
* @return LoginRequest
*/
public function getById(string $id): LoginRequest;

/**
* Save Login Request
*
* @param \Opengento\Hoodoor\Model\LoginRequest $model
* @return bool
*/
public function save(LoginRequest $model): bool;

/**
* Delete Login Request
*
* @param \Opengento\Hoodoor\Model\LoginRequest $model
* @return bool
*/
public function delete(LoginRequest $model): bool;

/**
* Lock Login Request
*
* @param \Opengento\Hoodoor\Model\LoginRequest $model
* @return bool
*/
Expand Down
13 changes: 10 additions & 3 deletions Block/Adminhtml/System/Config/Button.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
class Button extends Field
{
/**
* Create Element Html (Button + Script)
*
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @return string
* @throws \Magento\Framework\Exception\LocalizedException
Expand All @@ -28,21 +30,26 @@ protected function _getElementHtml(AbstractElement $element): string
}

/**
* Create Button Block
*
* @return string
* @throws \Magento\Framework\Exception\LocalizedException
*/
protected function getButtonHtml()
protected function getButtonHtml(): string
{
$button = $this->getLayout()->createBlock(WidgetButton::class)
->setData(array(
->setData([
'id' => 'generate_secret_key',
'label' => __('Generate Secret Key'),
'class' => 'generate-secret-key-button'
));
]);

return $button->toHtml();
}

/**
* Generate Secret Key Script
*
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @return string
*/
Expand Down
9 changes: 6 additions & 3 deletions Controller/Account/CreatePost.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,15 @@ class CreatePost extends CoreCreatePost implements CsrfAwareActionInterface, Htt
* @param \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository
* @param \Magento\Framework\Data\Form\FormKey\Validator|null $formKeyValidator
*/
public function __construct(
public function __construct( //phpcs:ignore
protected readonly Password $passwordService,
Context $context,
Session $customerSession,
ScopeConfigInterface $scopeConfig,
StoreManagerInterface $storeManager,
AccountManagementInterface $accountManagement,
Address $addressHelper, UrlFactory $urlFactory,
Address $addressHelper,
UrlFactory $urlFactory,
FormFactory $formFactory,
SubscriberFactory $subscriberFactory,
RegionInterfaceFactory $regionDataFactory,
Expand Down Expand Up @@ -115,12 +116,14 @@ public function __construct(
}

/**
* Execute
*
* @throws \Magento\Framework\Exception\NotFoundException
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function execute()
{
if(!$this->password) {
if (!$this->password) {
$this->password = $this->passwordService->generate();
}
$this->getRequest()->setParams([
Expand Down
2 changes: 2 additions & 0 deletions Controller/Account/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
class Edit extends \Magento\Customer\Controller\Account\Edit
{
/**
* Execute
*
* @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\View\Result\Page
*/
public function execute()
Expand Down
2 changes: 1 addition & 1 deletion Controller/Account/ForgotPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ class ForgotPassword extends \Magento\Customer\Controller\Account\ForgotPassword
public function execute()
{
$this->messageManager->addErrorMessage(__('Access denied.'));
return $this->_redirect('customer/account/login');
return $this->_redirect('customer/account');
}
}
22 changes: 16 additions & 6 deletions Controller/Adminhtml/Pwl/ProcessLogin.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ProcessLogin implements HttpGetActionInterface
* @param \Magento\Framework\Message\Manager $messageManager
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
*/
public function __construct(
public function __construct( //phpcs:ignore
protected readonly RequestLoginRepositoryInterface $loginRequestRepository,
protected readonly LoginService $adminLoginService,
protected readonly EncryptionService $encryptionService,
Expand All @@ -41,9 +41,11 @@ public function __construct(
}

/**
* Execute
*
* @return \Magento\Framework\Controller\Result\Redirect
*/
public function execute()
public function execute() // phpcs:ignore Generic.Metrics.NestingLevel.TooHigh
{
$redirect = $this->redirectFactory->create();
$params = $this->request->getParams();
Expand All @@ -59,21 +61,29 @@ public function execute()
$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.'));
$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.'));
throw new RequestException(
_('Invalid request. Please try again.') // phpcs:ignore
);
}
} else {
throw new RequestException(_('Invalid request. Please try again.'));
throw new RequestException(
_('Invalid request. Please try again.') // phpcs:ignore
);
}
} else {
throw new RequestException(_('Invalid request. Please try again.'));
throw new RequestException(
_('Invalid request. Please try again.') // phpcs:ignore
);
}
} catch (\Exception $e) {
$this->messageManager->addErrorMessage($e->getMessage());
Expand Down
12 changes: 9 additions & 3 deletions Controller/Adminhtml/Pwl/RequestLogin.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class RequestLogin implements HttpPostActionInterface
* @param \Magento\Backend\Block\Admin\Formkey $formKey
* @param \Opengento\Hoodoor\Service\Queue $queueService
*/
public function __construct(
public function __construct( //phpcs:ignore
protected readonly RequestInterface $request,
protected readonly RedirectFactory $redirectFactory,
protected readonly MessageManager $messageManager,
Expand All @@ -33,6 +33,8 @@ public function __construct(
}

/**
* Execute
*
* @return \Magento\Framework\Controller\Result\Redirect
*/
public function execute()
Expand All @@ -47,12 +49,16 @@ public function execute()
return $redirect->setPath('*/*');
}
if (!isset($params['login']['username'])) {
$this->messageManager->addErrorMessage(__('You must enter a valid email address.'));
$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.'));
$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('*/*');
Expand Down
16 changes: 10 additions & 6 deletions Controller/Pwl/ProcessLogin.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ProcessLogin implements HttpGetActionInterface
* @param \Magento\Framework\Message\Manager $messageManager
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
*/
public function __construct(
public function __construct( //phpcs:ignore
protected readonly RequestLoginRepositoryInterface $loginRequestRepository,
protected readonly LoginService $loginService,
protected readonly EncryptionService $encryptionService,
Expand All @@ -41,9 +41,11 @@ public function __construct(
}

/**
* Execute
*
* @return \Magento\Framework\Controller\Result\Redirect
*/
public function execute()
public function execute() // phpcs:ignore Generic.Metrics.NestingLevel.TooHigh
{
$redirect = $this->redirectFactory->create();
$params = $this->request->getParams();
Expand All @@ -59,20 +61,22 @@ public function execute()
$request = $this->loginRequestRepository->get($params['email']);
if ($request->getToken() === $params['token']) {
if ($request->hasBeenUsed() || $request->hasExpired()) {
$this->messageManager->addErrorMessage(__('Unable to execute request. Please try again.'));
$this->messageManager->addErrorMessage(
__('Unable to execute request. Please try again.')
);
return $redirect->setPath('*/account/login');
}
$this->loginRequestRepository->lock($request);
$this->loginService->perform($params);
$this->loginRequestRepository->delete($request);
} else {
throw new RequestException(_('Invalid request. Please try again.'));
throw new RequestException(_('Invalid request. Please try again.')); //phpcs:ignore
}
} else {
throw new RequestException(_('Invalid request. Please try again.'));
throw new RequestException(_('Invalid request. Please try again.')); //phpcs:ignore
}
} else {
throw new RequestException(_('Invalid request. Please try again.'));
throw new RequestException(_('Invalid request. Please try again.')); //phpcs:ignore
}
} catch (\Exception $e) {
$this->messageManager->addErrorMessage($e->getMessage());
Expand Down
16 changes: 12 additions & 4 deletions Controller/Pwl/RequestLogin.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class RequestLogin implements HttpPostActionInterface
* @param \Opengento\Hoodoor\Service\Request $requestService
* @param \Opengento\Hoodoor\Service\Queue $queueService
*/
public function __construct(
public function __construct( //phpcs:ignore
protected readonly RequestInterface $request,
protected readonly RedirectFactory $redirectFactory,
protected readonly MessageManager $messageManager,
Expand All @@ -36,6 +36,8 @@ public function __construct(
}

/**
* Execute
*
* @return \Magento\Framework\Controller\Result\Redirect
*/
public function execute()
Expand All @@ -46,16 +48,22 @@ public function execute()
if ($params) {
$isFormKey = $this->formKey->isPresent();
if (!$isFormKey) {
$this->messageManager->addErrorMessage(__('Invalid Form Key. Please refresh the page.'));
$this->messageManager->addErrorMessage(
__('Invalid Form Key. Please refresh the page.')
);
return $redirect->setPath('*/*/login');
}
if (!isset($params['login']['username'])) {
$this->messageManager->addErrorMessage(__('You must enter a valid email address.'));
$this->messageManager->addErrorMessage(
__('You must enter a valid email address.')
);
return $redirect->setPath('*/*/login');
} else {
try {
$this->queueService->add($params, 'customer');
$this->messageManager->addSuccessMessage(__('If a customer account exists, you will receive an email to proceed with your request.'));
$this->messageManager->addSuccessMessage(
__('If a customer account exists, you will receive an email to proceed with your request.')
);
} catch (\Exception $e) {
$this->messageManager->addErrorMessage($e->getMessage());
return $redirect->setPath('*/*/login');
Expand Down
10 changes: 9 additions & 1 deletion Model/Admin/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@

use Magento\Framework\App\DeploymentConfig;
use Magento\Framework\Serialize\Serializer\Json;
use Magento\Framework\Serialize\SerializerInterface;
use Magento\User\Model\Spi\NotificatorInterface;
use Magento\User\Model\UserValidationRules;

class User extends \Magento\User\Model\User
{
protected $serializer;
/**
* @var \Magento\Framework\Serialize\SerializerInterface
*/
protected SerializerInterface $serializer;

/**
* @param \Opengento\Hoodoor\Model\ResourceModel\Admin\User $resourceModel
Expand Down Expand Up @@ -75,6 +79,10 @@ public function __construct(
}

/**
* Load Admin User By Email
*
* @param string $email
* @return $this
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function loadByEmail(string $email): static
Expand Down
Loading

0 comments on commit 02e6cff

Please sign in to comment.