refact AUTH module
This commit is contained in:
@@ -15,6 +15,8 @@
|
||||
#include "esp_vfs.h"
|
||||
#include "cJSON.h"
|
||||
#include "rest.h"
|
||||
#include "evse_api.h"
|
||||
|
||||
|
||||
static const char *REST_TAG = "esp-rest";
|
||||
#define REST_CHECK(a, str, goto_tag, ...) \
|
||||
@@ -68,7 +70,7 @@ static struct {
|
||||
int energyLimit;
|
||||
int chargingTimeLimit;
|
||||
int temperatureLimit;
|
||||
} settings_config = {32, 0, 0, 0, 60};
|
||||
} settings_config = {0, 0, 0, 0, 0};
|
||||
|
||||
|
||||
// Estruturas para armazenar as configurações de autenticação e usuários
|
||||
@@ -76,7 +78,7 @@ static struct {
|
||||
bool RFID;
|
||||
bool App;
|
||||
bool Password;
|
||||
} auth_methods = {false, false, true};
|
||||
} auth_methods = {false, false, false};
|
||||
|
||||
static struct {
|
||||
char username[128];
|
||||
@@ -356,7 +358,9 @@ static esp_err_t config_settings_post_handler(httpd_req_t *req)
|
||||
|
||||
// Atualizando as configurações
|
||||
cJSON *currentLimit = cJSON_GetObjectItem(json, "currentLimit");
|
||||
if (currentLimit) settings_config.currentLimit = currentLimit->valueint;
|
||||
if (currentLimit)
|
||||
evse_set_max_charging_current(currentLimit->valueint);
|
||||
//settings_config.currentLimit = currentLimit->valueint;
|
||||
|
||||
cJSON *powerLimit = cJSON_GetObjectItem(json, "powerLimit");
|
||||
if (powerLimit) settings_config.powerLimit = powerLimit->valueint;
|
||||
@@ -368,7 +372,10 @@ static esp_err_t config_settings_post_handler(httpd_req_t *req)
|
||||
if (chargingTimeLimit) settings_config.chargingTimeLimit = chargingTimeLimit->valueint;
|
||||
|
||||
cJSON *temperatureLimit = cJSON_GetObjectItem(json, "temperatureLimit");
|
||||
if (temperatureLimit) settings_config.temperatureLimit = temperatureLimit->valueint;
|
||||
if (temperatureLimit)
|
||||
evse_set_temp_threshold(temperatureLimit->valueint);
|
||||
|
||||
//settings_config.temperatureLimit = temperatureLimit->valueint;
|
||||
|
||||
cJSON_Delete(json);
|
||||
|
||||
@@ -386,11 +393,14 @@ static esp_err_t config_settings_get_handler(httpd_req_t *req)
|
||||
|
||||
// Criar objeto JSON para enviar as configurações atuais
|
||||
cJSON *config = cJSON_CreateObject();
|
||||
cJSON_AddNumberToObject(config, "currentLimit", settings_config.currentLimit);
|
||||
|
||||
|
||||
cJSON_AddNumberToObject(config, "maxCurrentLimit", evse_get_max_charging_current());
|
||||
cJSON_AddNumberToObject(config, "currentLimit", evse_get_max_charging_current());
|
||||
cJSON_AddNumberToObject(config, "powerLimit", settings_config.powerLimit);
|
||||
cJSON_AddNumberToObject(config, "energyLimit", settings_config.energyLimit);
|
||||
cJSON_AddNumberToObject(config, "chargingTimeLimit", settings_config.chargingTimeLimit);
|
||||
cJSON_AddNumberToObject(config, "temperatureLimit", settings_config.temperatureLimit);
|
||||
cJSON_AddNumberToObject(config, "temperatureLimit", evse_get_temp_threshold());
|
||||
|
||||
// Convertendo para string e enviando a resposta
|
||||
const char *config_str = cJSON_Print(config);
|
||||
@@ -583,7 +593,7 @@ static esp_err_t config_auth_methods_get_handler(httpd_req_t *req)
|
||||
|
||||
// Criar objeto JSON com as configurações de métodos de autenticação
|
||||
cJSON *config = cJSON_CreateObject();
|
||||
cJSON_AddBoolToObject(config, "RFID", auth_methods.RFID);
|
||||
cJSON_AddBoolToObject(config, "RFID", evse_is_require_auth());
|
||||
cJSON_AddBoolToObject(config, "App", auth_methods.App);
|
||||
cJSON_AddBoolToObject(config, "Password", auth_methods.Password);
|
||||
|
||||
@@ -618,7 +628,7 @@ static esp_err_t config_auth_methods_post_handler(httpd_req_t *req)
|
||||
|
||||
// Atualizando as configurações de autenticação
|
||||
cJSON *RFID = cJSON_GetObjectItem(json, "RFID");
|
||||
if (RFID) auth_methods.RFID = RFID->valueint;
|
||||
if (RFID) evse_set_require_auth(RFID->valueint != 0);
|
||||
|
||||
cJSON *App = cJSON_GetObjectItem(json, "App");
|
||||
if (App) auth_methods.App = App->valueint;
|
||||
|
||||
Reference in New Issue
Block a user