require_once 'includes/classes/FormLogin.php'; $loginForm = new FormLogin(); use libAllure\Session; // In case of redirect... ob_start(); global $db; if (Session::isLoggedIn()) { if (isset($_REQUEST['redirect'])) { redirect($_REQUEST['redirect'], 'You are being redirected, hang tight!'); } else { redirect('index.php', 'You are already logged in!'); } require_once 'includes/widgets/footer.php'; } if (isset($_REQUEST['username'])) { $loginForm->getElement('username')->setValue(filter_var($_REQUEST['username'], FILTER_SANITIZE_STRING)); } if ($loginForm->validate()) { $username = $loginForm->getElementValue('username'); $password = $loginForm->getElementValue('password'); try { Session::checkCredentials($username, $password); applyAchievements(); logActivity('Logged in'); redirect('index.php', 'You have sucessfully logged in.'); } catch (\libAllure\UserNotFoundException $e) { $loginForm->setElementError('username', 'User not found.'); } catch (\libAllure\IncorrectPasswordException $e) { $loginForm->setElementError('password', 'Incorrect password.'); } catch (Exception $e) { $loginForm->setGeneralError('Failed to login because of a system problem.');
try { $username = $f->getElementValue('username'); Session::checkCredentials($username, $f->getElementValue('password')); setcookie('mylocation', Session::getUseR()->getData('location')); redirect('index.php', 'You have logged in.'); } catch (IncorrectPasswordException $e) { Logger::messageNormal('Failed login for ' . $username . ', password wrong.', LocalEventType::LOGIN_FAILURE_PASSWORD); $f->setElementError('password', 'Password wrong.'); } catch (UserNotFoundException $e) { Logger::messageNormal('Failed login for ' . $username . ', nonexistant user.', LocalEventType::LOGIN_FAILURE_USERNAME); $f->setElementError('username', 'User not found'); } } else { if (isset($_GET['formLogin-username'])) { $username = htmlentities($_GET['formLogin-username']); $f->getElement('username')->setValue($username); } } if (Session::isLoggedIn()) { redirect('index.php', 'You are already logged in!'); } define('TITLE', 'Login to, or Register an account'); require_once 'includes/widgets/header.php'; echo '<div class = "paralellContainer">'; $f->display(); echo '</div>'; echo '<div class = "paralellContainer">'; $fRegister->display(); echo '</div>'; startSidebar(); ?>