Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions firmware/main/hal/hal_account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,20 @@ static const std::string_view _setting_ns = "account";
static const std::string_view _setting_username_key = "username";
static const std::string_view _setting_device_name_key = "device_name";

static const std::string_view _get_user_account_info_url = "http://47.113.125.164:12800/stackChan/device/user";
static const std::string_view _get_device_info_url = "http://47.113.125.164:12800/stackChan/device/info";
static const std::string_view _unbind_user_account_info_url = "http://47.113.125.164:12800/stackChan/device/unbind";
static std::string get_user_account_info_url()
{
return secret_logic::get_server_url() + "/stackChan/device/user";
}

static std::string get_device_info_url()
{
return secret_logic::get_server_url() + "/stackChan/device/info";
}

static std::string get_unbind_user_account_info_url()
{
return secret_logic::get_server_url() + "/stackChan/device/unbind";
}

static bool request_authorized_get(std::string_view token, std::string_view url, std::string &response,
std::function<void(std::string_view)> onLog)
Expand Down Expand Up @@ -58,7 +69,8 @@ static bool fetch_username(std::string_view token, std::string &username, std::f
onLog("Updating user account info...");

std::string response;
if (!request_authorized_get(token, _get_user_account_info_url, response, onLog)) {
const std::string url = get_user_account_info_url();
if (!request_authorized_get(token, url, response, onLog)) {
return false;
}

Expand Down Expand Up @@ -101,7 +113,8 @@ static bool fetch_device_name(std::string_view token, std::string &deviceName,
onLog("Updating device info...");

std::string response;
if (!request_authorized_get(token, _get_device_info_url, response, onLog)) {
const std::string url = get_device_info_url();
if (!request_authorized_get(token, url, response, onLog)) {
return false;
}

Expand Down Expand Up @@ -193,7 +206,7 @@ bool Hal::unbindAccount(std::function<void(std::string_view)> onLog)
mclog::tagInfo(_tag, "requesting to unbind account...");
onLog("Unbinding account...");

if (!http->Open("POST", std::string(_unbind_user_account_info_url))) {
if (!http->Open("POST", get_unbind_user_account_info_url())) {
mclog::tagError(_tag, "failed to open http request");
onLog("Failed to connect to server");
return false;
Expand Down
8 changes: 6 additions & 2 deletions firmware/main/hal/hal_app_center.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@
*/
#include "hal.h"
#include "utils/ota/ota.h"
#include "utils/secret_logic/secret_logic.h"
#include <mooncake_log.h>
#include <memory>
#include <board.h>
#include <cJSON.h>

static const std::string_view _tag = "HAL-AppCenter";

static const std::string_view _app_info_list_url = "http://47.113.125.164:12800/stackChan/apps";
static std::string get_app_info_list_url()
{
return secret_logic::get_server_url() + "/stackChan/apps";
}

static const char *get_json_string(cJSON *item, std::initializer_list<const char *> keys)
{
Expand All @@ -33,7 +37,7 @@ app_center::AppInfoList_t Hal::fetchAppList()
auto network = board.GetNetwork();

auto http = network->CreateHttp(0);
if (!http->Open("GET", std::string(_app_info_list_url))) {
if (!http->Open("GET", get_app_info_list_url())) {
mclog::tagError(_tag, "failed to open http connection");
return app_list;
}
Expand Down