TYPO3 CMS  TYPO3_7-6
BackendUserSessionRepository.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
21 
26 {
32  public function findAllActive()
33  {
34  return $this->getDatabaseConnection()->exec_SELECTgetRows(
35  'ses_id AS id, ses_userid, ses_iplock AS ip, ses_tstamp AS timestamp',
36  'be_sessions',
37  '1=1'
38  );
39  }
40 
48  public function findByBackendUser(BackendUser $backendUser)
49  {
50  $sessions = [];
51  $db = $this->getDatabaseConnection();
52  $res = $db->exec_SELECTquery(
53  'ses_id AS id, ses_iplock AS ip, ses_tstamp AS timestamp',
54  'be_sessions',
55  'ses_userid = ' . (int)$backendUser->getUid(),
56  '',
57  'ses_tstamp ASC'
58  );
59  while ($row = $db->sql_fetch_assoc($res)) {
60  $sessions[] = [
61  'id' => $row['id'],
62  'ip' => $row['ip'],
63  'timestamp' => $row['timestamp']
64  ];
65  }
66  $db->sql_free_result($res);
67  return $sessions;
68  }
69 
76  public function switchBackToOriginalUser(AbstractUserAuthentication $authentication)
77  {
78  $updateData = [
79  'ses_userid' => $authentication->user['ses_backuserid'],
80  'ses_backuserid' => 0,
81  ];
82  $db = $this->getDatabaseConnection();
83  $db->exec_UPDATEquery(
84  'be_sessions',
85  'ses_id = ' . $db->fullQuoteStr($GLOBALS['BE_USER']->id, 'be_sessions') .
86  ' AND ses_name = ' . $db->fullQuoteStr(BackendUserAuthentication::getCookieName(), 'be_sessions') .
87  ' AND ses_userid=' . (int)$GLOBALS['BE_USER']->user['uid'], $updateData
88  );
89  }
90 
94  protected function getDatabaseConnection()
95  {
96  return $GLOBALS['TYPO3_DB'];
97  }
98 }
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']