From 92b7dd3335a6572debeacfb5faa82c63a5e67888 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Fri, 8 Jun 2018 20:03:25 +0200 Subject: Some minor fixes --- .../admin/src/Controller/AdminController.php | 296 ++++++++++----------- 1 file changed, 148 insertions(+), 148 deletions(-) (limited to 'main/app/sprinkles/admin/src/Controller/AdminController.php') diff --git a/main/app/sprinkles/admin/src/Controller/AdminController.php b/main/app/sprinkles/admin/src/Controller/AdminController.php index 91342de..7e4e2f0 100644 --- a/main/app/sprinkles/admin/src/Controller/AdminController.php +++ b/main/app/sprinkles/admin/src/Controller/AdminController.php @@ -1,148 +1,148 @@ -ci->authorizer; - - /** @var UserFrosting\Sprinkle\Account\Database\Models\User $currentUser */ - $currentUser = $this->ci->currentUser; - - // Access-controlled page - if (!$authorizer->checkAccess($currentUser, 'uri_dashboard')) { - throw new ForbiddenException(); - } - - /** @var UserFrosting\Sprinkle\Core\Util\ClassMapper $classMapper */ - $classMapper = $this->ci->classMapper; - - // Probably a better way to do this - $users = $classMapper->staticMethod('user', 'orderBy', 'created_at', 'desc') - ->take(8) - ->get(); - - // Transform the `create_at` date in "x days ago" type of string - $users->transform(function ($item, $key) { - $item->registered = Carbon::parse($item->created_at)->diffForHumans(); - return $item; - }); - - /** @var Config $config */ - $config = $this->ci->config; - - /** @var Config $config */ - $cache = $this->ci->cache; - - // Get each sprinkle db version - $sprinkles = $this->ci->sprinkleManager->getSprinkleNames(); - - return $this->ci->view->render($response, 'pages/dashboard.html.twig', [ - 'counter' => [ - 'users' => $classMapper->staticMethod('user', 'count'), - 'roles' => $classMapper->staticMethod('role', 'count'), - 'groups' => $classMapper->staticMethod('group', 'count') - ], - 'info' => [ - 'version' => [ - 'UF' => \UserFrosting\VERSION, - 'php' => phpversion(), - 'database' => EnvironmentInfo::database() - ], - 'database' => [ - 'name' => $config['db.default.database'] - ], - 'environment' => $this->ci->environment, - 'path' => [ - 'project' => \UserFrosting\ROOT_DIR - ] - ], - 'sprinkles' => $sprinkles, - 'users' => $users - ]); - } - - /** - * Clear the site cache. - * - * This route requires authentication. - * Request type: POST - */ - public function clearCache($request, $response, $args) { - /** @var UserFrosting\Sprinkle\Account\Authorize\AuthorizationManager */ - $authorizer = $this->ci->authorizer; - - /** @var UserFrosting\Sprinkle\Account\Database\Models\User $currentUser */ - $currentUser = $this->ci->currentUser; - - // Access-controlled page - if (!$authorizer->checkAccess($currentUser, 'clear_cache')) { - throw new ForbiddenException(); - } - - // Flush cache - $this->ci->cache->flush(); - - /** @var MessageStream $ms */ - $ms = $this->ci->alerts; - - $ms->addMessageTranslated('success', 'CACHE.CLEARED'); - - return $response->withStatus(200); - } - - /** - * Renders the modal form to confirm cache deletion. - * - * This does NOT render a complete page. Instead, it renders the HTML for the modal, which can be embedded in other pages. - * This page requires authentication. - * Request type: GET - */ - public function getModalConfirmClearCache($request, $response, $args) { - /** @var UserFrosting\Sprinkle\Account\Authorize\AuthorizationManager */ - $authorizer = $this->ci->authorizer; - - /** @var UserFrosting\Sprinkle\Account\Database\Models\User $currentUser */ - $currentUser = $this->ci->currentUser; - - // Access-controlled page - if (!$authorizer->checkAccess($currentUser, 'clear_cache')) { - throw new ForbiddenException(); - } - - return $this->ci->view->render($response, 'modals/confirm-clear-cache.html.twig', [ - 'form' => [ - 'action' => 'api/dashboard/clear-cache', - ] - ]); - } -} +ci->authorizer; + + /** @var UserFrosting\Sprinkle\Account\Database\Models\User $currentUser */ + $currentUser = $this->ci->currentUser; + + // Access-controlled page + if (!$authorizer->checkAccess($currentUser, 'uri_dashboard')) { + throw new ForbiddenException(); + } + + /** @var UserFrosting\Sprinkle\Core\Util\ClassMapper $classMapper */ + $classMapper = $this->ci->classMapper; + + // Probably a better way to do this + $users = $classMapper->staticMethod('user', 'orderBy', 'created_at', 'desc') + ->take(8) + ->get(); + + // Transform the `create_at` date in "x days ago" type of string + $users->transform(function ($item, $key) { + $item->registered = Carbon::parse($item->created_at)->diffForHumans(); + return $item; + }); + + /** @var Config $config */ + $config = $this->ci->config; + + /** @var Config $config */ + $cache = $this->ci->cache; + + // Get each sprinkle db version + $sprinkles = $this->ci->sprinkleManager->getSprinkleNames(); + + return $this->ci->view->render($response, 'pages/dashboard.html.twig', [ + 'counter' => [ + 'users' => $classMapper->staticMethod('user', 'count'), + 'roles' => $classMapper->staticMethod('role', 'count'), + 'groups' => $classMapper->staticMethod('group', 'count') + ], + 'info' => [ + 'version' => [ + 'UF' => \UserFrosting\VERSION, + 'php' => phpversion(), + 'database' => EnvironmentInfo::database() + ], + 'database' => [ + 'name' => $config['db.default.database'] + ], + 'environment' => $this->ci->environment, + 'path' => [ + 'project' => \UserFrosting\ROOT_DIR + ] + ], + 'sprinkles' => $sprinkles, + 'users' => $users + ]); + } + + /** + * Clear the site cache. + * + * This route requires authentication. + * Request type: POST + */ + public function clearCache($request, $response, $args) { + /** @var UserFrosting\Sprinkle\Account\Authorize\AuthorizationManager */ + $authorizer = $this->ci->authorizer; + + /** @var UserFrosting\Sprinkle\Account\Database\Models\User $currentUser */ + $currentUser = $this->ci->currentUser; + + // Access-controlled page + if (!$authorizer->checkAccess($currentUser, 'clear_cache')) { + throw new ForbiddenException(); + } + + // Flush cache + $this->ci->cache->flush(); + + /** @var MessageStream $ms */ + $ms = $this->ci->alerts; + + $ms->addMessageTranslated('success', 'CACHE.CLEARED'); + + return $response->withStatus(200); + } + + /** + * Renders the modal form to confirm cache deletion. + * + * This does NOT render a complete page. Instead, it renders the HTML for the modal, which can be embedded in other pages. + * This page requires authentication. + * Request type: GET + */ + public function getModalConfirmClearCache($request, $response, $args) { + /** @var UserFrosting\Sprinkle\Account\Authorize\AuthorizationManager */ + $authorizer = $this->ci->authorizer; + + /** @var UserFrosting\Sprinkle\Account\Database\Models\User $currentUser */ + $currentUser = $this->ci->currentUser; + + // Access-controlled page + if (!$authorizer->checkAccess($currentUser, 'clear_cache')) { + throw new ForbiddenException(); + } + + return $this->ci->view->render($response, 'modals/confirm-clear-cache.html.twig', [ + 'form' => [ + 'action' => 'api/dashboard/clear-cache', + ] + ]); + } +} -- cgit v1.2.3