Redirect after hour change

Done to avoid situation where refreshing the page will
resubmit the form
master
Damian Peterson 2 years ago
parent 56b00a20ef
commit 22cf158c58

@ -52,6 +52,7 @@ $selectedHour = 13;
$isLoggedIn = true;
$accessToken = $_COOKIE['access_token'];
$refreshToken = $_COOKIE['refresh_token'];
$newHour = $_COOKIE['hour'];
$customerNumber = '';
$connectionId = '';
$customerName = '';
@ -231,7 +232,12 @@ if (!isset($accessToken) && !isset($refreshToken)) {
try {
getCustomerDetails($vars, $accessToken, $customerNumber, $connectionId, $customerName);
getCurrentHour($vars, $accessToken, $customerNumber, $connectionId, $selectedHour);
$message = 'Select your hour of power.';
if ($newHour) {
$message = 'Done, changed to ' . $times[$newHour] . '.';
setcookie('hour', '', time() - 1000, "/");
} else {
$message = 'Select your hour of power.';
}
} catch (Exception $exception) {
if ($exception->getCode() === 401) {
try {
@ -265,7 +271,9 @@ if ($isLoggedIn && $_POST) {
if ($isValid) {
try {
setCurrentHour($vars, $accessToken, $customerNumber, $connectionId, $selectedHour);
$message = 'Done. Hour changed to ' . $times[$selectedHour] . '.';
setcookie('hour', $selectedHour, time() + 30000, "/");
header('Location: /');
die();
} catch (Exception $exception) {
$message = $exception->getMessage();
}

Loading…
Cancel
Save