mirror of
https://github.com/Sude-/lgogdownloader.git
synced 2024-11-20 11:49:17 +01:00
Update login function
Downloader::login will fail if Galaxy API login is not successful. Exporting cookies no longer works because Galaxy API login is tied to website login.
This commit is contained in:
parent
2d70bdfacb
commit
edc6486637
@ -293,7 +293,8 @@ int Downloader::login()
|
||||
if (!boost::filesystem::remove(Globals::globalConfig.curlConf.sCookiePath))
|
||||
std::cerr << "Failed to delete " << Globals::globalConfig.curlConf.sCookiePath << std::endl;
|
||||
|
||||
if (!gogWebsite->Login(email, password))
|
||||
int iWebsiteLoginResult = gogWebsite->Login(email, password);
|
||||
if (iWebsiteLoginResult < 1)
|
||||
{
|
||||
std::cerr << "HTTP: Login failed" << std::endl;
|
||||
return 0;
|
||||
@ -301,6 +302,16 @@ int Downloader::login()
|
||||
else
|
||||
{
|
||||
std::cerr << "HTTP: Login successful" << std::endl;
|
||||
}
|
||||
|
||||
if (iWebsiteLoginResult < 2)
|
||||
{
|
||||
std::cerr << "Galaxy: Login failed" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Galaxy: Login successful" << std::endl;
|
||||
|
||||
if (!Globals::galaxyConf.getJSON().empty())
|
||||
{
|
||||
|
@ -331,7 +331,7 @@ int Website::Login(const std::string& email, const std::string& password)
|
||||
if (login_form_html.find("google.com/recaptcha") != std::string::npos)
|
||||
{
|
||||
std::cout << "Login form contains reCAPTCHA (https://www.google.com/recaptcha/)" << std::endl
|
||||
<< "Login with browser and export cookies to \"" << Globals::globalConfig.curlConf.sCookiePath << "\"" << std::endl;
|
||||
<< "Try to login later" << std::endl;
|
||||
return res = 0;
|
||||
}
|
||||
|
||||
@ -495,10 +495,7 @@ int Website::Login(const std::string& email, const std::string& password)
|
||||
res = 1; // Login was successful
|
||||
}
|
||||
|
||||
if (auth_code.empty())
|
||||
res = 0;
|
||||
|
||||
if (res == 1)
|
||||
if (res == 1 && !auth_code.empty())
|
||||
{
|
||||
std::string token_url = "https://auth.gog.com/token?client_id=" + Globals::galaxyConf.getClientId()
|
||||
+ "&client_secret=" + Globals::galaxyConf.getClientSecret()
|
||||
@ -506,28 +503,25 @@ int Website::Login(const std::string& email, const std::string& password)
|
||||
+ "&redirect_uri=" + (std::string)curl_easy_escape(curlhandle, Globals::galaxyConf.getRedirectUri().c_str(), Globals::galaxyConf.getRedirectUri().size());
|
||||
|
||||
std::string json = this->getResponse(token_url);
|
||||
if (json.empty())
|
||||
res = 0;
|
||||
else
|
||||
if (!json.empty())
|
||||
{
|
||||
Json::Value token_json;
|
||||
Json::Reader *jsonparser = new Json::Reader;
|
||||
if (jsonparser->parse(json, token_json))
|
||||
{
|
||||
Globals::galaxyConf.setJSON(token_json);
|
||||
res = 1;
|
||||
res = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Failed to parse json" << std::endl << json << std::endl;
|
||||
std::cerr << jsonparser->getFormattedErrorMessages() << std::endl;
|
||||
res = 0;
|
||||
}
|
||||
delete jsonparser;
|
||||
}
|
||||
}
|
||||
|
||||
if (res == 1)
|
||||
if (res >= 1)
|
||||
curl_easy_setopt(curlhandle, CURLOPT_COOKIELIST, "FLUSH"); // Write all known cookies to the file specified by CURLOPT_COOKIEJAR
|
||||
|
||||
return res;
|
||||
|
Loading…
Reference in New Issue
Block a user