mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-09-30 04:11:00 +00:00
fix: merge access codes into one
This commit is contained in:
@@ -163,7 +163,7 @@ void ConnectPrinterDialog::on_button_confirm(wxCommandEvent &event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (m_obj) {
|
if (m_obj) {
|
||||||
m_obj->set_user_access_code(code.ToStdString());
|
m_obj->set_access_code(code.ToStdString());
|
||||||
}
|
}
|
||||||
EndModal(wxID_OK);
|
EndModal(wxID_OK);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,19 @@
|
|||||||
|
|
||||||
using namespace nlohmann;
|
using namespace nlohmann;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
// Orca: access_code and the now-removed user_access_code field used to be persisted under
|
||||||
|
// separate AppConfig keys. Fall back to the legacy key so upgrading users don't lose a
|
||||||
|
// previously-saved code.
|
||||||
|
std::string get_access_code_with_legacy_fallback(Slic3r::AppConfig* config, const std::string& dev_id)
|
||||||
|
{
|
||||||
|
std::string code = config->get("access_code", dev_id);
|
||||||
|
if (code.empty())
|
||||||
|
code = config->get("user_access_code", dev_id);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
namespace Slic3r
|
namespace Slic3r
|
||||||
{
|
{
|
||||||
DeviceManager::DeviceManager(NetworkAgent* agent)
|
DeviceManager::DeviceManager(NetworkAgent* agent)
|
||||||
@@ -48,8 +61,7 @@ namespace Slic3r
|
|||||||
obj->bind_sec_link = "secure";
|
obj->bind_sec_link = "secure";
|
||||||
obj->m_is_online = true;
|
obj->m_is_online = true;
|
||||||
obj->last_alive = Slic3r::Utils::get_current_time_utc();
|
obj->last_alive = Slic3r::Utils::get_current_time_utc();
|
||||||
obj->set_access_code(config->get("access_code", m.dev_id), false);
|
obj->set_access_code(get_access_code_with_legacy_fallback(config, m.dev_id), false);
|
||||||
obj->set_user_access_code(config->get("user_access_code", m.dev_id), false);
|
|
||||||
if (obj->has_access_right()) {
|
if (obj->has_access_right()) {
|
||||||
localMachineList.insert(std::make_pair(m.dev_id, obj));
|
localMachineList.insert(std::make_pair(m.dev_id, obj));
|
||||||
} else {
|
} else {
|
||||||
@@ -339,8 +351,7 @@ namespace Slic3r
|
|||||||
//load access code
|
//load access code
|
||||||
AppConfig* config = Slic3r::GUI::wxGetApp().app_config;
|
AppConfig* config = Slic3r::GUI::wxGetApp().app_config;
|
||||||
if (config) {
|
if (config) {
|
||||||
obj->set_access_code(Slic3r::GUI::wxGetApp().app_config->get("access_code", dev_id), false);
|
obj->set_access_code(get_access_code_with_legacy_fallback(config, dev_id), false);
|
||||||
obj->set_user_access_code(Slic3r::GUI::wxGetApp().app_config->get("user_access_code", dev_id), false);
|
|
||||||
}
|
}
|
||||||
localMachineList.insert(std::make_pair(dev_id, obj));
|
localMachineList.insert(std::make_pair(dev_id, obj));
|
||||||
|
|
||||||
@@ -382,7 +393,6 @@ namespace Slic3r
|
|||||||
obj->m_is_online = true;
|
obj->m_is_online = true;
|
||||||
obj->last_alive = Slic3r::Utils::get_current_time_utc();
|
obj->last_alive = Slic3r::Utils::get_current_time_utc();
|
||||||
obj->set_access_code(access_code, false);
|
obj->set_access_code(access_code, false);
|
||||||
obj->set_user_access_code(access_code, false);
|
|
||||||
|
|
||||||
update_local_machine(*obj);
|
update_local_machine(*obj);
|
||||||
|
|
||||||
|
|||||||
@@ -449,9 +449,7 @@ bool MachineObject::HasRecentLanMessage()
|
|||||||
|
|
||||||
std::string MachineObject::get_access_code() const
|
std::string MachineObject::get_access_code() const
|
||||||
{
|
{
|
||||||
if (get_user_access_code().empty())
|
return access_code;
|
||||||
return access_code;
|
|
||||||
return get_user_access_code();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MachineObject::set_access_code(std::string code, bool only_refresh)
|
void MachineObject::set_access_code(std::string code, bool only_refresh)
|
||||||
@@ -470,37 +468,6 @@ void MachineObject::set_access_code(std::string code, bool only_refresh)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MachineObject::erase_user_access_code()
|
|
||||||
{
|
|
||||||
this->user_access_code = "";
|
|
||||||
AppConfig* config = GUI::wxGetApp().app_config;
|
|
||||||
if (config) {
|
|
||||||
GUI::wxGetApp().app_config->erase("user_access_code", get_dev_id());
|
|
||||||
//GUI::wxGetApp().app_config->save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MachineObject::set_user_access_code(std::string code, bool only_refresh)
|
|
||||||
{
|
|
||||||
this->user_access_code = code;
|
|
||||||
if (only_refresh && !code.empty()) {
|
|
||||||
AppConfig* config = GUI::wxGetApp().app_config;
|
|
||||||
if (config && !code.empty()) {
|
|
||||||
GUI::wxGetApp().app_config->set_str("user_access_code", get_dev_id(), code);
|
|
||||||
DeviceManager::update_local_machine(*this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string MachineObject::get_user_access_code() const
|
|
||||||
{
|
|
||||||
AppConfig* config = GUI::wxGetApp().app_config;
|
|
||||||
if (config) {
|
|
||||||
return GUI::wxGetApp().app_config->get("user_access_code", get_dev_id());
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string MachineObject::get_show_printer_type() const
|
std::string MachineObject::get_show_printer_type() const
|
||||||
{
|
{
|
||||||
std::string printer_type = this->printer_type;
|
std::string printer_type = this->printer_type;
|
||||||
@@ -2948,7 +2915,6 @@ int MachineObject::parse_json(std::string tunnel, std::string payload, bool key_
|
|||||||
std::string access_code = j_pre["system"]["access_code"].get<std::string>();
|
std::string access_code = j_pre["system"]["access_code"].get<std::string>();
|
||||||
if (!access_code.empty()) {
|
if (!access_code.empty()) {
|
||||||
set_access_code(access_code);
|
set_access_code(access_code);
|
||||||
set_user_access_code(access_code);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,7 +113,6 @@ private:
|
|||||||
std::string dev_name;
|
std::string dev_name;
|
||||||
std::string dev_ip;
|
std::string dev_ip;
|
||||||
std::string access_code;
|
std::string access_code;
|
||||||
std::string user_access_code;
|
|
||||||
|
|
||||||
// type, time stamp, delay
|
// type, time stamp, delay
|
||||||
std::vector<std::tuple<std::string, uint64_t, uint64_t>> message_delay;
|
std::vector<std::tuple<std::string, uint64_t, uint64_t>> message_delay;
|
||||||
@@ -228,11 +227,6 @@ public:
|
|||||||
std::string get_access_code() const;
|
std::string get_access_code() const;
|
||||||
void set_access_code(std::string code, bool only_refresh = true);
|
void set_access_code(std::string code, bool only_refresh = true);
|
||||||
|
|
||||||
/*user access code*/
|
|
||||||
void set_user_access_code(std::string code, bool only_refresh = true);
|
|
||||||
void erase_user_access_code();
|
|
||||||
std::string get_user_access_code() const;
|
|
||||||
|
|
||||||
//PRINTER_TYPE printer_type = PRINTER_3DPrinter_UKNOWN;
|
//PRINTER_TYPE printer_type = PRINTER_3DPrinter_UKNOWN;
|
||||||
std::string printer_type; /* model_id */
|
std::string printer_type; /* model_id */
|
||||||
std::string get_show_printer_type() const;
|
std::string get_show_printer_type() const;
|
||||||
|
|||||||
@@ -2166,12 +2166,12 @@ void GUI_App::init_networking_callbacks()
|
|||||||
obj->is_tunnel_mqtt = tunnel;
|
obj->is_tunnel_mqtt = tunnel;
|
||||||
obj->command_request_push_all(true);
|
obj->command_request_push_all(true);
|
||||||
obj->command_get_version();
|
obj->command_get_version();
|
||||||
// Do NOT erase user code. Erasing will cause has_access_right to be false
|
// Do NOT erase the access code. Erasing will cause has_access_right to be false
|
||||||
// whenever the device slot isn't populated yet (e.g. LAN reselect after logout).
|
// whenever the device slot isn't populated yet (e.g. LAN reselect after logout).
|
||||||
// This filters this printer out of get_my_machine_list, silently dropping every status message
|
// This filters this printer out of get_my_machine_list, silently dropping every status message
|
||||||
// AND the get_access_code reply that would refill the code, leaving a permanently
|
// AND the get_access_code reply that would refill the code, leaving a permanently
|
||||||
// dead "connected but no live data" state.
|
// dead "connected but no live data" state.
|
||||||
// obj -> set_user_access_code("");
|
// obj -> set_access_code("");
|
||||||
obj->command_get_access_code();
|
obj->command_get_access_code();
|
||||||
if (m_agent)
|
if (m_agent)
|
||||||
m_agent->install_device_cert(obj->get_dev_id(), obj->is_lan_mode_printer());
|
m_agent->install_device_cert(obj->get_dev_id(), obj->is_lan_mode_printer());
|
||||||
@@ -2221,7 +2221,6 @@ void GUI_App::init_networking_callbacks()
|
|||||||
wxString text;
|
wxString text;
|
||||||
if (msg == "5") {
|
if (msg == "5") {
|
||||||
obj->set_access_code("");
|
obj->set_access_code("");
|
||||||
obj->erase_user_access_code();
|
|
||||||
text = wxString::Format(_L("Incorrect password"));
|
text = wxString::Format(_L("Incorrect password"));
|
||||||
wxGetApp().show_dialog(text);
|
wxGetApp().show_dialog(text);
|
||||||
} else {
|
} else {
|
||||||
@@ -8291,7 +8290,7 @@ bool GUI_App::show_modal_ip_address_enter_dialog(bool input_sn, wxString title)
|
|||||||
wxGetApp().app_config->save();
|
wxGetApp().app_config->save();
|
||||||
|
|
||||||
obj->set_dev_ip(ip_address.ToStdString());
|
obj->set_dev_ip(ip_address.ToStdString());
|
||||||
obj->set_user_access_code(access_code.ToStdString());
|
obj->set_access_code(access_code.ToStdString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1991,7 +1991,7 @@ void InputIpAddressDialog::workerThreadFunc(std::string str_ip, std::string str_
|
|||||||
if (w.expired()) return;
|
if (w.expired()) return;
|
||||||
|
|
||||||
if (m_obj) {
|
if (m_obj) {
|
||||||
m_obj->set_user_access_code(str_access_code);
|
m_obj->set_access_code(str_access_code);
|
||||||
wxGetApp().getDeviceManager()->set_selected_machine(m_obj->get_dev_id());
|
wxGetApp().getDeviceManager()->set_selected_machine(m_obj->get_dev_id());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -704,7 +704,6 @@ void SelectMachinePopup::update_user_devices()
|
|||||||
}
|
}
|
||||||
|
|
||||||
mobj->set_access_code("");
|
mobj->set_access_code("");
|
||||||
mobj->erase_user_access_code();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GUI::wxGetApp().plater())
|
if (GUI::wxGetApp().plater())
|
||||||
|
|||||||
@@ -1861,7 +1861,6 @@ void MoonrakerPrinterAgent::announce_printhost_device()
|
|||||||
if (auto* app_config = GUI::wxGetApp().app_config) {
|
if (auto* app_config = GUI::wxGetApp().app_config) {
|
||||||
const std::string access_code = device_info.api_key.empty() ? "88888888" : device_info.api_key;
|
const std::string access_code = device_info.api_key.empty() ? "88888888" : device_info.api_key;
|
||||||
app_config->set_str("access_code", device_info.dev_id, access_code);
|
app_config->set_str("access_code", device_info.dev_id, access_code);
|
||||||
app_config->set_str("user_access_code", device_info.dev_id, access_code);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nlohmann::json payload;
|
nlohmann::json payload;
|
||||||
|
|||||||
Reference in New Issue
Block a user