From 688e21052237bd7bf4cc26dedcb8493e332d3d71 Mon Sep 17 00:00:00 2001
From: Christian Kindel <iceman81292@gmail.com>
Date: Tue, 5 Mar 2019 15:34:02 -0600
Subject: [PATCH 1/4] use new api endpoint to check group enrollment

---
 software/esp32/main/wifi_client_main.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/software/esp32/main/wifi_client_main.cpp b/software/esp32/main/wifi_client_main.cpp
index 9cd4da3..aba7199 100644
--- a/software/esp32/main/wifi_client_main.cpp
+++ b/software/esp32/main/wifi_client_main.cpp
@@ -240,10 +240,10 @@ bool check_card(char* nfc_id) {
   get_json_token(data, tokens, num_t, "userID", userID);
 
   if(atoi(userID) > 0) {
-    int resp_len = get_user_groups(userID);
+    int resp_len = check_group_enrollment(userID, "1348");
 
-    if (resp_len < 2) {
-      post_log(CLIENT_TAG "Could+Not+Find+User+Groups",userID, nfc_id,"deny");
+    if (resp_len < 3) {
+      post_log(CLIENT_TAG "User+Not+Authorized",userID, nfc_id,"deny");
       return false;
     }
 

From 2a0e1c6f0e5106a173d65ca0f33034786a9fa242 Mon Sep 17 00:00:00 2001
From: Christian Kindel <iceman81292@gmail.com>
Date: Tue, 5 Mar 2019 15:34:26 -0600
Subject: [PATCH 2/4] change unlock pin

---
 software/esp32/main/wifi_client_main.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/software/esp32/main/wifi_client_main.cpp b/software/esp32/main/wifi_client_main.cpp
index aba7199..62d9716 100644
--- a/software/esp32/main/wifi_client_main.cpp
+++ b/software/esp32/main/wifi_client_main.cpp
@@ -95,7 +95,7 @@ Reader card_reader;
 Light red_light((gpio_num_t)19);
 Light yellow_light((gpio_num_t)18);
 Light green_light((gpio_num_t)17);
-Light machine_power((gpio_num_t)23);
+Light machine_power((gpio_num_t)33);
 Switch power_switch((gpio_num_t)32);
 
 // static const char *REQUEST = "POST " AUTH_ENDPOINT "?email=" CONFIG_USERNAME    "&password=" CONFIG_PASSWORD "\r\n"

From 8eb1d97217c67334eb9b9cc316d98721a9355428 Mon Sep 17 00:00:00 2001
From: Christian Kindel <iceman81292@gmail.com>
Date: Tue, 5 Mar 2019 15:35:24 -0600
Subject: [PATCH 3/4] add api function for checking group enrollment

---
 software/esp32/components/mcp_client/mcp_api.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/software/esp32/components/mcp_client/mcp_api.h b/software/esp32/components/mcp_client/mcp_api.h
index f865f67..8fd0519 100644
--- a/software/esp32/components/mcp_client/mcp_api.h
+++ b/software/esp32/components/mcp_client/mcp_api.h
@@ -169,6 +169,19 @@ int get_user_groups(char* userID)
     return execute_request(url,"", HTTP_METHOD_GET);
 }
 
+int check_group_enrollment(char* userID, char* groupID)
+{
+    char url[strlen("/api/users/") + strlen(userID) + strlen ("/checkgroup/") + strlen(groupID)+ 1] = {'\0'};
+    strcpy(url, "/api/users/");
+    // ESP_LOGI(MCP_API_TAG, "%s",url);
+    strcat(url, userID);
+    strcat(url, "/checkgroup/");
+    strcat(url, groupID);
+    ESP_LOGI(MCP_API_TAG, "%s",url);
+    return execute_request(url,"", HTTP_METHOD_GET);
+}
+
+
 
 
 static void post_log(char* message, char* userID, char* nfcID, char* type) {

From 1707e6e1ef56533133cf48319814444d10bba383 Mon Sep 17 00:00:00 2001
From: Christian Kindel <iceman81292@gmail.com>
Date: Tue, 5 Mar 2019 15:36:02 -0600
Subject: [PATCH 4/4] re-order the power off sequence so green light doesn't
 stay on if network is slow

---
 software/esp32/main/wifi_client_main.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/software/esp32/main/wifi_client_main.cpp b/software/esp32/main/wifi_client_main.cpp
index 62d9716..377f1e6 100644
--- a/software/esp32/main/wifi_client_main.cpp
+++ b/software/esp32/main/wifi_client_main.cpp
@@ -287,11 +287,11 @@ void app_main()
       }
       if (!power_switch.state() && state) {
         machine_power.off();
-        post_log(CLIENT_TAG "Power+Off","", "","");
         state = 0;
         yellow_light.off();
         green_light.off();
         red_light.off();
+        post_log(CLIENT_TAG "Power+Off","", "","");
       }
       else if(power_switch.state() && !state) {
         red_light.on();