Skip to content

Commit

Permalink
Removed redundant comparision
Browse files Browse the repository at this point in the history
  • Loading branch information
mamazu authored and lchrusciel committed Jan 4, 2019
1 parent d4c81f6 commit 836982c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/Controller/Checkout/CompleteOrderAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Exception\TokenNotFoundException;

final class CompleteOrderAction
{
Expand Down Expand Up @@ -51,6 +52,13 @@ public function __invoke(Request $request): Response
Response::HTTP_UNAUTHORIZED
)
);
} catch (TokenNotFoundException $notLoggedInException) {
return $this->viewHandler->handle(
View::create(
'You need to be logged in with the same user that wants to complete the order',
Response::HTTP_UNAUTHORIZED
)
);
}

return $this->viewHandler->handle(View::create(null, Response::HTTP_NO_CONTENT));
Expand Down
4 changes: 3 additions & 1 deletion src/Handler/CompleteOrderHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ private function getCustomer(string $emailAddress): CustomerInterface

// If the customer does not exist then it's normal checkout
if ($customer === null) {
/** @var CustomerInterface $customer */
$customer = $this->customerFactory->createNew();
$customer->setEmail($emailAddress);

Expand All @@ -80,7 +81,8 @@ private function getCustomer(string $emailAddress): CustomerInterface

// If the customer does exist the user has to be logged in with this customer. Otherwise the user is not authorized to complete the checkout
$loggedInUser = $this->loggedInUserProvider->provide();
if ($loggedInUser === null || $loggedInUser->getCustomer() !== $customer) {

if ($loggedInUser->getCustomer() !== $customer) {
throw new NotLoggedInException();
}

Expand Down

0 comments on commit 836982c

Please sign in to comment.