Add user settings feature to update username and password

Signed-off-by: YoungSoo Shin <shinys000114@gmail.com>
This commit is contained in:
2025-09-26 12:47:03 +09:00
parent 89e17efcfc
commit 40fd0a667a
5 changed files with 153 additions and 5 deletions

View File

@@ -177,6 +177,8 @@ static esp_err_t setting_post_handler(httpd_req_t* req)
cJSON* vin_climit_item = cJSON_GetObjectItem(root, "vin_current_limit");
cJSON* main_climit_item = cJSON_GetObjectItem(root, "main_current_limit");
cJSON* usb_climit_item = cJSON_GetObjectItem(root, "usb_current_limit");
cJSON* new_username_item = cJSON_GetObjectItem(root, "new_username");
cJSON* new_password_item = cJSON_GetObjectItem(root, "new_password");
if (mode_item && cJSON_IsString(mode_item))
{
@@ -322,6 +324,17 @@ static esp_err_t setting_post_handler(httpd_req_t* req)
}
httpd_resp_sendstr(req, "{\"status\":\"current_limit_updated\"}");
}
else if (new_username_item && cJSON_IsString(new_username_item) && new_password_item &&
cJSON_IsString(new_password_item))
{
const char* new_username = new_username_item->valuestring;
const char* new_password = new_password_item->valuestring;
nconfig_write(PAGE_USERNAME, new_username);
nconfig_write(PAGE_PASSWORD, new_password);
ESP_LOGI(TAG, "Username and password updated successfully.");
httpd_resp_sendstr(req, "{\"status\":\"user_credentials_updated\"}");
}
else
{
httpd_resp_send_err(req, HTTPD_400_BAD_REQUEST, "Invalid payload");