get("user"))) { $session->set("user", $user = Identity::guest()); } // The installer cannot set a user into the session, so it just sets an id which we should // upconvert into a user. // @todo set the user name into the session instead of 2 and then use it to get the user object if ($user === 2) { $user = Instance::lookup_user_by_name("admin"); self::set_active_user($user); $session->set("user", $user); } if (!$session->get("group_ids")) { $ids = array(); foreach ($user->groups as $group) { $ids[] = $group->id; } $session->set("group_ids", $ids); } } catch (Exception $e) { try { Session::instance()->destroy(); } catch (Exception $e) { // We don't care if there was a problem destroying the session. } url::redirect(item::root()->abs_url()); } } /** * Return the array of group ids this user belongs to * * @return array */ static function group_ids_for_active_user() { return self::instance()->get("group_ids", array(1)); } /** * Return the active user. If there's no active user, return the guest user. * * @return User_Definition */ static function active_user() { // @todo (maybe) cache this object so we're not always doing session lookups. $user = self::instance()->get("user", null); if (!isset($user)) { // Don't do this as a fallback in the Session::get() call because it can trigger unnecessary // work. $user = Identity::guest(); } return $user; } /** * Change the active user. * @param User_Definition $user */ static function set_active_user($user) { $session = Session::instance(); $session->set("user", $user); $session->delete("group_ids"); self::load_user(); } }