AccountClaimMiddleware.php
3 years ago
ArchiveModelMiddleware.php
3 years ago
BrandColorMiddleware.php
3 years ago
CheckoutRedirectMiddleware.php
3 years ago
ComponentAssetsMiddleware.php
3 years ago
CustomerDashboardRedirectMiddleware.php
3 years ago
EditModelMiddleware.php
3 years ago
LoginLinkMiddleware.php
3 years ago
LoginMiddleware.php
3 years ago
NonceMiddleware.php
3 years ago
OrderRedirectMiddleware.php
3 years ago
PathRedirectMiddleware.php
3 years ago
PaymentFailureRedirectMiddleware.php
3 years ago
PurchaseRedirectMiddleware.php
3 years ago
SubscriptionRedirectMiddleware.php
3 years ago
WebhooksMiddleware.php
2 years ago
NonceMiddleware.php
39 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SureCart\Middleware; |
| 4 | |
| 5 | use Closure; |
| 6 | use SureCartCore\Requests\RequestInterface; |
| 7 | use SureCartCore\Responses\RedirectResponse; |
| 8 | |
| 9 | /** |
| 10 | * Middleware for handling model archiving. |
| 11 | */ |
| 12 | class NonceMiddleware { |
| 13 | /** |
| 14 | * Handle the middleware. |
| 15 | * |
| 16 | * @param RequestInterface $request Request. |
| 17 | * @param Closure $next Next. |
| 18 | * @param string $model_name Model name. |
| 19 | * @return function |
| 20 | */ |
| 21 | public function handle( RequestInterface $request, Closure $next, $nonce_name ) { |
| 22 | // get nonce from body or query. |
| 23 | $nonce = $request->query( 'nonce' ) ?? $request->body( 'nonce' ); |
| 24 | |
| 25 | if ( empty( $nonce ) ) { |
| 26 | wp_die( esc_html__( 'Something is wrong with the provided link.', 'surecart' ) ); |
| 27 | exit; |
| 28 | } |
| 29 | |
| 30 | // check nonce. |
| 31 | if ( ! wp_verify_nonce( $nonce, $nonce_name ) ) { |
| 32 | wp_die( esc_html__( 'Your session expired - please try again.', 'surecart' ) ); |
| 33 | exit; |
| 34 | } |
| 35 | |
| 36 | return $next( $request ); |
| 37 | } |
| 38 | } |
| 39 |