/** * Contao ImportUser Hook Implementation * * Imports a user from phpbb if login credentials match * * @param $username * @param $password * @param $scope * @return bool */ public function onImportUser($username, $password, $scope) { if ($scope == 'tl_member') { // Before we try to import a user, we must check is username is maybe = username_clean // We already now that the user could not be found by username column if (($real_username = $this->findByCleanUsername($username)) != '') { // So we found the user by it's clean username, then we overwrite the POST Value // because contao will recheck it. Input::setPost('username', $real_username); return true; } $loginResult = System::getContainer()->get('phpbb_bridge.connector')->validateLogin($username, $password); // Only import user if login to forum succeeded if ($loginResult === true) { System::log("Trying to import User: " . $username, __METHOD__, TL_ACCESS); // Try to import the user to contao (tl_member / frontend) $importResult = System::getContainer()->get('phpbb_bridge.connector')->importUser($username, $password); return $importResult; // Should usually be true } } return false; }
/** * @param array $arrClasses * @param DataContainer $dc */ protected function saveClassesToCssClass(array $arrClasses, DataContainer $dc) { $strCssClassName = $this->getCssClassName($dc->id); $strClasses = implode(' ', $arrClasses); $strClasses = str_replace(' ', ' ', $strClasses); $strClasses = trim($strClasses); $dc->activeRecord->cssClass = $strClasses; Input::setPost($strCssClassName, $strClasses); $objDatabase = Database::getInstance(); $objDatabase->prepare("UPDATE {$dc->table} SET cssClass=? WHERE id=?")->execute($strClasses, $dc->id); }
/** * Validate the widget using the value. * * @param Widget $widget The widget to validate. * * @param string|null $value The value to validate. * * @return void * * @SuppressWarnings(PHPMD.Superglobals) * @SuppressWarnings(PHPMD.CamelCaseVariableName) */ protected function validateWidget($widget, $value) { if (null === $value) { return; } $name = $widget->name; // Backup $_POST value. $keeper = Input::post($name); Input::setPost($name, $value); $widget->validate(); // Restore $_POST value. Input::setPost($name, $keeper); }
/** * @param $strNewPassword * @param null $intId */ protected function setPostPassword($strNewPassword, $intId = null) { if (Input::get('act') == 'editAll' && is_numeric($intId)) { Input::setPost('password_' . $intId, $strNewPassword); Input::setPost('password_' . $intId . '_confirm', $strNewPassword); } else { Input::setPost('password', $strNewPassword); Input::setPost('password_confirm', $strNewPassword); } }
/** * Display a login form * * @return string */ public function generate() { if (TL_MODE == 'BE') { /** @var BackendTemplate|object $objTemplate */ $objTemplate = new \BackendTemplate('be_wildcard'); $objTemplate->wildcard = '### ' . Utf8::strtoupper($GLOBALS['TL_LANG']['FMD']['login'][0]) . ' ###'; $objTemplate->title = $this->headline; $objTemplate->id = $this->id; $objTemplate->link = $this->name; $objTemplate->href = 'contao/main.php?do=themes&table=tl_module&act=edit&id=' . $this->id; return $objTemplate->parse(); } // Set the last page visited if (!$_POST && $this->redirectBack) { $_SESSION['LAST_PAGE_VISITED'] = $this->getReferer(); } // Login if (\Input::post('FORM_SUBMIT') == 'tl_login_' . $this->id) { // Check whether username and password are set if (empty($_POST['username']) || empty($_POST['password'])) { \System::getContainer()->get('session')->getFlashBag()->set($this->strFlashType, $GLOBALS['TL_LANG']['MSC']['emptyField']); $this->reload(); } $this->import('FrontendUser', 'User'); $strRedirect = \Environment::get('request'); // Redirect to the last page visited if ($this->redirectBack && $_SESSION['LAST_PAGE_VISITED'] != '') { $strRedirect = $_SESSION['LAST_PAGE_VISITED']; } else { // Redirect to the jumpTo page if ($this->jumpTo && ($objTarget = $this->objModel->getRelated('jumpTo')) instanceof PageModel) { /** @var PageModel $objTarget */ $strRedirect = $objTarget->getFrontendUrl(); } // Overwrite the jumpTo page with an individual group setting $objMember = \MemberModel::findByUsername(\Input::post('username')); if ($objMember !== null) { $arrGroups = \StringUtil::deserialize($objMember->groups); if (!empty($arrGroups) && is_array($arrGroups)) { $objGroupPage = \PageModel::findFirstActiveByMemberGroups($arrGroups); if ($objGroupPage !== null) { $strRedirect = $objGroupPage->getFrontendUrl(); } } } } // Auto login is not allowed if (isset($_POST['autologin']) && !$this->autologin) { unset($_POST['autologin']); \Input::setPost('autologin', null); } // Login and redirect if ($this->User->login()) { $this->redirect($strRedirect); } $this->reload(); } // Logout and redirect to the website root if the current page is protected if (\Input::post('FORM_SUBMIT') == 'tl_logout_' . $this->id) { /** @var PageModel $objPage */ global $objPage; $this->import('FrontendUser', 'User'); $strRedirect = \Environment::get('request'); // Redirect to last page visited if ($this->redirectBack && strlen($_SESSION['LAST_PAGE_VISITED'])) { $strRedirect = $_SESSION['LAST_PAGE_VISITED']; } elseif ($objPage->protected) { $strRedirect = \Environment::get('base'); } // Logout and redirect if ($this->User->logout()) { $this->redirect($strRedirect); } $this->reload(); } return parent::generate(); }
/** * Add the file meta information to the request * * @param string $strUuid * @param string $strPtable * @param integer $intPid */ public static function addFileMetaInformationToRequest($strUuid, $strPtable, $intPid) { $objFile = \FilesModel::findByUuid($strUuid); if ($objFile === null) { return; } $arrMeta = \StringUtil::deserialize($objFile->meta); if (empty($arrMeta)) { return; } $objPage = null; if ($strPtable == 'tl_article') { $objPage = \PageModel::findOneBy(array('tl_page.id=(SELECT pid FROM tl_article WHERE id=?)'), $intPid); } else { // HOOK: support custom modules if (isset($GLOBALS['TL_HOOKS']['addFileMetaInformationToRequest']) && is_array($GLOBALS['TL_HOOKS']['addFileMetaInformationToRequest'])) { foreach ($GLOBALS['TL_HOOKS']['addFileMetaInformationToRequest'] as $callback) { if (($val = \System::importStatic($callback[0])->{$callback[1]}($strPtable, $intPid)) !== false) { $objPage = $val; } } if ($objPage instanceof Result && $objPage->numRows < 1) { return; } if (is_object($objPage) && !$objPage instanceof PageModel) { $objPage = \PageModel::findByPk($objPage->id); } } } if ($objPage === null) { return; } $objPage->loadDetails(); // Convert the language to a locale (see #5678) $strLanguage = str_replace('-', '_', $objPage->rootLanguage); if (isset($arrMeta[$strLanguage])) { if (\Input::post('title') == '' && !empty($arrMeta[$strLanguage]['title'])) { \Input::setPost('title', $arrMeta[$strLanguage]['title']); } if (\Input::post('alt') == '' && !empty($arrMeta[$strLanguage]['alt'])) { \Input::setPost('alt', $arrMeta[$strLanguage]['alt']); } if (\Input::post('caption') == '' && !empty($arrMeta[$strLanguage]['caption'])) { \Input::setPost('caption', $arrMeta[$strLanguage]['caption']); } } }
/** * Imports a user from phpbb to contao * * @param $username * @param $password * @return bool * @throws \Exception */ public function importUser($username, $password) { if ($this->debug) { System::log("phpbb_bridge: " . __METHOD__, __METHOD__, TL_ACCESS); } // Find User in forum $user = $this->getUser($username); if ($user) { System::log('Importing User ' . $username, __METHOD__, TL_ACCESS); // Try to find user by real username if he entered username_clean // he may not be imported yet with it's clean username $contaoUser = MemberModel::findByUsername($user->username); if (null == $contaoUser) { $contaoUser = new MemberModel(); } $contaoUser->username = $user->username; $contaoUser->username_clean = $user->username_clean; $contaoUser->email = $user->user_email; $contaoUser->firstname = 'Vorname'; $contaoUser->lastname = 'Nachname'; $contaoUser->password = Encryption::hash($password); $contaoUser->login = 1; $contaoUser->tstamp = $contaoUser->dateAdded = time(); $contaoUser->groups = $this->getForumMemberGroupIds(true); // @todo add try catch, make it more safe, logout phpbb user on fail? $contaoUser->save(); System::log('User imported: ' . $contaoUser->username, __METHOD__, TL_ACCESS); // username_clean used for login if ($username != $contaoUser->username) { Input::setPost('username', $contaoUser->username); } return true; } else { System::log($username . ' could not be found in phpbb db', __METHOD__, TL_ACCESS); return false; } }
/** * Add the file meta information to the request * * @param string $strUuid * @param string $strPtable * @param integer $intPid */ public static function addFileMetaInformationToRequest($strUuid, $strPtable, $intPid) { $objFile = \FilesModel::findByUuid($strUuid); if ($objFile === null) { return; } $arrMeta = deserialize($objFile->meta); if (empty($arrMeta)) { return; } $objPage = null; $db = \Database::getInstance(); switch ($strPtable) { case 'tl_article': $objPage = $db->prepare("SELECT * FROM tl_page WHERE id=(SELECT pid FROM tl_article WHERE id=?)")->execute($intPid); break; case 'tl_news': $objPage = $db->prepare("SELECT * FROM tl_page WHERE id=(SELECT jumpTo FROM tl_news_archive WHERE id=(SELECT pid FROM tl_news WHERE id=?))")->execute($intPid); break; case 'tl_news_archive': $objPage = $db->prepare("SELECT * FROM tl_page WHERE id=(SELECT jumpTo FROM tl_news_archive WHERE id=?)")->execute($intPid); break; case 'tl_calendar_events': $objPage = $db->prepare("SELECT * FROM tl_page WHERE id=(SELECT jumpTo FROM tl_calendar WHERE id=(SELECT pid FROM tl_calendar_events WHERE id=?))")->execute($intPid); break; case 'tl_calendar': $objPage = $db->prepare("SELECT * FROM tl_page WHERE id=(SELECT jumpTo FROM tl_calendar WHERE id=?)")->execute($intPid); break; case 'tl_faq_category': $objPage = $db->prepare("SELECT * FROM tl_page WHERE id=(SELECT jumpTo FROM tl_faq_category WHERE id=?)")->execute($intPid); break; default: // HOOK: support custom modules if (isset($GLOBALS['TL_HOOKS']['addFileMetaInformationToRequest']) && is_array($GLOBALS['TL_HOOKS']['addFileMetaInformationToRequest'])) { foreach ($GLOBALS['TL_HOOKS']['addFileMetaInformationToRequest'] as $callback) { if (($val = \System::importStatic($callback[0])->{$callback[1]}($strPtable, $intPid)) !== false) { $objPage = $val; } } } break; } if ($objPage === null || $objPage->numRows < 1) { return; } $objModel = new \PageModel(); $objModel->setRow($objPage->row()); $objModel->loadDetails(); // Convert the language to a locale (see #5678) $strLanguage = str_replace('-', '_', $objModel->rootLanguage); if (isset($arrMeta[$strLanguage])) { if (\Input::post('alt') == '' && !empty($arrMeta[$strLanguage]['title'])) { \Input::setPost('alt', $arrMeta[$strLanguage]['title']); } if (\Input::post('caption') == '' && !empty($arrMeta[$strLanguage]['caption'])) { \Input::setPost('caption', $arrMeta[$strLanguage]['caption']); } } }