Skip to content

Commit

Permalink
authorization flow work
Browse files Browse the repository at this point in the history
  • Loading branch information
rmahoney-bl committed Dec 4, 2016
1 parent 2488431 commit c274770
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions src/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,8 @@ private function pathDetermine($path = false, &$getModified = false)
if (substr_count($path, '?') > 0) {
$parts = explode('?', $path, 2);
parse_str($parts[1], $_GET);
$this->queryString = $parts[1];
$this->path = $parts[0];
$this->queryString = $parts[1];
$getModified = true;
}
}
Expand All @@ -296,20 +296,28 @@ public function execute(Array $callable, Array $parameters = [], Array $beforeAc
$this->filterParse($callable, $beforeActions, $afterActions, $activity);

// handle activity
$authorized = ['authorized' => true];
if (!empty($activity)) {
$userService = $this->container->get('userService');
$authorized = $userService->checkActivity($activity);
if (!$authorized['authorized']) {
$redirect = '/';
if (!empty($authorized['redirect'])) {
$redirect = $authorized['redirect'];
}
http_response_code(302);
header('Location: '. $redirect);
return false;
}
if (!$authorized['authorized']) {
// determine redirect
$redirect = '/';
if (!empty($authorized['redirect'])) {
$redirect = $authorized['redirect'];
}
header('X-Location: /authorization');
$this->response(json_encode([
'authorization' => [
'location' => $this->path . '?' . $this->queryString,
'redirect' => $redirect
]
]));
return;
}

// call each before action
foreach ($beforeActions as $before) {
if (!is_object($before[0])) {
$before[0] = new $before[0]();
Expand All @@ -326,6 +334,8 @@ public function execute(Array $callable, Array $parameters = [], Array $beforeAc
if ($this->response(call_user_func_array($callable, $parameters)) === false) {
return;
}

// call each after action
foreach ($afterActions as $after) {
if (!is_object($after[0])) {
$after[0] = new $after[0]();
Expand All @@ -335,8 +345,6 @@ public function execute(Array $callable, Array $parameters = [], Array $beforeAc
}
}
$this->purgeAfter();

return;
}

private function getJsonInput () : array
Expand Down

0 comments on commit c274770

Please sign in to comment.