/** * Attempt to validate a user and if it fails * see if cookie is available. In case of either being a success * setup the user session details. Otherwise, do nothing but leave * it blank. */ public function validate() { if (isset($_SESSION[SESSION_NAME])) { $userData = $this->fetchUserDetails($_SESSION[SESSION_NAME]['ID'], true); // If user was deactivated since last visit to the site // forcefully log them out, and invalidate their session if ($userData['STATUS'] == 'inactive') { Session::logout(); header('Location: ' . WEB_NAME . '/'); } // Otherwise, setup the fetched userData as the // IMS_USER session $_SESSION[SESSION_NAME] = $userData; return true; } else { if (isset($_COOKIE[COOKIE_NAME])) { // Test to see if a COOKIE has been set allowing for a persistant // Login experience on repeat visits after closing the browser $cookie = json_decode($_COOKIE[COOKIE_NAME], true); if ($cookie != NULL) { if ($this->validateByCookie($cookie['UUID'], $cookie['ID'])) { return true; } } } } Session::logout(); return false; }
/** * Logout * Logout of the site by invalidating the session * and removing cookies. */ public function Logout() { lib\Session::logout(); header('Location: ' . WEB_URL . '/'); }