static function get($opt = null) { if (!self::$Instance) { self::$Instance = new self($opt); } return self::$Instance; }
function initialize() { $userid = (int) LoginSession::get()->check(); if (!$userid || $userid >= MANAGER_ID_MAX) { $this->setRedirect(HOME_URL); return; } }
protected function checkSession() { $userid = (int) LoginSession::get()->check(); if (!$userid) { throw new VoiceException(CommonMessages::get()->msg('NO_SESSION')); } $this->userid = $userid; }
function handle() { $this->assign('api_url', API_URL); if ($this->userid) { $playlistArray = $this->playlistDb->getUserInfos($this->userid); $this->assign("playlist_array", $playlistArray); } if ($this->memory) { $this->handleProgram(); } if (is_a($this->media, "VoiceInfo")) { $key = LoginSession::get()->getTempKey(); $apiMedia = sprintf("%smedia/%d/%s/%s.mp3", API_URL, $key->userid, $key->tempKey, $this->media->mediaid); $this->assign('media_info', $this->media); $this->assign('api_media', $apiMedia); } }
function initialize() { $path = $_SERVER['PHP_SELF']; $cells = mb_split('/', $path); $filename = array_pop($cells); $key = array_pop($cells); $userid = array_pop($cells); $file = mb_split('\\.', $filename); $mid = $file[0]; $ext = $file[1]; if ($ext != "mp3") { throw new VoiceException(self::ERROR_INVALID_FORMAT); } $_REQUEST[LoginSession::SESSION_USERID] = $userid; $_REQUEST[LoginSession::SESSION_KEY] = $key; if (!LoginSession::get()->check()) { throw new VoiceException(self::ERROR_NO_SESSION); } $this->info = MediaInfo::getInfo($mid); if (!$this->info) { throw new VoiceException(self::ERROR_NO_INFO); } }
function handle() { $command = $_REQUEST['command']; switch ($this->mode) { case self::MODE_NOT_LOGINED: if ($command != 'login') { break; } $this->user = $this->db->authorizeUser($this->user); if (!$this->user->userid) { throw new VoiceException(CommonMessages::get()->msg('LOGIN_ERROR')); } LoginSession::get()->make($this->user->userid); $this->assignHash(LoginSession::get()->getSessionArray()); $this->assign('logined', true); break; case self::MODE_LOGINED: if ($command == 'logout') { LoginSession::get()->clear(); $this->assign('logined', false); } break; } }
// all API requests will use a HTTP GET request method $apirequest = $_SERVER['REQUEST_METHOD'] == 'POST'; // if it is an API request we will load all JSON variables from the request body into $_POST since php doesn't do this automatically if ($apirequest) { $_POST = json_decode(file_get_contents('php://input'), true); // also if the POST values contained the session id and it wasn't set in the headers we will set it here if (isset($_POST['token'])) { $_COOKIE[$SESSION['tokenid']] = $_POST['token']; } } // setup db access require SCRIPTROOT . 'dbaccess.php'; $dbconnection = CreateDBConnection(); // setup login session require SCRIPTROOT . 'loginsession.php'; $session = new LoginSession(); // make sure we meet authentication requirements $requiresauthentication = isset($target['usersonly']) && $target['usersonly']; $requiresadmin = isset($target['adminsonly']) && $target['adminsonly']; $requiresguest = isset($target['guestsonly']) && $target['guestsonly']; // check if we need to be authenticated if ($requiresauthentication || $requiresadmin) { if (!$session->IsLoggedIn() || $requiresadmin && ($session->GetStatus() != AccountStatus::Admin && $session->GetStatus() != AccountStatus::Owner)) { if ($apirequest) { ErrorPage(401); } else { header('Location: ' . $routes->generate('login')); } die; } } else {
protected function assignSession() { $this->assignHash(LoginSession::get()->getSessionArray()); }