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