| @@ 21-66 (lines=46) @@ | ||
| 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 | $access_token; |
|
| 27 | ||
| 28 | if ($result->num_rows > 0) |
|
| 29 | { |
|
| 30 | // output data of each row |
|
| 31 | while($row = $result->fetch_assoc()) { |
|
| 32 | //$access_token = $row["access_token"]; |
|
| 33 | $expiration_date = $row["expiration_date"]; |
|
| 34 | $deviceUid = $row["device_uid"]; |
|
| 35 | $access_token = $row["access_token"]; |
|
| 36 | } |
|
| 37 | } |
|
| 38 | else |
|
| 39 | { |
|
| 40 | echo '0 results'; |
|
| 41 | } |
|
| 42 | ||
| 43 | if($expiration_date <= time()) { |
|
| 44 | $accountCreator = new CreateUser(); |
|
| 45 | $accountCreator->setAccessToken($access_token);//$accountData->getAccessToken()); |
|
| 46 | $accountCreator->setDeviceUid($deviceUid); |
|
| 47 | $accountCreator->setLocation($location); |
|
| 48 | $data = $accountCreator->execute(); |
|
| 49 | ||
| 50 | $access_token = (string)$data[0]['access_token']; |
|
| 51 | $expiration_date = $data[0]['expiration_date']; |
|
| 52 | $device_uid = (string)$data[1]; |
|
| 53 | ||
| 54 | $db = new DatabaseConnect(); |
|
| 55 | $result = $db->query("UPDATE accounts |
|
| 56 | SET access_token='" . $access_token . "', |
|
| 57 | expiration_date='" . $expiration_date . "' |
|
| 58 | WHERE device_uid='" . $device_uid . "'"); |
|
| 59 | ||
| 60 | if($result === false){ |
|
| 61 | echo "Adding account failed: (" . $db->errno . ") " . $db->error; |
|
| 62 | } |
|
| 63 | } |
|
| 64 | ||
| 65 | return $access_token; |
|
| 66 | } |
|
| 67 | ||
| 68 | function isTokenFreshByAccessToken(Location $location, $accessToken) |
|
| 69 | { |
|
| @@ 68-111 (lines=44) @@ | ||
| 65 | return $access_token; |
|
| 66 | } |
|
| 67 | ||
| 68 | function isTokenFreshByAccessToken(Location $location, $accessToken) |
|
| 69 | { |
|
| 70 | $db = new DatabaseConnect(); |
|
| 71 | $result = $db->query("SELECT * FROM accounts WHERE access_token='" . $accessToken . "'"); |
|
| 72 | ||
| 73 | if ($result->num_rows > 0) |
|
| 74 | { |
|
| 75 | // output data of each row |
|
| 76 | while($row = $result->fetch_assoc()) { |
|
| 77 | //$access_token = $row["access_token"]; |
|
| 78 | $expiration_date = $row["expiration_date"]; |
|
| 79 | $deviceUid = $row["device_uid"]; |
|
| 80 | $access_token = $row["access_token"]; |
|
| 81 | } |
|
| 82 | } |
|
| 83 | else |
|
| 84 | { |
|
| 85 | echo '0 results'; |
|
| 86 | } |
|
| 87 | ||
| 88 | if($expiration_date <= time()) { |
|
| 89 | $accountCreator = new CreateUser(); |
|
| 90 | $accountCreator->setAccessToken($access_token);//$accountData->getAccessToken()); |
|
| 91 | $accountCreator->setDeviceUid($deviceUid); |
|
| 92 | $accountCreator->setLocation($location); |
|
| 93 | $data = $accountCreator->execute(); |
|
| 94 | ||
| 95 | $access_token = (string)$data[0]['access_token']; |
|
| 96 | $expiration_date = $data[0]['expiration_date']; |
|
| 97 | $device_uid = (string)$data[1]; |
|
| 98 | ||
| 99 | $db = new DatabaseConnect(); |
|
| 100 | $result = $db->query("UPDATE accounts |
|
| 101 | SET access_token='" . $access_token . "', |
|
| 102 | expiration_date='" . $expiration_date . "' |
|
| 103 | WHERE device_uid='" . $device_uid . "'"); |
|
| 104 | ||
| 105 | if($result === false){ |
|
| 106 | echo "Adding account failed: (" . $db->errno . ") " . $db->error; |
|
| 107 | } |
|
| 108 | } |
|
| 109 | ||
| 110 | return TRUE; |
|
| 111 | } |
|
| 112 | ||
| 113 | function isTokenFreshByDeviceUid(Location $location, $deviceUid) |
|
| 114 | { |
|
| @@ 113-158 (lines=46) @@ | ||
| 110 | return TRUE; |
|
| 111 | } |
|
| 112 | ||
| 113 | function isTokenFreshByDeviceUid(Location $location, $deviceUid) |
|
| 114 | { |
|
| 115 | $db = new DatabaseConnect(); |
|
| 116 | $result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $deviceUid . "'"); |
|
| 117 | ||
| 118 | $access_token; |
|
| 119 | ||
| 120 | if ($result->num_rows > 0) |
|
| 121 | { |
|
| 122 | // output data of each row |
|
| 123 | while($row = $result->fetch_assoc()) { |
|
| 124 | //$access_token = $row["access_token"]; |
|
| 125 | $expiration_date = $row["expiration_date"]; |
|
| 126 | $deviceUid = $row["device_uid"]; |
|
| 127 | $access_token = $row["access_token"]; |
|
| 128 | } |
|
| 129 | } |
|
| 130 | else |
|
| 131 | { |
|
| 132 | echo '0 results'; |
|
| 133 | } |
|
| 134 | ||
| 135 | if($expiration_date <= time()) { |
|
| 136 | $accountCreator = new CreateUser(); |
|
| 137 | $accountCreator->setAccessToken($access_token); |
|
| 138 | $accountCreator->setDeviceUid($deviceUid); |
|
| 139 | $accountCreator->setLocation($location); |
|
| 140 | $data = $accountCreator->execute(); |
|
| 141 | ||
| 142 | $access_token = (string)$data[0]['access_token']; |
|
| 143 | $expiration_date = $data[0]['expiration_date']; |
|
| 144 | $device_uid = (string)$data[1]; |
|
| 145 | ||
| 146 | $db = new DatabaseConnect(); |
|
| 147 | $result = $db->query("UPDATE accounts |
|
| 148 | SET access_token='" . $access_token . "', |
|
| 149 | expiration_date='" . $expiration_date . "' |
|
| 150 | WHERE device_uid='" . $device_uid . "'"); |
|
| 151 | ||
| 152 | if($result === false){ |
|
| 153 | echo "Adding account failed: (" . $db->errno . ") " . $db->error; |
|
| 154 | } |
|
| 155 | } |
|
| 156 | ||
| 157 | return $access_token; |
|
| 158 | } |
|
| 159 | ||
| 160 | function getLocationByAccessToken($accessToken) |
|
| 161 | { |
|