2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2010 */
6 /* Inclusive Design Institute */
8 /* This program is free software. You can redistribute it and/or */
9 /* modify it under the terms of the GNU General Public License */
10 /* as published by the Free Software Foundation. */
11 /************************************************************************/
14 * DAO for "oauth_client_tokens" table
20 if (!defined('TR_INCLUDE_PATH')) exit;
22 require_once(TR_INCLUDE_PATH. 'classes/DAO/DAO.class.php');
24 class OAuthClientTokensDAO extends DAO {
32 * @return token id, if successful
33 * false and add error into global var $msg, if unsuccessful
36 public function Create($oauth_server_id, $token, $token_type, $token_secret, $user_id)
38 global $addslashes, $msg;
40 $missing_fields = array();
42 /* token type check */
43 if ($token_type <> 'request' && $token_type <> 'access')
45 $msg->addError('INVALID_TOKEN_TYPE');
48 if (!$msg->containsErrors())
50 /* insert into the db */
51 $sql = "INSERT INTO ".TABLE_PREFIX."oauth_client_tokens
59 VALUES (".$oauth_server_id.",
67 if (!$this->execute($sql))
69 $msg->addError('DB_NOT_UPDATED');
84 * Delete token row by token, token_type
86 * @param $token, $token_type
87 * @return true if successful, otherwise, return false
90 function deleteByTokenAndType($token, $token_type)
92 $sql = "DELETE FROM ".TABLE_PREFIX."oauth_client_tokens
93 WHERE token = '".$token."'
94 AND token_type = '".$token_type."'";
95 return $this->execute($sql);
99 * Return row by consumer
101 * @param $oauth_server_id, $token_type
103 * @author Cindy Qi Li
105 function get($oauth_server_id, $token_type)
107 $sql = "SELECT * FROM ".TABLE_PREFIX."oauth_client_tokens
108 WHERE oauth_server_id='".$oauth_server_id."'
109 AND token_type='".$token_type."'";
110 return $this->execute($sql);
114 * Return token row by consumer key, token type, token
116 * @param $consumer_key, $token_type, $token
117 * @return table rows if successful, otherwise, return false
118 * @author Cindy Qi Li
120 function getByToken($consumer_key, $token)
122 $sql = "SELECT * FROM ".TABLE_PREFIX."oauth_client_servers c, ".TABLE_PREFIX."oauth_client_tokens t
123 WHERE c.oauth_server_id = t.oauth_server_id
124 AND c.consumer_key='".$consumer_key."'
125 AND t.token = '".$token."'";
126 return $this->execute($sql);
130 * Return token row by token, token_type
132 * @param $token, $token_type
133 * @return table rows if successful, otherwise, return false
134 * @author Cindy Qi Li
136 function getByTokenAndType($token, $token_type)
138 $sql = "SELECT * FROM ".TABLE_PREFIX."oauth_client_tokens
139 WHERE token = '".$token."'
140 AND token_type = '".$token_type."'";
141 return $this->execute($sql);
145 * Return token row by consumer key, token, nounce
147 * @param $consumer_key, $token, $nounce
148 * @return table rows if successful, otherwise, return false
149 * @author Cindy Qi Li
151 function getByTokenAndNounce($consumer_key, $token, $nonce)
153 $sql = "SELECT * FROM ".TABLE_PREFIX."oauth_client_servers, c".TABLE_PREFIX."oauth_client_tokens t
154 WHERE c.oauth_server_id = t.oauth_server_id
155 AND c.consumer_key='".$consumer_key."'
156 AND t.token = '".$token."'
157 AND t.nounce = '".$nonce."'";
158 return $this->execute($sql);