Improve UI flow for linking Munzee, allow back button to cancel
This commit is contained in:
parent
6da04c2af7
commit
96587b1eb0
@ -7,9 +7,10 @@ if (!isset($database) || ($database == null)) {
|
|||||||
/* If the user has a Munzee key */
|
/* If the user has a Munzee key */
|
||||||
if ($database->has('munzee', ['player_uuid' => $_SESSION['uuid']])) {
|
if ($database->has('munzee', ['player_uuid' => $_SESSION['uuid']])) {
|
||||||
|
|
||||||
|
file_put_contents("munzee.log", "Checking if user " . $_SESSION['uuid'] . " has an unexpired token\n", FILE_APPEND);
|
||||||
/* Check if we need to refresh the bearer token first */
|
/* Check if we need to refresh the bearer token first */
|
||||||
if ($database->has('munzee', ['player_uuid' => $_SESSION['uuid'], 'expires[<=]' => (time() + 30)])) {
|
if ($database->has('munzee', ['player_uuid' => $_SESSION['uuid'], 'expires[<=]' => (time() + 30)])) {
|
||||||
|
file_put_contents("munzee.log", "User " . $_SESSION['uuid'] . " has an expired token. Refreshing.\n", FILE_APPEND);
|
||||||
$url = 'https://api.munzee.com/oauth/login';
|
$url = 'https://api.munzee.com/oauth/login';
|
||||||
$fields = array(
|
$fields = array(
|
||||||
'client_id' => urlencode(MUNZEE_KEY),
|
'client_id' => urlencode(MUNZEE_KEY),
|
||||||
@ -45,9 +46,10 @@ if ($database->has('munzee', ['player_uuid' => $_SESSION['uuid']])) {
|
|||||||
|
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
|
|
||||||
$data = json_decode($result, TRUE);
|
$data = json_decode($result, TRUE)['data'];
|
||||||
|
file_put_contents("munzee.log", "$result\n\n", FILE_APPEND);
|
||||||
if ($data['status_code'] == 200) {
|
if ($data['status_code'] == 200) {
|
||||||
|
file_put_contents("munzee.log", "User " . $_SESSION['uuid'] . " has a new unexpired token!\n", FILE_APPEND);
|
||||||
$database->update('munzee', ['bearertoken' => $data['token']['access_token'], 'refreshtoken' => $data['token']['refresh_token'], 'expires' => $data['token']['expires']], ['player_uuid' => $_SESSION['uuid']]);
|
$database->update('munzee', ['bearertoken' => $data['token']['access_token'], 'refreshtoken' => $data['token']['refresh_token'], 'expires' => $data['token']['expires']], ['player_uuid' => $_SESSION['uuid']]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -55,6 +57,7 @@ if ($database->has('munzee', ['player_uuid' => $_SESSION['uuid']])) {
|
|||||||
|
|
||||||
/* Check again now */
|
/* Check again now */
|
||||||
if ($database->has('munzee', ['player_uuid' => $_SESSION['uuid'], 'expires[>]' => (time() + 30)])) {
|
if ($database->has('munzee', ['player_uuid' => $_SESSION['uuid'], 'expires[>]' => (time() + 30)])) {
|
||||||
|
file_put_contents("munzee.log", "User " . $_SESSION['uuid'] . " attempting capture of $origcode.\n", FILE_APPEND);
|
||||||
$url = 'https://api.munzee.com/capture/light/';
|
$url = 'https://api.munzee.com/capture/light/';
|
||||||
$header = array(
|
$header = array(
|
||||||
'Content-type: application/json',
|
'Content-type: application/json',
|
||||||
@ -81,13 +84,14 @@ if ($database->has('munzee', ['player_uuid' => $_SESSION['uuid']])) {
|
|||||||
CURLOPT_TIMEOUT => 120, // time-out on response
|
CURLOPT_TIMEOUT => 120, // time-out on response
|
||||||
);
|
);
|
||||||
curl_setopt_array($ch, $options);
|
curl_setopt_array($ch, $options);
|
||||||
|
|
||||||
$result = curl_exec($ch);
|
$result = curl_exec($ch);
|
||||||
//close connection
|
//close connection
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
|
|
||||||
$data = json_decode($result, TRUE);
|
$data = json_decode($result, TRUE);
|
||||||
|
file_put_contents("munzee.log", "User " . $_SESSION['uuid'] . " captured $origcode:\n", FILE_APPEND);
|
||||||
|
file_put_contents("munzee.log", " $result\n\n", FILE_APPEND);
|
||||||
// Add munzee capture info to response
|
// Add munzee capture info to response
|
||||||
$returndata["messages"][] = ["title" => "Captured a Munzee!", "text" => $data["data"]["result"]];
|
$returndata["messages"][] = ["title" => "Captured a Munzee!", "text" => $data["data"]["result"]];
|
||||||
}
|
}
|
||||||
|
@ -37,8 +37,16 @@ if (is_empty($origcode)) {
|
|||||||
sendError("Bad code!", true);
|
sendError("Bad code!", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (strpos($origcode, "munzee") > 1) {
|
||||||
|
include 'capturemunzee.php';
|
||||||
|
}
|
||||||
|
} catch (Exception $ex) {
|
||||||
|
file_put_contents("munzee.log", "Error with Munzee code: $ex\n", FILE_APPEND);
|
||||||
|
}
|
||||||
|
|
||||||
if ($database->has('claimedcodes', ["AND" => ['code' => $origcode, 'playeruuid' => $_SESSION['uuid']]])) {
|
if ($database->has('claimedcodes', ["AND" => ['code' => $origcode, 'playeruuid' => $_SESSION['uuid']]])) {
|
||||||
sendError("You've already found this code!", true);
|
//sendError("You've already found this code!", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
$codearray = str_split($origcode);
|
$codearray = str_split($origcode);
|
||||||
@ -64,7 +72,4 @@ $returndata = [
|
|||||||
|
|
||||||
$returndata["messages"][] = ["title" => "Found an item!", "text" => "Found one $itemname"];
|
$returndata["messages"][] = ["title" => "Found an item!", "text" => "Found one $itemname"];
|
||||||
|
|
||||||
if (strpos($origcode, "munzee") > 1) {
|
|
||||||
include 'capturemunzee.php';
|
|
||||||
}
|
|
||||||
sendOK($itemname);
|
sendOK($itemname);
|
||||||
|
Reference in New Issue
Block a user