Login url with service. Changed code for registering custom url to not check downloader dest..

This commit is contained in:
David Kocik 2024-08-21 13:40:43 +02:00 committed by Lukas Matena
parent 17300d7549
commit 02ddb36108
7 changed files with 27 additions and 14 deletions

View File

@ -1718,7 +1718,7 @@ bool PageDownloader::on_finish_downloader() const
bool DownloaderUtils::Worker::perform_registration_linux = false;
#endif // __linux__
bool DownloaderUtils::Worker::perform_register(const std::string& path)
bool DownloaderUtils::Worker::perform_download_register(const std::string& path)
{
boost::filesystem::path aux_dest (path);
boost::system::error_code ec;
@ -1734,6 +1734,10 @@ bool DownloaderUtils::Worker::perform_register(const std::string& path)
}
BOOST_LOG_TRIVIAL(info) << "Downloader registration: Directory for downloads: " << chosen_dest.string();
wxGetApp().app_config->set("url_downloader_dest", chosen_dest.string());
perform_url_register();
}
bool DownloaderUtils::Worker::perform_url_register()
{
#ifdef _WIN32
// Registry key creation for "prusaslicer://" URL
@ -1793,12 +1797,12 @@ bool DownloaderUtils::Worker::on_finish() {
BOOST_LOG_TRIVIAL(debug) << "PageDownloader::on_finish_downloader ac_value " << ac_value << " downloader_checked " << downloader_checked;
if (ac_value && downloader_checked) {
// already registered but we need to do it again
if (!perform_register(GUI::into_u8(path_name())))
if (!perform_download_register(GUI::into_u8(path_name())))
return false;
app_config->set("downloader_url_registered", "1");
} else if (!ac_value && downloader_checked) {
// register
if (!perform_register(GUI::into_u8(path_name())))
if (!perform_download_register(GUI::into_u8(path_name())))
return false;
app_config->set("downloader_url_registered", "1");
} else if (ac_value && !downloader_checked) {

View File

@ -52,7 +52,8 @@ namespace DownloaderUtils {
void set_path_name(const std::string& name);
bool on_finish();
static bool perform_register(const std::string& path);
static bool perform_download_register(const std::string& path);
static bool perform_url_register();
#ifdef __linux__
static bool perform_registration_linux;
#endif // __linux__

View File

@ -3337,7 +3337,7 @@ void GUI_App::show_downloader_registration_dialog()
, true, wxYES_NO);
if (msg.ShowModal() == wxID_YES) {
auto downloader_worker = new DownloaderUtils::Worker(nullptr);
downloader_worker->perform_register(app_config->get("url_downloader_dest"));
downloader_worker->perform_download_register(app_config->get("url_downloader_dest"));
#if defined(__linux__) && defined(SLIC3R_DESKTOP_INTEGRATION)
if (DownloaderUtils::Worker::perform_registration_linux)
DesktopIntegrationDialog::perform_downloader_desktop_integration();

View File

@ -891,7 +891,7 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame)
}
});
this->q->Bind(EVT_OPEN_EXTERNAL_LOGIN, [this](wxCommandEvent& evt) {
DownloaderUtils::Worker::perform_register(wxGetApp().app_config->get("url_downloader_dest"));
DownloaderUtils::Worker::perform_url_register();
#if defined(__linux__)
// Remove all desktop files registering prusaslicer:// url done by previous versions.
DesktopIntegrationDialog::undo_downloader_registration_rigid();
@ -900,7 +900,15 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame)
DesktopIntegrationDialog::perform_downloader_desktop_integration();
#endif // SLIC3R_DESKTOP_INTEGRATION
#endif // __linux__
wxString url = user_account->get_login_redirect_url()+ L"&choose_account=1";
std::string service;
if (evt.GetString().Find("accounts.google.com") != wxString::npos) {
service = "google";
} else if (evt.GetString().Find("appleid.apple.com") != wxString::npos) {
service = "apple";
} else if (evt.GetString().Find("facebook.com") != wxString::npos) {
service = "facebook";
}
wxString url = user_account->get_login_redirect_url(service);
wxGetApp().open_login_browser_with_dialog(into_u8(url));
});

View File

@ -39,7 +39,7 @@ public:
void do_login();
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(const std::string& service = std::string()) { return m_communication->get_login_redirect_url(service); }
void set_remember_session(bool remember);
void toggle_remember_session();

View File

@ -322,7 +322,7 @@ void UserAccountCommunication::on_uuid_map_success()
}
// Generates and stores Code Verifier - second call deletes previous one.
wxString UserAccountCommunication::generate_login_redirect_url()
wxString UserAccountCommunication::generate_login_redirect_url()
{
auto& sc = Utils::ServiceConfig::instance();
const std::string AUTH_HOST = sc.account_url();
@ -339,7 +339,7 @@ wxString UserAccountCommunication::generate_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);
return url;
}
wxString UserAccountCommunication::get_login_redirect_url() const
wxString UserAccountCommunication::get_login_redirect_url(const std::string& service/* = std::string()*/) const
{
auto& sc = Utils::ServiceConfig::instance();
const std::string AUTH_HOST = sc.account_url();
@ -349,10 +349,10 @@ wxString UserAccountCommunication::get_login_redirect_url() const
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);
std::string params = GUI::format("embed=1&client_id=%1%&response_type=code&code_challenge=%2%&code_challenge_method=S256&scope=basic_info&redirect_uri=%3%&language=%4%", CLIENT_ID, code_challenge, REDIRECT_URI, language);
params = Http::url_encode(params);
wxString url = GUI::format_wxstr(L"%1%/login/%2%?next=/o/authorize/?%3%", AUTH_HOST, service, params);
return url;
}
void UserAccountCommunication::login_redirect()

View File

@ -45,7 +45,7 @@ public:
// Generates and stores Code Verifier - second call deletes previous one.
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;
wxString get_login_redirect_url(const std::string& service = std::string()) const;
// Trigger function starts various remote operations
void enqueue_connect_status_action();
void enqueue_connect_printer_models_action();