TYPO3 CMS  TYPO3_6-2
BackendUserController.php
Go to the documentation of this file.
1 <?php
3 
17 
24 
28  protected $moduleData;
29 
35 
41 
47 
53 
62  public function processRequest(\TYPO3\CMS\Extbase\Mvc\RequestInterface $request, \TYPO3\CMS\Extbase\Mvc\ResponseInterface $response) {
63  $this->moduleData = $this->moduleDataStorageService->loadModuleData();
64  // We "finally" persist the module data.
65  try {
66  parent::processRequest($request, $response);
67  $this->moduleDataStorageService->persistModuleData($this->moduleData);
68  } catch (\TYPO3\CMS\Extbase\Mvc\Exception\StopActionException $e) {
69  $this->moduleDataStorageService->persistModuleData($this->moduleData);
70  throw $e;
71  }
72  }
73 
80  public function initializeAction() {
81  // @TODO: Extbase backend modules relies on frontend TypoScript for view, persistence
82  // and settings. Thus, we need a TypoScript root template, that then loads the
83  // ext_typoscript_setup.txt file of this module. This is nasty, but can not be
84  // circumvented until there is a better solution in extbase.
85  // For now we throw an exception if no settings are detected.
86  if (empty($this->settings)) {
87  throw new \RuntimeException('No settings detected. This module can not work then. This usually happens if there is no frontend TypoScript template with root flag set. ' . 'Please create a frontend page with a TypoScript root template.', 1344375003);
88  }
89  }
90 
98  public function indexAction(\TYPO3\CMS\Beuser\Domain\Model\Demand $demand = NULL) {
99  if ($demand === NULL) {
100  $demand = $this->moduleData->getDemand();
101  } else {
102  $this->moduleData->setDemand($demand);
103  }
104  // Switch user permanently or only until logout
105  if (\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('SwitchUser')) {
106  $this->switchUser(
107  \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('SwitchUser'),
108  \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('switchBackUser')
109  );
110  }
111  $compareUserList = $this->moduleData->getCompareUserList();
112  $this->view->assign('demand', $demand);
113  $this->view->assign('returnUrl', rawurlencode(BackendUtility::getModuleUrl('system_BeuserTxBeuser')));
114  $this->view->assign('dateFormat', $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy']);
115  $this->view->assign('timeFormat', $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm']);
116  $this->view->assign('backendUsers', $this->backendUserRepository->findDemanded($demand));
117  $this->view->assign('backendUserGroups', array_merge(array(''), $this->backendUserGroupRepository->findAll()->toArray()));
118  $this->view->assign('compareUserList', !empty($compareUserList) ? $this->backendUserRepository->findByUidList($compareUserList) : '');
119  }
120 
126  public function onlineAction() {
127  $onlineUsersAndSessions = array();
128  $onlineUsers = $this->backendUserRepository->findOnline();
129  foreach ($onlineUsers as $onlineUser) {
130  $onlineUsersAndSessions[] = array(
131  'backendUser' => $onlineUser,
132  'sessions' => $this->backendUserSessionRepository->findByBackendUser($onlineUser)
133  );
134  }
135  $this->view->assign('dateFormat', $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy']);
136  $this->view->assign('timeFormat', $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm']);
137  $this->view->assign('onlineUsersAndSessions', $onlineUsersAndSessions);
138  $this->view->assign('currentSessionId', $GLOBALS['BE_USER']->user['ses_id']);
139  }
140 
146  public function compareAction() {
147  $compareUserList = $this->moduleData->getCompareUserList();
148  $this->view->assign('dateFormat', $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy']);
149  $this->view->assign('timeFormat', $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm']);
150  $this->view->assign('compareUserList', !empty($compareUserList) ? $this->backendUserRepository->findByUidList($compareUserList) : '');
151  }
152 
159  public function addToCompareListAction($uid) {
160  $this->moduleData->attachUidCompareUser($uid);
161  $this->moduleDataStorageService->persistModuleData($this->moduleData);
162  $this->forward('index');
163  }
164 
172  $this->moduleData->detachUidCompareUser($uid);
173  $this->moduleDataStorageService->persistModuleData($this->moduleData);
174  $this->forward('index');
175  }
176 
185  protected function terminateBackendUserSessionAction(\TYPO3\CMS\Beuser\Domain\Model\BackendUser $backendUser, $sessionId) {
186  $GLOBALS['TYPO3_DB']->exec_DELETEquery(
187  'be_sessions',
188  'ses_userid = "' . (int)$backendUser->getUid() . '" AND ses_id = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($sessionId, 'be_sessions') . ' LIMIT 1'
189  );
190  if ($GLOBALS['TYPO3_DB']->sql_affected_rows() == 1) {
191  $message = 'Session successfully terminated.';
192  $this->flashMessageContainer->add($message, '', \TYPO3\CMS\Core\Messaging\FlashMessage::OK);
193  }
194  $this->forward('online');
195  }
196 
204  protected function switchUser($switchUser, $switchBack = FALSE) {
205  $targetUser = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecord('be_users', $switchUser);
206  if (is_array($targetUser) && $GLOBALS['BE_USER']->isAdmin()) {
207  $updateData['ses_userid'] = $targetUser['uid'];
208  // User switchback or replace current session?
209  if ($switchBack) {
210  $updateData['ses_backuserid'] = (int)$GLOBALS['BE_USER']->user['uid'];
211 
212  // Set backend user listing module as starting module for switchback
213  $GLOBALS['BE_USER']->uc['startModuleOnFirstLogin'] = 'system_BeuserTxBeuser';
214  $GLOBALS['BE_USER']->writeUC();
215  }
216 
217  $whereClause = 'ses_id=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($GLOBALS['BE_USER']->id, 'be_sessions');
218  $whereClause .= ' AND ses_name=' . $GLOBALS['TYPO3_DB']->fullQuoteStr(\TYPO3\CMS\Core\Authentication\BackendUserAuthentication::getCookieName(), 'be_sessions');
219  $whereClause .= ' AND ses_userid=' . (int)$GLOBALS['BE_USER']->user['uid'];
220 
221  $GLOBALS['TYPO3_DB']->exec_UPDATEquery(
222  'be_sessions',
223  $whereClause,
224  $updateData
225  );
226 
227  $redirectUrl = $GLOBALS['BACK_PATH'] . 'index.php' . ($GLOBALS['TYPO3_CONF_VARS']['BE']['interfaces'] ? '' : '?commandLI=1');
229  }
230  }
231 
232 }
indexAction(\TYPO3\CMS\Beuser\Domain\Model\Demand $demand=NULL)
processRequest(\TYPO3\CMS\Extbase\Mvc\RequestInterface $request, \TYPO3\CMS\Extbase\Mvc\ResponseInterface $response)
$uid
Definition: server.php:36
forward($actionName, $controllerName=NULL, $extensionName=NULL, array $arguments=NULL)
static getModuleUrl($moduleName, $urlParameters=array(), $backPathOverride=FALSE, $returnAbsoluteUrl=FALSE)
static redirect($url, $httpStatus=self::HTTP_STATUS_303)
Definition: HttpUtility.php:76
terminateBackendUserSessionAction(\TYPO3\CMS\Beuser\Domain\Model\BackendUser $backendUser, $sessionId)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]