Example #1
0
 /**
  * Execute a logged cURL request
  *
  * @param string $url URL
  * @param array $opts Array of cURL options
  * @return mixed cURL response
  * @throws \Exception
  */
 public static function logged_exec($url, array $opts = array())
 {
     $opts[CURLOPT_POST] = true;
     $opts[CURLOPT_POSTFIELDS] = array('session' => PyLoad::getInstance()->getSession());
     $opts[CURLOPT_HTTPHEADER] = array('Content-Type: multipart/form-data');
     return self::curl($url, $opts);
 }
Example #2
0
 /**
  * Login into pyLoad
  *
  * @param string $username Username
  * @param string $password Password
  * @return string Session ID
  * @throws \Exception
  */
 public function login($username, $password)
 {
     if (!is_null(PyLoad::getInstance()->getSession())) {
         return PyLoad::getInstance()->getSession();
     }
     $curl_opts[CURLOPT_POST] = true;
     $curl_opts[CURLOPT_POSTFIELDS] = array('username' => $username, 'password' => $password);
     $curl_opts[CURLOPT_HTTPHEADER] = array('Content-Type: multipart/form-data');
     $session = CURL::exec('login', $curl_opts);
     $session = str_replace('"', '', $session);
     PyLoad::getInstance()->setSession($session);
     return $session;
 }
Example #3
0
 /**
  * Check that user is authenticated
  *
  * @throws \Exception
  */
 protected function checkAuthentication()
 {
     if (is_null(PyLoad::getInstance()->getSession())) {
         throw new \Exception('You must be authenticated to access this URL');
     }
 }