Skip to content

Commit

Permalink
Add default M2 e-mail validation to whitelist. Add notice for whiteli…
Browse files Browse the repository at this point in the history
…st functionality to README.md
  • Loading branch information
Ilja committed Jan 21, 2020
1 parent 104e7f4 commit 0a7db37
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,13 @@ Magento 2 routers.
## Customization
To add new path you must provide your own validator, that must implement `ScandiPWA\Router\ValidatorInterface` and
register it as an array element passed to `ScandiPWA\Router\ValidationManager` using `di.xml`.


## Accessing Magento 2 default routes
In order to allow Magento 2 to handle some routes in default manner (only serverside functionality) you must allow
specific routes to be accessed by adding RegExp to `src/app/etc/di.xml::ignoredURLs` arguments list.

So far there are 3 paths whitelisted out of the box:
- `/newsletter/subscriber/confirm` - subscribe to newsletter
- `/newsletter/subscriber/unsubscribe` - unsubscribe to newsletter
- `/customer/account/confirm/` - confirm e-mail (redirect to homepage in any case, modify according to your needs)
43 changes: 43 additions & 0 deletions src/Controller/Customer/RedirectPlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* @category ScandiPWA
* @package ScandiPWA\Router
* @author Ilja Lapkovskis <[email protected] / [email protected]>
* @copyright Copyright (c) 2019 Scandiweb, Ltd (http://scandiweb.com)
* @license OSL-3.0
*/

namespace ScandiPWA\Router\Controller\Customer;


use Magento\Customer\Controller\Account\Confirm;
use \Magento\Framework\Controller\Result\Redirect;
use Magento\Framework\UrlInterface;


class RedirectPlugin
{
/**
* @var UrlInterface
*/
protected $urlModel;

/**
* ValidateRedirect constructor.
* @param UrlInterface $urlModel
*/
public function __construct(UrlInterface $urlModel)
{
$this->urlModel = $urlModel;
}

/**
* @param Confirm $a
* @param Redirect $result
* @return Redirect
*/
public function afterExecute(Confirm $subject, $result)
{
return $result->setPath($this->urlModel->getBaseUrl());
}
}
7 changes: 6 additions & 1 deletion src/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="ScandiPWA\Router\ValidationManagerInterface" type="ScandiPWA\Router\ValidationManager"/>
<preference for="Magento\Framework\View\Result\Page" type="ScandiPWA\Router\View\Result\Page"/>
<preference for="ScandiPWA\Router\Controller\Router" type="ScandiPWA\Router\Controller\ConfigurableRouter" />
<preference for="ScandiPWA\Router\Controller\Router" type="ScandiPWA\Router\Controller\ConfigurableRouter"/>
<type name="Magento\Customer\Controller\Account\Confirm">
<plugin name="customize_email_validation_redirect"
type="ScandiPWA\Router\Controller\Customer\RedirectPlugin"></plugin>
</type>
<type name="ScandiPWA\Router\ValidationManager">
<arguments>
<argument name="validators" xsi:type="array">
Expand All @@ -29,6 +33,7 @@
<argument name="ignoredURLs" xsi:type="array">
<item name="confirmSubscribeToNewsletter" xsi:type="string">^/newsletter/subscriber/confirm/.*</item>
<item name="unsubscribeFromNewslettter" xsi:type="string">^/newsletter/subscriber/unsubscribe/.*</item>
<item name="validateCustomerEmail" xsi:type="string">^/customer/account/confirm/.*</item>
</argument>
</arguments>
</virtualType>
Expand Down

0 comments on commit 0a7db37

Please sign in to comment.