Skip to content

Commit

Permalink
Merge branch 'client-4.0' of github.com:MakeICT/electronic-door into …
Browse files Browse the repository at this point in the history
…client-3.0
  • Loading branch information
Rowbotronics committed Mar 5, 2019
2 parents b15d805 + 5c68af2 commit 07aa554
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
13 changes: 13 additions & 0 deletions software/esp32/components/mcp_client/mcp_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions software/esp32/main/wifi_client_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 07aa554

Please sign in to comment.