mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-14 23:15:54 +08:00
Keep login dialog opened while opening 3rd vendor in external browser.
This commit is contained in:
parent
ab358cb4c4
commit
2bde97fb11
@ -23,7 +23,7 @@ ConfigWizardWebViewPage::ConfigWizardWebViewPage(ConfigWizard *parent)
|
|||||||
|
|
||||||
// Create the webview
|
// Create the webview
|
||||||
m_browser_sizer = new wxBoxSizer(wxHORIZONTAL);
|
m_browser_sizer = new wxBoxSizer(wxHORIZONTAL);
|
||||||
m_browser = WebView::CreateWebView(this, p_user_account->get_login_redirect_url(), {});
|
m_browser = WebView::CreateWebView(this, p_user_account->generate_login_redirect_url(), {});
|
||||||
if (!m_browser) {
|
if (!m_browser) {
|
||||||
// TRN Config wizard page with a log in page.
|
// TRN Config wizard page with a log in page.
|
||||||
wxStaticText* fail_text = new wxStaticText(this, wxID_ANY, _L("Failed to load a web browser. Logging in is not possible in the moment."));
|
wxStaticText* fail_text = new wxStaticText(this, wxID_ANY, _L("Failed to load a web browser. Logging in is not possible in the moment."));
|
||||||
|
@ -272,6 +272,9 @@ struct Plater::priv
|
|||||||
std::unique_ptr<NotificationManager> notification_manager;
|
std::unique_ptr<NotificationManager> notification_manager;
|
||||||
std::unique_ptr<UserAccount> user_account;
|
std::unique_ptr<UserAccount> user_account;
|
||||||
std::unique_ptr<PresetArchiveDatabase> preset_archive_database;
|
std::unique_ptr<PresetArchiveDatabase> preset_archive_database;
|
||||||
|
// Login dialog needs to be kept somewhere.
|
||||||
|
// It is created inside evt Bind. But it might be closed from another event.
|
||||||
|
LoginWebViewDialog* login_dialog { nullptr };
|
||||||
|
|
||||||
ProjectDirtyStateManager dirty_state;
|
ProjectDirtyStateManager dirty_state;
|
||||||
|
|
||||||
@ -875,11 +878,19 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame)
|
|||||||
user_account->on_login_code_recieved(evt.data);
|
user_account->on_login_code_recieved(evt.data);
|
||||||
});
|
});
|
||||||
this->q->Bind(EVT_OPEN_PRUSAAUTH, [this](OpenPrusaAuthEvent& evt) {
|
this->q->Bind(EVT_OPEN_PRUSAAUTH, [this](OpenPrusaAuthEvent& evt) {
|
||||||
|
if (login_dialog != nullptr) {
|
||||||
|
this->q->RemoveChild(login_dialog);
|
||||||
|
login_dialog->Destroy();
|
||||||
|
login_dialog = nullptr;
|
||||||
|
}
|
||||||
BOOST_LOG_TRIVIAL(info) << "open login browser: " << evt.data.first;
|
BOOST_LOG_TRIVIAL(info) << "open login browser: " << evt.data.first;
|
||||||
std::string dialog_msg;
|
std::string dialog_msg;
|
||||||
LoginWebViewDialog dialog(this->q, dialog_msg, evt.data.first);
|
login_dialog = new LoginWebViewDialog(this->q, dialog_msg, evt.data.first, this->q);
|
||||||
if (dialog.ShowModal() != wxID_OK) {
|
if (login_dialog->ShowModal() == wxID_OK) {
|
||||||
if(!dialog_msg.empty()) {
|
user_account->on_login_code_recieved(dialog_msg);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this->q->Bind(EVT_OPEN_EXTERNAL_LOGIN, [this](wxCommandEvent& evt) {
|
||||||
DownloaderUtils::Worker::perform_register(wxGetApp().app_config->get("url_downloader_dest"));
|
DownloaderUtils::Worker::perform_register(wxGetApp().app_config->get("url_downloader_dest"));
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
// Remove all desktop files registering prusaslicer:// url done by previous versions.
|
// Remove all desktop files registering prusaslicer:// url done by previous versions.
|
||||||
@ -889,11 +900,8 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame)
|
|||||||
DesktopIntegrationDialog::perform_downloader_desktop_integration();
|
DesktopIntegrationDialog::perform_downloader_desktop_integration();
|
||||||
#endif // SLIC3R_DESKTOP_INTEGRATION
|
#endif // SLIC3R_DESKTOP_INTEGRATION
|
||||||
#endif // __linux__
|
#endif // __linux__
|
||||||
wxGetApp().open_login_browser_with_dialog(/*dialog_msg*/evt.data.second);
|
wxString url = user_account->get_login_redirect_url()+ L"&choose_account=1";
|
||||||
}
|
wxGetApp().open_login_browser_with_dialog(into_u8(url));
|
||||||
} else {
|
|
||||||
user_account->on_login_code_recieved(dialog_msg);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
this->q->Bind(EVT_UA_LOGGEDOUT, [this](UserAccountSuccessEvent& evt) {
|
this->q->Bind(EVT_UA_LOGGEDOUT, [this](UserAccountSuccessEvent& evt) {
|
||||||
@ -914,6 +922,12 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame)
|
|||||||
});
|
});
|
||||||
|
|
||||||
this->q->Bind(EVT_UA_ID_USER_SUCCESS, [this](UserAccountSuccessEvent& evt) {
|
this->q->Bind(EVT_UA_ID_USER_SUCCESS, [this](UserAccountSuccessEvent& evt) {
|
||||||
|
if (login_dialog != nullptr) {
|
||||||
|
this->q->RemoveChild(login_dialog);
|
||||||
|
login_dialog->Destroy();
|
||||||
|
login_dialog = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
// There are multiple handlers and we want to notify all
|
// There are multiple handlers and we want to notify all
|
||||||
evt.Skip();
|
evt.Skip();
|
||||||
std::string who = user_account->get_username();
|
std::string who = user_account->get_username();
|
||||||
|
@ -38,6 +38,7 @@ public:
|
|||||||
bool is_logged();
|
bool is_logged();
|
||||||
void do_login();
|
void do_login();
|
||||||
void do_logout();
|
void do_logout();
|
||||||
|
wxString generate_login_redirect_url() { return m_communication->generate_login_redirect_url(); }
|
||||||
wxString get_login_redirect_url() { return m_communication->get_login_redirect_url(); }
|
wxString get_login_redirect_url() { return m_communication->get_login_redirect_url(); }
|
||||||
|
|
||||||
void set_remember_session(bool remember);
|
void set_remember_session(bool remember);
|
||||||
|
@ -322,7 +322,8 @@ void UserAccountCommunication::on_uuid_map_success()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Generates and stores Code Verifier - second call deletes previous one.
|
// Generates and stores Code Verifier - second call deletes previous one.
|
||||||
wxString UserAccountCommunication::get_login_redirect_url() {
|
wxString UserAccountCommunication::generate_login_redirect_url()
|
||||||
|
{
|
||||||
auto& sc = Utils::ServiceConfig::instance();
|
auto& sc = Utils::ServiceConfig::instance();
|
||||||
const std::string AUTH_HOST = sc.account_url();
|
const std::string AUTH_HOST = sc.account_url();
|
||||||
const std::string CLIENT_ID = client_id();
|
const std::string CLIENT_ID = client_id();
|
||||||
@ -338,9 +339,25 @@ wxString UserAccountCommunication::get_login_redirect_url() {
|
|||||||
wxString url = GUI::format_wxstr(L"%1%/o/authorize/?embed=1&client_id=%2%&response_type=code&code_challenge=%3%&code_challenge_method=S256&scope=basic_info&redirect_uri=%4%&language=%5%", AUTH_HOST, CLIENT_ID, code_challenge, REDIRECT_URI, language);
|
wxString url = GUI::format_wxstr(L"%1%/o/authorize/?embed=1&client_id=%2%&response_type=code&code_challenge=%3%&code_challenge_method=S256&scope=basic_info&redirect_uri=%4%&language=%5%", AUTH_HOST, CLIENT_ID, code_challenge, REDIRECT_URI, language);
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
wxString UserAccountCommunication::get_login_redirect_url() const
|
||||||
|
{
|
||||||
|
auto& sc = Utils::ServiceConfig::instance();
|
||||||
|
const std::string AUTH_HOST = sc.account_url();
|
||||||
|
const std::string CLIENT_ID = client_id();
|
||||||
|
const std::string REDIRECT_URI = "prusaslicer://login";
|
||||||
|
CodeChalengeGenerator ccg;
|
||||||
|
std::string code_challenge = ccg.generate_chalenge(m_code_verifier);
|
||||||
|
wxString language = GUI::wxGetApp().current_language_code();
|
||||||
|
language = language.SubString(0, 1);
|
||||||
|
BOOST_LOG_TRIVIAL(info) << "code verifier: " << m_code_verifier;
|
||||||
|
BOOST_LOG_TRIVIAL(info) << "code challenge: " << code_challenge;
|
||||||
|
|
||||||
|
wxString url = GUI::format_wxstr(L"%1%/o/authorize/?embed=1&client_id=%2%&response_type=code&code_challenge=%3%&code_challenge_method=S256&scope=basic_info&redirect_uri=%4%&language=%5%", AUTH_HOST, CLIENT_ID, code_challenge, REDIRECT_URI, language);
|
||||||
|
return url;
|
||||||
|
}
|
||||||
void UserAccountCommunication::login_redirect()
|
void UserAccountCommunication::login_redirect()
|
||||||
{
|
{
|
||||||
wxString url1 = get_login_redirect_url();
|
wxString url1 = generate_login_redirect_url();
|
||||||
wxString url2 = url1 + L"&choose_account=1";
|
wxString url2 = url1 + L"&choose_account=1";
|
||||||
wxQueueEvent(m_evt_handler,new OpenPrusaAuthEvent(GUI::EVT_OPEN_PRUSAAUTH, {std::move(url1), std::move(url2)}));
|
wxQueueEvent(m_evt_handler,new OpenPrusaAuthEvent(GUI::EVT_OPEN_PRUSAAUTH, {std::move(url1), std::move(url2)}));
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,9 @@ public:
|
|||||||
void do_logout();
|
void do_logout();
|
||||||
void do_clear();
|
void do_clear();
|
||||||
// Generates and stores Code Verifier - second call deletes previous one.
|
// Generates and stores Code Verifier - second call deletes previous one.
|
||||||
wxString get_login_redirect_url();
|
wxString generate_login_redirect_url();
|
||||||
|
// Only recreates the url with already existing url (if generate was not called before - url will be faulty)
|
||||||
|
wxString get_login_redirect_url() const;
|
||||||
// Trigger function starts various remote operations
|
// Trigger function starts various remote operations
|
||||||
void enqueue_connect_status_action();
|
void enqueue_connect_status_action();
|
||||||
void enqueue_connect_printer_models_action();
|
void enqueue_connect_printer_models_action();
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
// to set authorization cookie for all WebKit requests to Connect
|
// to set authorization cookie for all WebKit requests to Connect
|
||||||
#define AUTH_VIA_FETCH_OVERRIDE 0
|
#define AUTH_VIA_FETCH_OVERRIDE 0
|
||||||
|
|
||||||
|
wxDEFINE_EVENT(EVT_OPEN_EXTERNAL_LOGIN, wxCommandEvent);
|
||||||
|
|
||||||
namespace pt = boost::property_tree;
|
namespace pt = boost::property_tree;
|
||||||
|
|
||||||
@ -1370,9 +1371,10 @@ void PrinterPickWebViewDialog::on_dpi_changed(const wxRect &suggested_rect)
|
|||||||
Refresh();
|
Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
LoginWebViewDialog::LoginWebViewDialog(wxWindow *parent, std::string &ret_val, const wxString& url)
|
LoginWebViewDialog::LoginWebViewDialog(wxWindow *parent, std::string &ret_val, const wxString& url, wxEvtHandler* evt_handler)
|
||||||
: WebViewDialog(parent, url, _L("Log in dialog"), wxSize(50 * wxGetApp().em_unit(), 80 * wxGetApp().em_unit()), {})
|
: WebViewDialog(parent, url, _L("Log in dialog"), wxSize(50 * wxGetApp().em_unit(), 80 * wxGetApp().em_unit()), {})
|
||||||
, m_ret_val(ret_val)
|
, m_ret_val(ret_val)
|
||||||
|
, p_evt_handler(evt_handler)
|
||||||
{
|
{
|
||||||
Centre();
|
Centre();
|
||||||
}
|
}
|
||||||
@ -1385,11 +1387,12 @@ void LoginWebViewDialog::on_navigation_request(wxWebViewEvent &evt)
|
|||||||
EndModal(wxID_OK);
|
EndModal(wxID_OK);
|
||||||
} else if (url.starts_with(L"http")) {
|
} else if (url.starts_with(L"http")) {
|
||||||
auto& sc = Utils::ServiceConfig::instance();
|
auto& sc = Utils::ServiceConfig::instance();
|
||||||
if (!url.starts_with(GUI::from_u8(sc.account_url()))) {
|
if (!m_evt_sent && !url.starts_with(GUI::from_u8(sc.account_url()))) {
|
||||||
m_ret_val = GUI::into_u8(url);
|
wxCommandEvent* evt = new wxCommandEvent(EVT_OPEN_EXTERNAL_LOGIN);
|
||||||
EndModal(wxID_EXECUTE);
|
evt->SetString(url);
|
||||||
|
p_evt_handler->QueueEvent(evt);
|
||||||
|
m_evt_sent = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void LoginWebViewDialog::on_dpi_changed(const wxRect &suggested_rect)
|
void LoginWebViewDialog::on_dpi_changed(const wxRect &suggested_rect)
|
||||||
|
@ -17,6 +17,8 @@
|
|||||||
class wxWebView;
|
class wxWebView;
|
||||||
class wxWebViewEvent;
|
class wxWebViewEvent;
|
||||||
|
|
||||||
|
wxDECLARE_EVENT(EVT_OPEN_EXTERNAL_LOGIN, wxCommandEvent);
|
||||||
|
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
namespace GUI {
|
namespace GUI {
|
||||||
|
|
||||||
@ -276,12 +278,14 @@ public:
|
|||||||
class LoginWebViewDialog : public WebViewDialog
|
class LoginWebViewDialog : public WebViewDialog
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
LoginWebViewDialog(wxWindow *parent, std::string &ret_val, const wxString& url);
|
LoginWebViewDialog(wxWindow *parent, std::string &ret_val, const wxString& url, wxEvtHandler* evt_handler);
|
||||||
void on_navigation_request(wxWebViewEvent &evt) override;
|
void on_navigation_request(wxWebViewEvent &evt) override;
|
||||||
void on_dpi_changed(const wxRect &suggested_rect) override;
|
void on_dpi_changed(const wxRect &suggested_rect) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string& m_ret_val;
|
std::string& m_ret_val;
|
||||||
|
wxEvtHandler* p_evt_handler;
|
||||||
|
bool m_evt_sent{ false };
|
||||||
};
|
};
|
||||||
|
|
||||||
class LogoutWebViewDialog : public WebViewDialog
|
class LogoutWebViewDialog : public WebViewDialog
|
||||||
|
Loading…
x
Reference in New Issue
Block a user