@@ 21-64 (lines=44) @@ | ||
18 | ||
19 | $lastPostId = ''; |
|
20 | ||
21 | function isTokenFresh(Location $location) |
|
22 | { |
|
23 | $db = new DatabaseConnect(); |
|
24 | $result = $db->query("SELECT * FROM accounts WHERE id='1'"); |
|
25 | ||
26 | if ($result->num_rows > 0) |
|
27 | { |
|
28 | // output data of each row |
|
29 | while($row = $result->fetch_assoc()) { |
|
30 | //$access_token = $row["access_token"]; |
|
31 | $expiration_date = $row["expiration_date"]; |
|
32 | $deviceUid = $row["device_uid"]; |
|
33 | $access_token = $row["access_token"]; |
|
34 | } |
|
35 | } |
|
36 | else |
|
37 | { |
|
38 | echo '0 results'; |
|
39 | } |
|
40 | ||
41 | if($expiration_date <= time()) { |
|
42 | $accountCreator = new CreateUser(); |
|
43 | $accountCreator->setAccessToken($access_token);//$accountData->getAccessToken()); |
|
44 | $accountCreator->setDeviceUid($deviceUid); |
|
45 | $accountCreator->setLocation($location); |
|
46 | $data = $accountCreator->execute(); |
|
47 | ||
48 | $access_token = (string)$data[0]['access_token']; |
|
49 | $expiration_date = $data[0]['expiration_date']; |
|
50 | $device_uid = (string)$data[1]; |
|
51 | ||
52 | $db = new DatabaseConnect(); |
|
53 | $result = $db->query("UPDATE accounts |
|
54 | SET access_token='" . $access_token . "', |
|
55 | expiration_date='" . $expiration_date . "' |
|
56 | WHERE device_uid='" . $device_uid . "'"); |
|
57 | ||
58 | if($result === false){ |
|
59 | echo "Adding account failed: (" . $db->errno . ") " . $db->error; |
|
60 | } |
|
61 | } |
|
62 | ||
63 | return TRUE; |
|
64 | } |
|
65 | ||
66 | function isTokenFreshByAccessToken(Location $location, $accessToken) |
|
67 | { |
|
@@ 66-109 (lines=44) @@ | ||
63 | return TRUE; |
|
64 | } |
|
65 | ||
66 | function isTokenFreshByAccessToken(Location $location, $accessToken) |
|
67 | { |
|
68 | $db = new DatabaseConnect(); |
|
69 | $result = $db->query("SELECT * FROM accounts WHERE access_token='" . $accessToken . "'"); |
|
70 | ||
71 | if ($result->num_rows > 0) |
|
72 | { |
|
73 | // output data of each row |
|
74 | while($row = $result->fetch_assoc()) { |
|
75 | //$access_token = $row["access_token"]; |
|
76 | $expiration_date = $row["expiration_date"]; |
|
77 | $deviceUid = $row["device_uid"]; |
|
78 | $access_token = $row["access_token"]; |
|
79 | } |
|
80 | } |
|
81 | else |
|
82 | { |
|
83 | echo '0 results'; |
|
84 | } |
|
85 | ||
86 | if($expiration_date <= time()) { |
|
87 | $accountCreator = new CreateUser(); |
|
88 | $accountCreator->setAccessToken($access_token);//$accountData->getAccessToken()); |
|
89 | $accountCreator->setDeviceUid($deviceUid); |
|
90 | $accountCreator->setLocation($location); |
|
91 | $data = $accountCreator->execute(); |
|
92 | ||
93 | $access_token = (string)$data[0]['access_token']; |
|
94 | $expiration_date = $data[0]['expiration_date']; |
|
95 | $device_uid = (string)$data[1]; |
|
96 | ||
97 | $db = new DatabaseConnect(); |
|
98 | $result = $db->query("UPDATE accounts |
|
99 | SET access_token='" . $access_token . "', |
|
100 | expiration_date='" . $expiration_date . "' |
|
101 | WHERE device_uid='" . $device_uid . "'"); |
|
102 | ||
103 | if($result === false){ |
|
104 | echo "Adding account failed: (" . $db->errno . ") " . $db->error; |
|
105 | } |
|
106 | } |
|
107 | ||
108 | return TRUE; |
|
109 | } |
|
110 | ||
111 | function getKarma($accessToken) |
|
112 | { |