public function token()
 {
     try {
         return new DTOAuthToken($this->db->where("token='{$this->access_token}'"));
     } catch (Exception $e) {
         DTLog::error("Could not find token: " . $e->getMessage());
     }
     return null;
 }
 public function group($itemKey, $prefix = null)
 {
     $xml = $this->request("groups/{$itemKey}", array("content" => "json"));
     try {
         $elm = new SimpleXMLElement($xml);
     } catch (Exception $e) {
         DTLog::error("Could not parse group ({$xml}): " . $e->getMessage());
         throw $e;
     }
     return json_decode($elm->content, true);
 }
 protected function sendRequestToProvider($url, $params, $method = "GET", $multipart = false)
 {
     $mtd = strtolower($method) == "get" ? "GET" : "POST";
     try {
         unset($params["tok"], $params["fmt"], $params["act"], $params["callback"]);
         $r = DTHTTPRequest::makeHTTPRequest($url, $params, $mtd);
         return $r->getResponseBody();
     } catch (OAuthException $E) {
         DTLog::error("Failed to access ({$url})");
     }
 }
 /** override the access token method to use add /oauth/ to the path */
 function oauthAccessToken()
 {
     $token = $this->requestToken();
     $secret = $this->requestTokenSecret();
     $this->oauth->setToken($this->requestToken(), $this->requestTokenSecret());
     $response = $this->oauth->getAccessToken("https://api.twitter.com/oauth/access_token");
     if (!isset($response["oauth_token"])) {
         DTLog::error("bad response from access token request: " . json_encode($response));
     }
     $this->setAccessToken($response["oauth_token"], $response["oauth_token_secret"]);
     $oauth = $this->session[$this->api["name"]];
     unset($oauth["oauth_request_token"]);
     unset($oauth["oauth_request_secret"]);
 }
 /** performs standard authentication, authorizing the relevant token if necessary */
 public function actionAuthenticate()
 {
     $u = parent::actionAuthenticate();
     if (isset($u)) {
         try {
             //update oauth token
             $tok_str = $this->params->stringParam("oauth_token");
             if (empty($tok_str)) {
                 DTLog::error("OAuth token parameter was empty.");
             }
             $token = new DTOAuthToken($this->db->where("token='{$tok_str}' AND type=0"));
             return $this->authorizeToken($token, $u);
         } catch (Exception $e) {
             DTLog::Debug("auth error: " . $e->getMessage());
         }
         //the user failed to authenticate (maybe bad user/pass)
     }
     return $u;
 }
 /**
  *	reset a password
  *	@param alias - the user to reset password for
  */
 public function actionResetPassword()
 {
     $rst = $this->params->stringParam("rst");
     $user_id = $this->params->stringParam("user_id");
     try {
         $t = new DTResetToken($this->db->filter(array("token" => $rst, "user_id" => $user_id, "is_valid" => 1, "expires_at" => array(">", $this->db->now()))));
         $t["is_valid"] = 0;
         //invalidate the token
         $t->clean();
         $t->update($this->db);
         $params = $this->params->allParams();
         $u = $this->castUser($this->db->filter(array("id" => $user_id, "is_active" => 1)));
         $u->clean();
         $u->merge($params);
         $u->update($this->db);
     } catch (Exception $e) {
         DTLog::error("Failed to reset password:" . $e->getMessage());
         return false;
     }
     return true;
 }
Beispiel #7
0
/**
* @desc Almacena los datos del log en la base de datos
**/
function dt_save_log($edit = 0)
{
    global $xoopsSecurity;
    $query = '';
    foreach ($_POST as $k => $v) {
        ${$k} = $v;
        if ($k == 'XOOPS_TOKEN_REQUEST' || ($k = 'action')) {
            continue;
        }
        $query = $query == '' ? $k . '=' . urlencode($v) : "&{$k}=" . urlencode($v);
    }
    //Verificamos si el software es válido
    if ($item <= 0) {
        redirectMsg('items.php', __('Download item ID not provided!', 'dtransport'), RMMSG_WARN);
    }
    //Verificamos si existe el software
    $sw = new DTSoftware($item);
    if ($sw->isNew()) {
        redirectMsg('items.php', __('Specified download item does not exists!', 'dtransport'), RMMSG_WARN);
    }
    if (!$xoopsSecurity->check()) {
        redirectMsg('logs.php?item=' . $item, __('Session token not valid!', 'dtransport'), RMMSG_ERROR);
    }
    if ($edit) {
        $action = 'action=edit';
        // Edición del registro
        if ($id <= 0) {
            redirectMsg('logs.php?item=' . $item, __('Item log ID not provided!', 'dtransport'), 1);
        }
        $lg = new DTLog($id);
        if ($lg->isNew()) {
            redirectMsg('logs.php?item=' . $item, __('Specified log does not exists!', 'dtransport'), 1);
        }
    } else {
        $action = 'action=new';
        $lg = new DTLog();
    }
    $lg->setSoftware($item);
    $lg->setTitle($title);
    $lg->setLog($log);
    $lg->setDate(time());
    if (!$lg->save()) {
        redirectMsg('logs.php?' . $query . '&' . $action, __('Item log could not be saved!', 'dtransport') . '<br />' . $lg->error(), RMMSG_ERROR);
    } else {
        redirectMsg('logs.php?item=' . $item, __('Database updated successfully!', 'dtransport'), RMMSG_SAVED);
    }
}
 /**
 	subclasses may override this method to provide custom token classes
 	@return returns the token associated with this connection
 */
 public function token()
 {
     if (!isset($this->provider, $this->provider->token)) {
         return null;
     }
     try {
         return new DTOAuthToken($this->db->where("token='{$this->provider->token}'"));
     } catch (Exception $e) {
         DTLog::error("Could not find token: " . $e->getMessage());
     }
     return null;
 }