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();
}