File: access_token_api.php

package info (click to toggle)
fusionforge 5.3.2%2B20141104-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 60,472 kB
  • sloc: php: 271,846; sql: 36,817; python: 14,575; perl: 6,406; sh: 5,980; xml: 4,294; pascal: 1,411; makefile: 911; cpp: 52; awk: 27
file content (110 lines) | stat: -rw-r--r-- 2,930 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
require_once 'OAuth.php';

class OAuthAccessToken extends OAuthToken {

	protected $id;
	protected $provider_id;
	protected $user_id;
	protected $time_stamp;

	function __construct( $provider_id, $key, $secret, $user_id, $time_stamp=null, $id=0) {
		parent::__construct($key, $secret);
		$this->id = $id;
		$this->provider_id = $provider_id;
		$this->user_id = $user_id;
		$this->time_stamp = $time_stamp;
	}

	public function get_id()	{
		return $this->id;
	}

	public function set_id($id) 	{
		$this->id = $id;
	}

	public function get_provider_id()	{
		return $this->provider_id;
	}

	public function get_token_key() {
		return $this->key;
	}

	public function get_token_secret() {
		return $this->secret;
	}

	public function get_user_id() {
		return $this->user_id;
	}

	public function get_time_stamp() {
		return $this->time_stamp;
	}

	static function convert_row_to_object($row)	{
		if($row!=null)	{
			$access_token = new OAuthAccessToken($row['provider_id'], $row['token_key'], $row['token_secret'], $row['user_id'], $row['time_stamp'], $row['id']);
			return $access_token;
		}else {
			return null;
		}
	}

	static function get_access_token($id) {
		$conn = FFOAuthDataStore::singleton();
		$row = $conn->find_token_from_id($id);
		$access_token = self::convert_row_to_object($row);
		return $access_token;
	}

	static function get_all_access_tokens($user_id) {
		$conn = FFOAuthDataStore::singleton();
		$rows = $conn->find_all_access_tokens($user_id);
		$access_tokens = array();
		foreach ($rows as $row)	{
			$access_token = OAuthAccessToken::convert_row_to_object($row);
			$access_tokens[] = $access_token;
		}
		return $access_tokens;
	}

	static function get_all_access_tokens_by_provider($provider_id, $user_id) {
		$conn = FFOAuthDataStore::singleton();
		$rows = $conn->find_access_tokens_by_provider($provider_id, $user_id);
		$access_tokens = array();
		foreach ($rows as $row)	{
			$access_token = OAuthAccessToken::convert_row_to_object($row);
			$access_tokens[] = $access_token;
		}
		return $access_tokens;
	}

	function write_to_db() {
		if ( strlen(trim( $this->get_provider_id() ))==0 || strlen(trim( $this->get_user_id() ))==0 || strlen(trim( $this->get_token_key() ))==0 || strlen(trim( $this->get_token_secret() ))==0 ) {
			exit_error( "Error trying to add the access token. Some required parameters are not set.", 'oauthconsumer' );
		}
		$conn = FFOAuthDataStore::singleton();
		$id = $conn->save_access_token($this);
		if(!$id)	{
			exit_error("Error trying to add access token to DB", 'oauthconsumer');
		}else {
			$this->set_id($id);
		}
	}

	function delete()	{
		$conn = FFOAuthDataStore::singleton();
		$id = $this->get_id();
		if($id!=0)	{
			if(!($conn->delete_access_token($id)))	{
				exit_error("Error trying to delete access token from DB", 'oauthconsumer');
			}
		}else 	{
			exit_error("Trying to delete non-existent access token from DB", 'oauthconsumer');
		}
	}

}