Skip to content

Commit

Permalink
Merge pull request #14 from misakwa/MAP-183
Browse files Browse the repository at this point in the history
fix(MAP-183) - Add multi-user user removal support
  • Loading branch information
splittingred committed Jan 29, 2018
2 parents 8400218 + b3de552 commit 326295d
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions index.php
Expand Up @@ -28,9 +28,10 @@
$key = getUserKey($data['store_hash'], $data['user']['email']);
$user = json_decode($redis->get($key), true);
if (empty($user)) {
return 'Invalid user.';
$user = $data['user'];
$redis->set($key, json_encode($user, true));
}
return 'Welcome ' . json_encode($user);
return 'Welcome ' . json_encode($user, true);
});

$app->get('/auth/callback', function (Request $request) use ($app) {
Expand Down Expand Up @@ -68,6 +69,19 @@

});

// Endpoint for removing users in a multi-user setup
$app->get('/remove-user', function(Request $request) use ($app) {
$data = verifySignedRequest($request->get('signed_payload'));
if (empty($data)) {
return 'Invalid signed_payload.';
}

$key = getUserKey($data['store_hash'], $data['user']['email']);
$redis = new Credis_Client('localhost');
$redis->del($key);
return '[Remove User] '.$data['user']['email'];
});

/**
* GET /storefront/{storeHash}/customers/{jwtToken}/recently_purchased.html
* Fetches the "Recently Purchased Products" HTML block and displays it in the frontend.
Expand Down Expand Up @@ -174,7 +188,7 @@ function getAuthToken($storeHash)
}

/**
* @param string $jwtToken customer's JWT token sent from the storefront.
* @param string $jwtToken customer's JWT token sent from the storefront.
* @return string customer's ID decoded and verified
*/
function getCustomerIdFromToken($jwtToken)
Expand Down

0 comments on commit 326295d

Please sign in to comment.