mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-05-16 10:02:12 +00:00
init
This commit is contained in:
@@ -182,6 +182,42 @@ std::shared_ptr<HttpServer::Response> HttpServer::bbl_auth_handle_request(const
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(info) << "thirdparty_login: get_response";
|
||||
|
||||
const std::string auth_code = url_get_param(url, "code");
|
||||
if (!auth_code.empty()) {
|
||||
std::string state = url_get_param(url, "state");
|
||||
NetworkAgent* agent = wxGetApp().getAgent();
|
||||
if (!agent) {
|
||||
return std::make_shared<ResponseNotFound>();
|
||||
}
|
||||
|
||||
json payload;
|
||||
payload["command"] = "user_login";
|
||||
payload["data"]["code"] = auth_code;
|
||||
payload["data"]["state"] = state;
|
||||
|
||||
agent->change_user(payload.dump());
|
||||
const bool login_ok = agent->is_user_login();
|
||||
if (login_ok) {
|
||||
wxGetApp().request_user_login(1);
|
||||
GUI::wxGetApp().CallAfter([] { wxGetApp().ShowUserLogin(false); });
|
||||
}
|
||||
|
||||
const std::string title = login_ok ? "Authentication complete" : "Authentication failed";
|
||||
const std::string message = login_ok
|
||||
? "You can return to OrcaSlicer. This window will close automatically."
|
||||
: "Something went wrong. Please return to OrcaSlicer and try again.";
|
||||
const std::string html =
|
||||
"<html><head><meta charset=\"utf-8\">"
|
||||
"<style>body{font-family:Arial,sans-serif;background:#f7f7f7;color:#222;margin:32px;}"
|
||||
"a.button{display:inline-block;padding:10px 16px;margin-top:12px;background:#0f8bff;color:#fff;text-decoration:none;border-radius:6px;}"
|
||||
"</style></head><body><div class=\"container\">"
|
||||
"<h2>" + title + "</h2>"
|
||||
"<p>" + message + "</p>"
|
||||
"<script>setTimeout(function(){try{window.close();}catch(e){}},1500);</script>"
|
||||
"</div></body></html>";
|
||||
return std::make_shared<ResponseHtml>(html);
|
||||
}
|
||||
|
||||
if (boost::contains(url, "access_token")) {
|
||||
std::string redirect_url = url_get_param(url, "redirect_url");
|
||||
std::string access_token = url_get_param(url, "access_token");
|
||||
@@ -249,7 +285,17 @@ void HttpServer::ResponseNotFound::write_response(std::stringstream& ssOut)
|
||||
|
||||
void HttpServer::ResponseRedirect::write_response(std::stringstream& ssOut)
|
||||
{
|
||||
const std::string sHTML = "<html><body><p>redirect to url </p></body></html>";
|
||||
const std::string sHTML =
|
||||
"<html><head><meta charset=\"utf-8\">"
|
||||
"<meta http-equiv=\"refresh\" content=\"0;url=" + location_str + "\">"
|
||||
"<style>body{font-family:Arial,sans-serif;background:#f7f7f7;color:#222;margin:32px;}"
|
||||
"a.button{display:inline-block;padding:10px 16px;margin-top:12px;background:#0f8bff;color:#fff;text-decoration:none;border-radius:6px;}"
|
||||
"</style></head><body><div class=\"container\">"
|
||||
"<h2>Authentication complete</h2>"
|
||||
"<p>You can return to OrcaSlicer. If your browser does not redirect automatically, use the button below.</p>"
|
||||
"<a class=\"button\" href=\"" + location_str + "\">Continue</a>"
|
||||
"<script>setTimeout(function(){try{window.close();}catch(e){}},1500);</script>"
|
||||
"</div></body></html>";
|
||||
ssOut << "HTTP/1.1 302 Found" << std::endl;
|
||||
ssOut << "Location: " << location_str << std::endl;
|
||||
ssOut << "content-type: text/html" << std::endl;
|
||||
@@ -258,5 +304,14 @@ void HttpServer::ResponseRedirect::write_response(std::stringstream& ssOut)
|
||||
ssOut << sHTML;
|
||||
}
|
||||
|
||||
void HttpServer::ResponseHtml::write_response(std::stringstream& ssOut)
|
||||
{
|
||||
ssOut << "HTTP/1.1 200 OK" << std::endl;
|
||||
ssOut << "content-type: text/html" << std::endl;
|
||||
ssOut << "content-length: " << html.length() << std::endl;
|
||||
ssOut << std::endl;
|
||||
ssOut << html;
|
||||
}
|
||||
|
||||
} // GUI
|
||||
} //Slic3r
|
||||
|
||||
Reference in New Issue
Block a user