/** * Checks if a user is logged in. * * @return bool True if a user is logged in, or false otherwise. */ function isLoggedIn() { $session = Session::start(); $user = getUser(); if (isset($user) && $user->loggedIn()) { return true; } elseif (isset($_COOKIE['medicutor_token'])) { $newuser = new User(); if ($newuser->loginWithToken($_COOKIE['medicutor_token'])) { $session->set('user', $newuser); makeNewToken($newuser); return true; } } return false; }
$messages[] = "Registration successful"; $session->clear('register_flag'); } if (isset($_POST['submit'])) { if ($_POST['submit'] == 'Login as guest') { $user = new User(); $user->setGuest(true); $session->set('user', $user); header("Location: index.php"); exit; } elseif (isset($_POST['username']) && isset($_POST['passwd'])) { $username = $_POST['username']; $passwd = $_POST['passwd']; $user = new User(); if ($user->login($username, $passwd)) { // Login successful, set session variables and redirect to index $session->set('user', $user); if (isset($_POST['remember_me']) && $_POST['remember_me'] == 'true') { makeNewToken($user); } header("Location: index.php"); exit; } else { $warnings[] = "Login failed"; } } else { $warnings[] = "Missing fields"; } } // Include the HTML template: require __DIR__ . '/../templates/login.php';