mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-13 04:29:03 +08:00
Open login in browser only for external services
This commit is contained in:
parent
ce44b8638f
commit
47d793ffb3
@ -875,11 +875,18 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame)
|
||||
user_account->on_login_code_recieved(evt.data);
|
||||
});
|
||||
this->q->Bind(EVT_OPEN_PRUSAAUTH, [this](OpenPrusaAuthEvent& evt) {
|
||||
BOOST_LOG_TRIVIAL(info) << "open login browser: " << evt.data;
|
||||
/*
|
||||
BOOST_LOG_TRIVIAL(info) << "open login browser: " << evt.data.first;
|
||||
std::string dialog_msg;
|
||||
LoginWebViewDialog dialog(this->q, dialog_msg, evt.data);
|
||||
LoginWebViewDialog dialog(this->q, dialog_msg, evt.data.first);
|
||||
if (dialog.ShowModal() != wxID_OK) {
|
||||
if(!dialog_msg.empty()) {
|
||||
DownloaderUtils::Worker::perform_register(wxGetApp().app_config->get("url_downloader_dest"));
|
||||
#ifdef __linux__
|
||||
if (DownloaderUtils::Worker::perform_registration_linux)
|
||||
DesktopIntegrationDialog::perform_downloader_desktop_integration();
|
||||
#endif // __linux__
|
||||
wxGetApp().open_login_browser_with_dialog(evt.data.second);
|
||||
}
|
||||
return;
|
||||
}
|
||||
user_account->on_login_code_recieved(dialog_msg);
|
||||
|
@ -38,7 +38,7 @@ public:
|
||||
bool is_logged();
|
||||
void do_login();
|
||||
void do_logout();
|
||||
wxString get_login_redirect_url() { return m_communication->get_login_redirect_url(); }
|
||||
wxString get_login_redirect_url() { return m_communication->get_login_redirect_url(true); }
|
||||
|
||||
void set_remember_session(bool remember);
|
||||
void toggle_remember_session();
|
||||
|
@ -321,7 +321,7 @@ void UserAccountCommunication::on_uuid_map_success()
|
||||
}
|
||||
}
|
||||
|
||||
wxString UserAccountCommunication::get_login_redirect_url() {
|
||||
wxString UserAccountCommunication::get_login_redirect_url(bool internal) {
|
||||
auto& sc = Utils::ServiceConfig::instance();
|
||||
const std::string AUTH_HOST = sc.account_url();
|
||||
const std::string CLIENT_ID = client_id();
|
||||
@ -334,14 +334,17 @@ wxString UserAccountCommunication::get_login_redirect_url() {
|
||||
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/?client_id=%2%&response_type=code&code_challenge=%3%&code_challenge_method=S256&scope=basic_info&redirect_uri=%4%&language=%5%&choose_account=1", 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);
|
||||
if (!internal) {
|
||||
url += L"&choose_account=1";
|
||||
}
|
||||
return url;
|
||||
}
|
||||
void UserAccountCommunication::login_redirect()
|
||||
{
|
||||
wxString url = get_login_redirect_url();
|
||||
wxQueueEvent(m_evt_handler,new OpenPrusaAuthEvent(GUI::EVT_OPEN_PRUSAAUTH, std::move(url)));
|
||||
wxString url1 = get_login_redirect_url(true);
|
||||
wxString url2 = get_login_redirect_url(false);
|
||||
wxQueueEvent(m_evt_handler,new OpenPrusaAuthEvent(GUI::EVT_OPEN_PRUSAAUTH, {std::move(url1), std::move(url2)}));
|
||||
}
|
||||
|
||||
bool UserAccountCommunication::is_logged()
|
||||
|
@ -42,7 +42,7 @@ public:
|
||||
void do_login();
|
||||
void do_logout();
|
||||
void do_clear();
|
||||
wxString get_login_redirect_url();
|
||||
wxString get_login_redirect_url(bool internal);
|
||||
// Trigger function starts various remote operations
|
||||
void enqueue_connect_status_action();
|
||||
void enqueue_connect_printer_models_action();
|
||||
|
@ -14,7 +14,7 @@
|
||||
namespace Slic3r {
|
||||
namespace GUI {
|
||||
|
||||
using OpenPrusaAuthEvent = Event<wxString>;
|
||||
using OpenPrusaAuthEvent = Event<std::pair<wxString,wxString>>;
|
||||
using UserAccountSuccessEvent = Event<std::string>;
|
||||
using UserAccountFailEvent = Event<std::string>;
|
||||
using UserAccountTimeEvent = Event<int>;
|
||||
|
@ -1370,22 +1370,22 @@ void PrinterPickWebViewDialog::on_dpi_changed(const wxRect &suggested_rect)
|
||||
}
|
||||
|
||||
LoginWebViewDialog::LoginWebViewDialog(wxWindow *parent, std::string &ret_val, const wxString& url)
|
||||
: 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)
|
||||
{
|
||||
Centre();
|
||||
}
|
||||
void LoginWebViewDialog::on_navigation_request(wxWebViewEvent &evt)
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << " " << evt.GetURL();
|
||||
wxString url = evt.GetURL();
|
||||
if (url.starts_with(L"prusaslicer")) {
|
||||
evt.Veto();
|
||||
m_ret_val = into_u8(url);
|
||||
EndModal(wxID_OK);
|
||||
} else if (!url.starts_with(L"https://account.prusa3d.com")) {
|
||||
m_ret_val = GUI::into_u8(url);
|
||||
EndModal(wxID_EXECUTE);
|
||||
}
|
||||
}
|
||||
void LoginWebViewDialog::on_dpi_changed(const wxRect &suggested_rect)
|
||||
|
Loading…
x
Reference in New Issue
Block a user