Fixed bug #11831: Remove reference operators for objects
[Packages/TYPO3.CMS.git] / typo3 / classes / class.ajaxlogin.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2008-2009 Christoph Koehler (christoph@webempoweredchurch.org)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * This is the ajax handler for backend login after timeout.
29 *
30 * @author Christoph Koehler <christoph@webempoweredchurch.org>
31 */
32 class AjaxLogin {
33
34 /**
35 * Handles the actual login process, more specifically it defines the response.
36 * The login details were sent in as part of the ajax request and automatically logged in
37 * the user inside the init.php part of the ajax call. If that was successful, we have
38 * a BE user and reset the timer and hide the login window.
39 * If it was unsuccessful, we display that and show the login box again.
40 *
41 * @param string $params Always empty.
42 * @param string $ajaxObj The Ajax object used to return content and set content types
43 * @return void
44 */
45 public function login($params = array(), TYPO3AJAX &$ajaxObj = null) {
46 if ($GLOBALS['BE_USER']->user['uid']) {
47 $json = '{success: true}';
48 } else {
49 $json = '{success: false}';
50 }
51 $ajaxObj->addContent('login', $json);
52 }
53
54 /**
55 * Logs out the current BE user
56 *
57 * @param string $params Always empty.
58 * @param string $TYPO3AJAX The Ajax object used to return content and set content types
59 * @return void
60 */
61 public function logout($params = array(), TYPO3AJAX &$ajaxObj = null) {
62 $GLOBALS['BE_USER']->logoff();
63 if($GLOBALS['BE_USER']->user['uid']) {
64 $ajaxObj->addContent('logout', '{sucess: false}');
65 } else {
66 $ajaxObj->addContent('logout', '{sucess: true}');
67 }
68 }
69
70 /**
71 * Refreshes the login without needing login information. We just refresh the session.
72 *
73 *
74 * @param string $params Always empty.
75 * @param string $ajaxObj The Ajax object used to return content and set content types
76 * @return void
77 */
78 public function refreshLogin($params = array(), TYPO3AJAX &$ajaxObj = null) {
79 $GLOBALS['BE_USER']->checkAuthentication();
80 $ajaxObj->addContent('refresh', '{sucess: true}');
81 }
82
83
84 /**
85 * Checks if the user session is expired yet
86 *
87 * @param string $params Always empty.
88 * @param string $TYPO3AJAX The Ajax object used to return content and set content types
89 * @return void
90 */
91 function isTimedOut($params = array(), TYPO3AJAX &$ajaxObj = null) {
92 if(is_object($GLOBALS['BE_USER'])) {
93
94 if (@is_file(PATH_typo3conf.'LOCK_BACKEND')) {
95 $ajaxObj->addContent('login', '{timed_out: false,locked:true}');
96 $ajaxObj->setContentFormat('json');
97 } else {
98 $GLOBALS['BE_USER']->fetchUserSession(true);
99 $ses_tstamp = $GLOBALS['BE_USER']->user['ses_tstamp'];
100 $timeout = $GLOBALS['BE_USER']->auth_timeout_field;
101
102 // if 120 seconds from now is later than the session timeout, we need to show the refresh dialog.
103 // 120 is somewhat arbitrary to allow for a little room during the countdown and load times, etc.
104 if($GLOBALS['EXEC_TIME'] >= $ses_tstamp+$timeout-120) {
105 $ajaxObj->addContent('login', '{timed_out: true}');
106 $ajaxObj->setContentFormat('json');
107 } else {
108 $ajaxObj->addContent('login', '{timed_out: false}');
109 $ajaxObj->setContentFormat('json');
110 }
111 }
112 } else {
113 $ajaxObj->addContent('login', '{success: false, error: "No BE_USER object"}');
114 }
115 }
116 }
117
118 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/classes/class.ajaxlogin.php']) {
119 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/classes/class.ajaxlogin.php']);
120 }
121
122 ?>