*/ class LoginController { const SIGNAL_RenderLoginForm = 'renderLoginForm'; // Internal, GPvars: // GPvar: redirect_url; The URL to redirect to after login. /** * @todo Define visibility */ public $redirect_url; // GPvar: Defines which interface to load (from interface selector) /** * @todo Define visibility */ public $GPinterface; // GPvar: preset username /** * @todo Define visibility */ public $u; // GPvar: preset password /** * @todo Define visibility */ public $p; // GPvar: If "L" is "OUT", then any logged in used is logged out. If redirect_url is given, we redirect to it /** * @todo Define visibility */ public $L; // Login-refresh boolean; The backend will call this script with this value set when the login is close to being expired and the form needs to be redrawn. /** * @todo Define visibility */ public $loginRefresh; // Value of forms submit button for login. /** * @todo Define visibility */ public $commandLI; // Internal, static: // Set to the redirect URL of the form (may be redirect_url or "backend.php") /** * @todo Define visibility */ public $redirectToURL; // Internal, dynamic: // Content accumulation /** * @todo Define visibility */ public $content; // A selector box for selecting value for "interface" may be rendered into this variable /** * @todo Define visibility */ public $interfaceSelector; // A selector box for selecting value for "interface" may be rendered into this variable // this will have an onchange action which will redirect the user to the selected interface right away /** * @todo Define visibility */ public $interfaceSelector_jump; // A hidden field, if the interface is not set. /** * @todo Define visibility */ public $interfaceSelector_hidden; // Additional hidden fields to be placed at the login form /** * @todo Define visibility */ public $addFields_hidden = ''; // sets the level of security. *'normal' = clear-text. 'challenged' = hashed // password/username from form in $formfield_uident. 'superchallenged' = hashed password hashed again with username. /** * @todo Define visibility */ public $loginSecurityLevel = 'superchallenged'; /** * @var \TYPO3\CMS\Extbase\SignalSlot\Dispatcher */ protected $signalSlotDispatcher; /** * Initialize the login box. Will also react on a &L=OUT flag and exit. * * @return void * @todo Define visibility */ public function init() { // We need a PHP session session for most login levels session_start(); $this->redirect_url = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('redirect_url')); $this->GPinterface = GeneralUtility::_GP('interface'); // Grabbing preset username and password, for security reasons this feature only works if SSL is used if (GeneralUtility::getIndpEnv('TYPO3_SSL')) { $this->u = GeneralUtility::_GP('u'); $this->p = GeneralUtility::_GP('p'); } // If "L" is "OUT", then any logged in is logged out. If redirect_url is given, we redirect to it $this->L = GeneralUtility::_GP('L'); // Login $this->loginRefresh = GeneralUtility::_GP('loginRefresh'); // Value of "Login" button. If set, the login button was pressed. $this->commandLI = GeneralUtility::_GP('commandLI'); // Sets the level of security from conf vars if ($GLOBALS['TYPO3_CONF_VARS']['BE']['loginSecurityLevel']) { $this->loginSecurityLevel = $GLOBALS['TYPO3_CONF_VARS']['BE']['loginSecurityLevel']; } // Try to get the preferred browser language $preferredBrowserLanguage = $GLOBALS['LANG']->csConvObj->getPreferredClientLanguage(GeneralUtility::getIndpEnv('HTTP_ACCEPT_LANGUAGE')); // If we found a $preferredBrowserLanguage and it is not the default language and no be_user is logged in // initialize $GLOBALS['LANG'] again with $preferredBrowserLanguage if ($preferredBrowserLanguage != 'default' && !$GLOBALS['BE_USER']->user['uid']) { $GLOBALS['LANG']->init($preferredBrowserLanguage); } $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_login.xlf'); // Setting the redirect URL to "backend.php" if no alternative input is given $this->redirectToURL = $this->redirect_url ? $this->redirect_url : 'backend.php'; // Do a logout if the command is set if ($this->L == 'OUT' && is_object($GLOBALS['BE_USER'])) { $GLOBALS['BE_USER']->logoff(); if ($this->redirect_url) { HttpUtility::redirect($this->redirect_url); } die; } } /** * Main function - creating the login/logout form * * @return void * @todo Define visibility */ public function main() { // Initialize template object: $GLOBALS['TBE_TEMPLATE']->bodyTagAdditions = ' onload="startUp();"'; $GLOBALS['TBE_TEMPLATE']->moduleTemplate = $GLOBALS['TBE_TEMPLATE']->getHtmlTemplate('EXT:backend/Resources/Private/Templates/login.html'); $GLOBALS['TBE_TEMPLATE']->getPageRenderer()->loadExtJS(); $GLOBALS['TBE_TEMPLATE']->getPageRenderer()->loadPrototype(); $GLOBALS['TBE_TEMPLATE']->getPageRenderer()->loadScriptaculous(); // Set JavaScript for creating a MD5 hash of the password: $GLOBALS['TBE_TEMPLATE']->JScode .= $this->getJScode(); // Checking, if we should make a redirect. // Might set JavaScript in the header to close window. $this->checkRedirect(); // Initialize interface selectors: $this->makeInterfaceSelectorBox(); // Creating form based on whether there is a login or not: if (!$GLOBALS['BE_USER']->user['uid']) { $GLOBALS['TBE_TEMPLATE']->form = $this->startForm(); $loginForm = $this->makeLoginForm(); } else { $GLOBALS['TBE_TEMPLATE']->form = '
'; $loginForm = $this->makeLogoutForm(); } // Starting page: $this->content .= $GLOBALS['TBE_TEMPLATE']->startPage('TYPO3 Login: ' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'], FALSE); // Add login form: $this->content .= $this->wrapLoginForm($loginForm); $this->content .= $GLOBALS['TBE_TEMPLATE']->endPage(); } /** * Outputting the accumulated content to screen * * @return void * @todo Define visibility */ public function printContent() { echo $this->content; } /***************************** * * Various functions * ******************************/ /** * Creates the login form * This is drawn when NO login exists. * * @return string HTML output * @todo Define visibility */ public function makeLoginForm() { $content = HtmlParser::getSubpart($GLOBALS['TBE_TEMPLATE']->moduleTemplate, '###LOGIN_FORM###'); $markers = array( 'VALUE_USERNAME' => htmlspecialchars($this->u), 'VALUE_PASSWORD' => htmlspecialchars($this->p), 'VALUE_SUBMIT' => $GLOBALS['LANG']->getLL('labels.submitLogin', TRUE) ); // Show an error message if the login command was successful already, otherwise remove the subpart if (!$this->isLoginInProgress()) { $content = HtmlParser::substituteSubpart($content, '###LOGIN_ERROR###', ''); } else { $markers['ERROR_MESSAGE'] = $GLOBALS['LANG']->getLL('error.login', TRUE); $markers['ERROR_LOGIN_TITLE'] = $GLOBALS['LANG']->getLL('error.login.title', TRUE); $markers['ERROR_LOGIN_DESCRIPTION'] = $GLOBALS['LANG']->getLL('error.login.description', TRUE); } // Remove the interface selector markers if it's not available if (!($this->interfaceSelector && !$this->loginRefresh)) { $content = HtmlParser::substituteSubpart($content, '###INTERFACE_SELECTOR###', ''); } else { $markers['LABEL_INTERFACE'] = $GLOBALS['LANG']->getLL('labels.interface', TRUE); $markers['VALUE_INTERFACE'] = $this->interfaceSelector; } return HtmlParser::substituteMarkerArray($content, $markers, '###|###'); } /** * Creates the logout form * This is drawn if a user login already exists. * * @return string HTML output * @todo Define visibility */ public function makeLogoutForm() { $content = HtmlParser::getSubpart($GLOBALS['TBE_TEMPLATE']->moduleTemplate, '###LOGOUT_FORM###'); $markers = array( 'LABEL_USERNAME' => $GLOBALS['LANG']->getLL('labels.username', TRUE), 'VALUE_USERNAME' => htmlspecialchars($GLOBALS['BE_USER']->user['username']), 'VALUE_SUBMIT' => $GLOBALS['LANG']->getLL('labels.submitLogout', TRUE) ); // Remove the interface selector markers if it's not available if (!$this->interfaceSelector_jump) { $content = HtmlParser::substituteSubpart($content, '###INTERFACE_SELECTOR###', ''); } else { $markers['LABEL_INTERFACE'] = $GLOBALS['LANG']->getLL('labels.interface', TRUE); $markers['VALUE_INTERFACE'] = $this->interfaceSelector_jump; } return HtmlParser::substituteMarkerArray($content, $markers, '###|###'); } /** * Wrapping the login form table in another set of tables etc: * * @param string $content HTML content for the login form * @return string The HTML for the page. * @todo Define visibility */ public function wrapLoginForm($content) { $mainContent = HtmlParser::getSubpart($GLOBALS['TBE_TEMPLATE']->moduleTemplate, '###PAGE###'); if ($GLOBALS['TBE_STYLES']['logo_login']) { $logo = ''; } else { $logo = '