Esempio n. 1
0
 public function updateUserLogin($userDetails)
 {
     $sessionId = Session::getSessionId();
     $query = "UPDATE " . Users_DBTable::DB_TABLE_NAME . " SET ";
     $query .= Users_DBTable::SESSION_ID . "='" . $sessionId . "', ";
     $query .= Users_DBTable::IP_ADDRESS . "='" . $userDetails[Users_DBTable::IP_ADDRESS] . "', ";
     $query .= Users_DBTable::IS_LOGGED_IN . " = '1', ";
     $query .= Users_DBTable::LAST_LOGIN . " = '" . date('Y-m-d H:i:s') . "' WHERE ";
     $query .= Users_DBTable::USER_ID . " = '" . $userDetails[Users_DBTable::USER_ID] . "'";
     return DBManager::executeQuery($query);
 }
 /**
  * Make a request to Grooveshark.
  *
  * @param string $method The API method to use.
  * @param array $parameters Optional. Query parameters.
  * @param Session $session Optional. HTTP headers.
  *
  * @return array
  */
 public function send($method, $parameters = array(), $session)
 {
     $payload = array('method' => $method, 'parameters' => $parameters, 'header' => array('wsKey' => $session->getClientKey()));
     $sessionId = $session->getSessionId();
     if (isset($sessionId)) {
         $payload['header']['sessionID'] = $session->getSessionId();
     }
     $c = curl_init();
     $postData = json_encode($payload);
     curl_setopt($c, CURLOPT_POST, 1);
     curl_setopt($c, CURLOPT_POSTFIELDS, $postData);
     $headers = array('Expect:', 'Content-Type: application/json');
     curl_setopt($c, CURLOPT_HTTPHEADER, $headers);
     $signature = $this->createMessageSignature($postData, $session->getClientSecret());
     $url = self::API_URL . "?sig=" . $signature;
     curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($c, CURLOPT_URL, $url);
     curl_setopt($c, CURLOPT_TIMEOUT, 6);
     curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 2);
     curl_setopt($c, CURLOPT_SSL_VERIFYPEER, 0);
     curl_setopt($c, CURLOPT_USERAGENT, 'fastest963-GroovesharkAPI-PHP-' . $session->getClientKey());
     $response = curl_exec($c);
     $status = (int) curl_getinfo($c, CURLINFO_HTTP_CODE);
     curl_close($c);
     if ($status != 200) {
         throw new Exception\GroovesharkAPIException('Unexpected return code from Grooveshark API.', $httpCode);
     }
     $body = json_decode($response, true);
     if (isset($body['errors'])) {
         $error = $body['errors'][0];
         if (isset($error['message']) && isset($error['code'])) {
             throw new Exception\GroovesharkAPIException($error['message'], $error['code']);
         } else {
             throw new Exception\GroovesharkAPIException('Unknow Exception');
         }
     }
     return $body;
 }
Esempio n. 3
0
 public static function setUser($user, $remember = false)
 {
     if (!$user || !$user->is_active) {
         return Auth\Model\Guest::create(Session::getSessionId());
     }
     $session = new Session('auth');
     Session::regenerateSessionId();
     self::$currentUser = $user;
     /* if (!$user->hasRight(null, Bazalt::ACL_CAN_LOGIN)) {
            self::$currentUser = null;
            return null;
        }*/
     $user->session_id = Session::getSessionId();
     $user->updateLastActivity();
     $token = $user->getAuthorizationToken();
     $session->user_id = $user->id;
     $session->authorization_token = $token;
     $lifetime = $remember ? time() + self::getUserSessionLifetime() : 0;
     $_COOKIE['authorization_token'] = $token;
     if (!TESTING_STAGE) {
         setcookie('authorization_token', $_COOKIE['authorization_token'], $lifetime, '/', null, false, true);
     }
     return $user;
 }
Esempio n. 4
0
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param      Session $obj A Session object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool($obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getSessionId();
         }
         // if key === null
         SessionPeer::$instances[$key] = $obj;
     }
 }
Esempio n. 5
0
 /**
  * Destroy current session and delete all the data
  * if deleteCookies flag is true, then delete corresponding cookies as well
  * 
  * @param string $deleteCookies
  * @return boolean
  */
 public static function destroy($deleteCookies = true)
 {
     if ($deleteCookies) {
         if (isset($_COOKIE[session_name()])) {
             $params = session_get_cookie_params();
             // Setting cookie expiry date to '1980-01-01'
             setcookie(session_name(), false, 315554400, $params['path'], $params['domain'], $params['secure']);
         }
     }
     $isDestroyed = session_destroy();
     if ($isDestroyed) {
         self::$_isSessionRunning = false;
         Logger::getLogger()->LogDebug('Session with ID : ' . Session::getSessionId() . 'is closing');
     }
     return $isDestroyed;
 }
Esempio n. 6
0
 /**
  * Exclude object from result
  *
  * @param   Session $session Object to remove from the list of results
  *
  * @return SessionQuery The current query, for fluid interface
  */
 public function prune($session = null)
 {
     if ($session) {
         $this->addUsingAlias(SessionPeer::SESSION_ID, $session->getSessionId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }
Esempio n. 7
0
$redis->pconnect(Config::get('datasource'));
\Resque::setBackend(Config::get('datasource'));
/* GitHub Webhooks */
$app->post('/github/', function () use($app) {
    $github = new GitHubWebhook();
    $result = $github->handleEvent($app->request->headers->get('X-GitHub-Event'));
    textResponse($result['code'], $result['message']);
});
/* Authentication - Login */
$app->post('/auth/', function () use($app, $session) {
    if (!isset($_POST['machineid']) || !isset($_POST['secret'])) {
        textResponse(403, 'Authentication failed');
    } elseif (!$session->login($_POST['machineid'], $_POST['secret'])) {
        textResponse(403, 'Authentication failed');
    } else {
        jsonResponse(200, array('sessionid' => $session->getSessionId()));
    }
});
$app->get('/auth/', function () use($app) {
    textResponse(400, 'Only POST method allowed for authentication');
});
/* Jails - List all jails */
$app->get('/jails/', 'isAllowed', function () use($app) {
    $jails = new Jails();
    jsonResponse(200, $jails->getJails());
});
/* Jails - List individual jail info */
$app->get('/jails/:jailname/', 'isAllowed', function ($jailname) use($app) {
    $jails = new Jails();
    if (!$jails->exists($jailname)) {
        textResponse(404, 'Jail unknown');