/** * Sets the currently logged in user. * @param User $user The user to set. * @param string $password The password of the user, just to be sure. */ public static function setUser(User $user, $password) { // Let's first issue a new session token to null out any old forms Session::issueToken(); // Make sure the user isn't a guest and the password works if ($user == null || $user->isGuest() || !$user->isPassword($password)) { // Delete the cookies Cookie::delete('userid'); Cookie::delete('sid'); // Set the user to a guest self::$user = User::guest(); return; } // Make sure this isn't already the signed in user if (self::$user != null && self::$user->getUserId() == $user->getUserId()) { return; } // Set the cookies Cookie::set('userid', $user->getUserId()); Cookie::set('sid', $user->getCookiePassword()); // Update the user's visit times $user->updateVisitInfo(); // Let's now set the local version self::$user = $user; }