...
 
Commits (3)
......@@ -59,8 +59,7 @@ class Manager
$search = null,
PropagateProperties $propagateProperties = null,
ACL $acl = null
)
{
) {
$this->repository = $repository ?: new Repository();
$this->paywallReview = $paywallReview ?: new Delegates\PaywallReview();
$this->slug = $slug ?: new Delegates\Slug();
......
......@@ -7,8 +7,8 @@ namespace Minds\Core\Router\Exceptions;
class UnverifiedEmailException extends \Exception
{
public function __construct() {
public function __construct()
{
$this->message = 'You must verify your account';
}
}
......@@ -9,11 +9,13 @@ namespace Minds\Core\Router\Middleware\Kernel;
use Exception;
use Minds\Core\Di\Di;
use Minds\Core\Di\Ref as DiRef;
use Minds\Core\Router\Exceptions\UnverifiedEmailException;
use Minds\Core\Router\RegistryEntry;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Zend\Diactoros\Response\JsonResponse;
class RegistryEntryMiddleware implements MiddlewareInterface
{
......@@ -50,23 +52,32 @@ class RegistryEntryMiddleware implements MiddlewareInterface
$binding = $registryEntry->getBinding();
$parameters = $registryEntry->extract($request->getUri()->getPath());
if ($binding instanceof DiRef) {
return call_user_func(
[
Di::_()->get($binding->getProvider()),
$binding->getMethod()
],
$request
->withAttribute('parameters', $parameters)
);
} elseif (is_callable($binding)) {
return call_user_func(
$binding,
$request
->withAttribute('parameters', $parameters)
);
} else {
throw new Exception("Invalid router binding");
try {
if ($binding instanceof DiRef) {
return call_user_func(
[
Di::_()->get($binding->getProvider()),
$binding->getMethod(),
],
$request
->withAttribute('parameters', $parameters)
);
} elseif (is_callable($binding)) {
return call_user_func(
$binding,
$request
->withAttribute('parameters', $parameters)
);
} else {
throw new Exception("Invalid router binding");
}
} catch (UnverifiedEmailException $e) {
return new JsonResponse([
'status' => 'error',
'message' => $e->getMessage(),
'code' => 403,
'must_verify' => true,
], 403);
}
}
......
......@@ -162,7 +162,8 @@ class Router
header('HTTP/1.1 403 Forbidden', true, 403);
echo json_encode([
'error' => $e->getMessage(),
'status' => 'error',
'message' => $e->getMessage(),
'code' => 403,
'must_verify' => true
]);
......
......@@ -48,8 +48,7 @@ class ManagerSpec extends ObjectBehavior
Delegates\Search $search,
PropagateProperties $propagateProperties,
ACL $acl
)
{
) {
$this->beConstructedWith(
$repository,
$paywallReview,
......