Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

Commit

Permalink
Merge pull request #301 from darrynten/ref/get-flow-type
Browse files Browse the repository at this point in the history
Refactors the functionality to get the flow type.
  • Loading branch information
Tyler King authored Aug 12, 2019
2 parents 01c4990 + b46bae1 commit 517623d
Showing 1 changed file with 32 additions and 11 deletions.
43 changes: 32 additions & 11 deletions src/ShopifyApp/Middleware/AuthShop.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,9 @@ protected function validateShop(Request $request)

$session->setShop($shop);

$flowType = null;
if ($shop === null || $shop->trashed()) {
// We need to do a full flow
$flowType = AuthShopHandler::FLOW_FULL;
} elseif (!$session->isValid()) {
// Just a session issue, do a partial flow if we can...
$flowType = $session->isType(ShopSession::GRANT_PERUSER) ?
AuthShopHandler::FLOW_FULL :
AuthShopHandler::FLOW_PARTIAL;
}
$flowType = $this->getFlowType($shop, $session);

if ($flowType !== null) {
if ($flowType) {
// We have a bad session
return $this->handleBadSession(
$flowType,
Expand All @@ -85,6 +76,36 @@ protected function validateShop(Request $request)
return true;
}

/**
* Gets the appropriate flow type. It either returns full, partial,
* or false. If it returns false it means that everything is fine.
*
* @param $shop The shop model.
* @param \OhMyBrew\ShopifyApp\Services\ShopSession $session The session service for the shop.
*
* @return bool|string
*/
private function getFlowType($shop, $session)
{
// We need to do a full flow if no shop or it is deleted
if ($shop === null || $shop->trashed()) {
return AuthShopHandler::FLOW_FULL;
}

// Do nothing if the session is valid
if ($session->isValid()) {
return false;
}

// We need to do a full flow if it grant per user
if ($session->isType(ShopSession::GRANT_PERUSER)) {
return AuthShopHandler::FLOW_FULL;
}

// Default is the partial flow
return AuthShopHandler::FLOW_PARTIAL;
}

/**
* Handles a bad shop session.
*
Expand Down

0 comments on commit 517623d

Please sign in to comment.