TYPO3 CMS  TYPO3_7-6
AjaxLoginHandler.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Backend;
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  */
16 
20 
25 {
37  public function loginAction(ServerRequestInterface $request, ResponseInterface $response)
38  {
39  if ($this->isAuthorizedBackendSession()) {
40  $result = ['success' => true];
41  if ($this->hasLoginBeenProcessed()) {
43  $formProtection->setSessionTokenFromRegistry();
44  $formProtection->persistSessionToken();
45  }
46  } else {
47  $result = ['success' => false];
48  }
49 
50  $response->getBody()->write(json_encode(['login' => $result]));
51  return $response;
52  }
53 
61  public function logoutAction(ServerRequestInterface $request, ResponseInterface $response)
62  {
63  $backendUser = $this->getBackendUser();
64  $backendUser->logoff();
65 
66  $response->getBody()->write(json_encode([
67  'logout' => [
68  'success' => !isset($backendUser->user['uid'])
69  ]
70  ]));
71  return $response;
72  }
73 
81  public function refreshAction(ServerRequestInterface $request, ResponseInterface $response)
82  {
83  $this->getBackendUser()->checkAuthentication();
84 
85  $response->getBody()->write(json_encode([
86  'refresh' => [
87  'success' => true
88  ]
89  ]));
90  return $response;
91  }
92 
100  public function isTimedOutAction(ServerRequestInterface $request, ResponseInterface $response)
101  {
102  $session = [
103  'timed_out' => false,
104  'will_time_out' => false,
105  'locked' => false
106  ];
107  $backendUser = $this->getBackendUser();
108  if (@is_file(PATH_typo3conf . 'LOCK_BACKEND')) {
109  $session['locked'] = true;
110  } elseif (!isset($backendUser->user['uid'])) {
111  $session['timed_out'] = true;
112  } else {
113  $backendUser->fetchUserSession(true);
114  $ses_tstamp = $backendUser->user['ses_tstamp'];
115  $timeout = $backendUser->auth_timeout_field;
116  // If 120 seconds from now is later than the session timeout, we need to show the refresh dialog.
117  // 120 is somewhat arbitrary to allow for a little room during the countdown and load times, etc.
118  $session['will_time_out'] = $GLOBALS['EXEC_TIME'] >= $ses_tstamp + $timeout - 120;
119  }
120  $response->getBody()->write(json_encode(['login' => $session]));
121  return $response;
122  }
123 
129  protected function isAuthorizedBackendSession()
130  {
131  $backendUser = $this->getBackendUser();
132  return $backendUser !== null && $backendUser instanceof BackendUserAuthentication && isset($backendUser->user['uid']);
133  }
134 
140  protected function hasLoginBeenProcessed()
141  {
142  $loginFormData = $this->getBackendUser()->getLoginFormData();
143  return $loginFormData['status'] === 'login' && !empty($loginFormData['uname']) && !empty($loginFormData['uident']);
144  }
145 
149  protected function getBackendUser()
150  {
151  return isset($GLOBALS['BE_USER']) ? $GLOBALS['BE_USER'] : null;
152  }
153 }
logoutAction(ServerRequestInterface $request, ResponseInterface $response)
loginAction(ServerRequestInterface $request, ResponseInterface $response)
isTimedOutAction(ServerRequestInterface $request, ResponseInterface $response)
refreshAction(ServerRequestInterface $request, ResponseInterface $response)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']