|
@@ -7,6 +7,8 @@ use Silex\Application;
|
|
|
use Silex\ControllerCollection;
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
+use Symfony\Component\HttpFoundation\RedirectResponse;
|
|
|
+
|
|
|
|
|
|
|
|
|
* The controller for Square backend routes.
|
|
@@ -30,8 +32,8 @@ class SquareBackendController extends Base
|
|
|
|
|
|
public function addRoutes(ControllerCollection $collection)
|
|
|
{
|
|
|
- $collection->match('/', [$this, 'squareDashboard']);
|
|
|
- $collection->match('/request-oauth-token', [$this, 'oauthRequestToken']);
|
|
|
+ $collection->match('/', [$this, 'squareDashboard'])->before([$this, 'checkUserPermissions']);
|
|
|
+ $collection->match('/request-oauth-token', [$this, 'oauthRequestToken'])->before([$this, 'checkUserPermissions']);
|
|
|
return $collection;
|
|
|
}
|
|
|
|
|
@@ -78,7 +80,16 @@ class SquareBackendController extends Base
|
|
|
|
|
|
|
|
|
|
|
|
- private function getOAuthToken($authorizationCode) {
|
|
|
+ public function checkUserPermissions()
|
|
|
+ {
|
|
|
+ $currentUser = $this->app['users']->getCurrentUser();
|
|
|
+ $currentUserId = $currentUser['id'];
|
|
|
+ if (!$this->app['users']->hasRole($currentUserId, 'root') && !$this->app['users']->hasRole($currentUserId, 'admin')) {
|
|
|
+ return new RedirectResponse($this->generateUrl('dashboard'), Response::HTTP_SEE_OTHER);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private function getOAuthToken($authorizationCode) {
|
|
|
|
|
|
|
|
|
$oauthApi = new \SquareConnect\Api\OAuthApi($this->apiClient);
|