class.ajaxlogin.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 2008-2010 Christoph Koehler (christoph@webempoweredchurch.org)
00006 *  All rights reserved
00007 *
00008 *  This script is part of the TYPO3 project. The TYPO3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *  A copy is found in the textfile GPL.txt and important notices to the license
00017 *  from the author is found in LICENSE.txt distributed with these scripts.
00018 *
00019 *
00020 *  This script is distributed in the hope that it will be useful,
00021 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 *  GNU General Public License for more details.
00024 *
00025 *  This copyright notice MUST APPEAR in all copies of the script!
00026 ***************************************************************/
00027 /**
00028  * This is the ajax handler for backend login after timeout.
00029  *
00030  * @author  Christoph Koehler <christoph@webempoweredchurch.org>
00031  */
00032 class AjaxLogin {
00033 
00034     /**
00035      * Handles the actual login process, more specifically it defines the response.
00036      * The login details were sent in as part of the ajax request and automatically logged in
00037      * the user inside the init.php part of the ajax call. If that was successful, we have
00038      * a BE user and reset the timer and hide the login window.
00039      * If it was unsuccessful, we display that and show the login box again.
00040      *
00041      * @param   array       $parameters: Parameters (not used)
00042      * @param   TYPO3AJAX   $ajaxObj: The calling parent AJAX object
00043      * @return  void
00044      */
00045     public function login(array $parameters, TYPO3AJAX $ajaxObj) {
00046         if ($GLOBALS['BE_USER']->user['uid']) {
00047             $json = array('success' => TRUE);
00048         } else {
00049             $json = array('success' => FALSE);
00050         }
00051         $ajaxObj->addContent('login', $json);
00052         $ajaxObj->setContentFormat('json');
00053     }
00054 
00055     /**
00056      * Logs out the current BE user
00057      *
00058      * @param   array       $parameters: Parameters (not used)
00059      * @param   TYPO3AJAX   $ajaxObj: The calling parent AJAX object
00060      * @return  void
00061      */
00062     public function logout(array $parameters, TYPO3AJAX $ajaxObj) {
00063         $GLOBALS['BE_USER']->logoff();
00064         if($GLOBALS['BE_USER']->user['uid']) {
00065             $ajaxObj->addContent('logout', array('success' => FALSE));
00066         } else {
00067             $ajaxObj->addContent('logout', array('success' => TRUE));
00068         }
00069         $ajaxObj->setContentFormat('json');
00070     }
00071 
00072     /**
00073      * Refreshes the login without needing login information. We just refresh the session.
00074      *
00075      *
00076      * @param   array       $parameters: Parameters (not used)
00077      * @param   TYPO3AJAX   $ajaxObj: The calling parent AJAX object
00078      * @return  void
00079      */
00080     public function refreshLogin(array $parameters, TYPO3AJAX $ajaxObj) {
00081         $GLOBALS['BE_USER']->checkAuthentication();
00082         $ajaxObj->addContent('refresh', array('success' => TRUE));
00083         $ajaxObj->setContentFormat('json');
00084     }
00085 
00086 
00087     /**
00088      * Checks if the user session is expired yet
00089      *
00090      * @param   array       $parameters: Parameters (not used)
00091      * @param   TYPO3AJAX   $ajaxObj: The calling parent AJAX object
00092      * @return  void
00093      */
00094     function isTimedOut(array $parameters, TYPO3AJAX $ajaxObj) {
00095         if(is_object($GLOBALS['BE_USER'])) {
00096             $ajaxObj->setContentFormat('json');
00097             if (@is_file(PATH_typo3conf.'LOCK_BACKEND')) {
00098                 $ajaxObj->addContent('login', array('timed_out' => FALSE, 'locked' => TRUE));
00099                 $ajaxObj->setContentFormat('json');
00100             } else {
00101                 $GLOBALS['BE_USER']->fetchUserSession(TRUE);
00102                 $ses_tstamp = $GLOBALS['BE_USER']->user['ses_tstamp'];
00103                 $timeout = $GLOBALS['BE_USER']->auth_timeout_field;
00104 
00105                 // if 120 seconds from now is later than the session timeout, we need to show the refresh dialog.
00106                 // 120 is somewhat arbitrary to allow for a little room during the countdown and load times, etc.
00107                 if ($GLOBALS['EXEC_TIME'] >= $ses_tstamp + $timeout - 120) {
00108                     $ajaxObj->addContent('login', array('timed_out' => TRUE));
00109                 } else {
00110                     $ajaxObj->addContent('login', array('timed_out' => FALSE));
00111                 }
00112             }
00113         } else {
00114             $ajaxObj->addContent('login', array('success' => FALSE, 'error' => 'No BE_USER object'));
00115         }
00116     }
00117 
00118     /**
00119      * Gets a MD5 challenge.
00120      *
00121      * @param   array       $parameters: Parameters (not used)
00122      * @param   TYPO3AJAX   $parent: The calling parent AJAX object
00123      * @return  void
00124      */
00125     public function getChallenge(array $parameters, TYPO3AJAX $parent) {
00126         session_start();
00127 
00128         $_SESSION['login_challenge'] = md5(uniqid('') . getmypid());
00129 
00130         session_commit();
00131 
00132         $parent->addContent('challenge', $_SESSION['login_challenge']);
00133         $parent->setContentFormat('json');
00134     }
00135 }
00136 
00137 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/classes/class.ajaxlogin.php'])   {
00138     include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/classes/class.ajaxlogin.php']);
00139 }
00140 
00141 ?>

Generated on Sat Sep 4 04:17:13 2010 for TYPO3 API by  doxygen 1.4.7