芝麻web文件管理V1.00
编辑当前文件:/home/mgatv524/cms.mgaplay.com.br/lib/Controller/Sessions.php
. */ namespace Xibo\Controller; use Carbon\Carbon; use Slim\Http\Response as Response; use Slim\Http\ServerRequest as Request; use Xibo\Factory\SessionFactory; use Xibo\Helper\DateFormatHelper; use Xibo\Storage\StorageServiceInterface; use Xibo\Support\Exception\AccessDeniedException; /** * Class Sessions * @package Xibo\Controller */ class Sessions extends Base { /** * @var StorageServiceInterface */ private $store; /** * @var SessionFactory */ private $sessionFactory; /** * Set common dependencies. * @param StorageServiceInterface $store * @param SessionFactory $sessionFactory */ public function __construct($store, $sessionFactory) { $this->store = $store; $this->sessionFactory = $sessionFactory; } /** * @param Request $request * @param Response $response * @return \Psr\Http\Message\ResponseInterface|Response * @throws \Xibo\Support\Exception\ControllerNotImplemented * @throws \Xibo\Support\Exception\GeneralException */ function displayPage(Request $request, Response $response) { $this->getState()->template = 'sessions-page'; return $this->render($request, $response); } /** * @param Request $request * @param Response $response * @return \Psr\Http\Message\ResponseInterface|Response * @throws \Xibo\Support\Exception\ControllerNotImplemented * @throws \Xibo\Support\Exception\GeneralException */ function grid(Request $request, Response $response) { $sanitizedQueryParams = $this->getSanitizer($request->getQueryParams()); $sessions = $this->sessionFactory->query($this->gridRenderSort($sanitizedQueryParams), $this->gridRenderFilter([ 'type' => $sanitizedQueryParams->getString('type'), 'fromDt' => $sanitizedQueryParams->getString('fromDt') ], $sanitizedQueryParams)); foreach ($sessions as $row) { /* @var \Xibo\Entity\Session $row */ // Normalise the date $row->lastAccessed = Carbon::createFromTimeString($row->lastAccessed)->format(DateFormatHelper::getSystemFormat()); if (!$this->isApi($request) && $this->getUser()->isSuperAdmin()) { $row->includeProperty('buttons'); if ($row->isExpired == 1) { continue; } // Edit $row->buttons[] = array( 'id' => 'sessions_button_logout', 'url' => $this->urlFor($request,'sessions.confirm.logout.form', ['id' => $row->userId]), 'text' => __('Logout') ); } } $this->getState()->template = 'grid'; $this->getState()->recordsTotal = $this->sessionFactory->countLast(); $this->getState()->setData($sessions); return $this->render($request, $response); } /** * Confirm Logout Form * @param Request $request * @param Response $response * @param $id * @return \Psr\Http\Message\ResponseInterface|Response * @throws AccessDeniedException * @throws \Xibo\Support\Exception\ControllerNotImplemented * @throws \Xibo\Support\Exception\GeneralException */ function confirmLogoutForm(Request $request, Response $response, $id) { if ($this->getUser()->userTypeId != 1) { throw new AccessDeniedException(); } $this->getState()->template = 'sessions-form-confirm-logout'; $this->getState()->setData([ 'userId' => $id, 'help' => $this->getHelp()->link('Sessions', 'Logout') ]); return $this->render($request, $response); } /** * Logout * @param Request $request * @param Response $response * @param $id * @return \Psr\Http\Message\ResponseInterface|Response * @throws AccessDeniedException * @throws \Xibo\Support\Exception\ControllerNotImplemented * @throws \Xibo\Support\Exception\GeneralException * @throws \Xibo\Support\Exception\NotFoundException */ public function logout(Request $request, Response $response, $id) { if ($this->getUser()->userTypeId != 1) { throw new AccessDeniedException(); } $this->sessionFactory->expireByUserId($id); // Return $this->getState()->hydrate([ 'message' => __('User Logged Out.') ]); return $this->render($request, $response); } }