From a42f5b08b8b1e4c26f35199ea0b23cc26fb5a9d9 Mon Sep 17 00:00:00 2001
From: Carlgo11 <Carlgo11@users.noreply.github.com>
Date: Sun, 14 Feb 2021 00:55:43 +0100
Subject: [PATCH] Only revoke voucher on guest auth success

---
 php/submit.php | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/php/submit.php b/php/submit.php
index ce3cbf5..ec3e03b 100644
--- a/php/submit.php
+++ b/php/submit.php
@@ -40,9 +40,12 @@
         if (isset($voucher['qos_usage_quota'])) $usage_quota = $voucher['qos_usage_quota'];
 
         $authorized = $unifi_connection->authorize_guest($mac, $voucher['duration'], $max_up, $max_down, $usage_quota, $ap_mac);
-        $unifi_connection->revoke_voucher($voucher['_id']);
-        header('Status: 202');
-        print(json_encode(['success' => TRUE], JSON_PRETTY_PRINT));
+        if ($authorized) {
+            header('Status: 202');
+            $unifi_connection->revoke_voucher($voucher['_id']);
+        }
+        else header('Status: 500');
+        print(json_encode(['success' => $authorized]));
         return;
     }
 }