Add option to force browser login

This commit is contained in:
Sude 2024-08-22 13:09:51 +03:00
parent 5c4b201873
commit b4c6638e19
5 changed files with 47 additions and 36 deletions

View File

@ -232,6 +232,7 @@ class Config
// Booleans // Booleans
bool bLogin; bool bLogin;
bool bForceBrowserLogin;
bool bSaveConfig; bool bSaveConfig;
bool bResetConfig; bool bResetConfig;

View File

@ -206,6 +206,7 @@ int main(int argc, char *argv[])
#ifdef USE_QT_GUI_LOGIN #ifdef USE_QT_GUI_LOGIN
("gui-login", bpo::value<bool>(&Globals::globalConfig.bForceGUILogin)->zero_tokens()->default_value(false), "Login (force GUI login)\nImplies --enable-login-gui") ("gui-login", bpo::value<bool>(&Globals::globalConfig.bForceGUILogin)->zero_tokens()->default_value(false), "Login (force GUI login)\nImplies --enable-login-gui")
#endif #endif
("browser-login", bpo::value<bool>(&Globals::globalConfig.bForceBrowserLogin)->zero_tokens()->default_value(false), "Login (force browser login)")
("check-login-status", bpo::value<bool>(&bCheckLoginStatus)->zero_tokens()->default_value(false), "Check login status") ("check-login-status", bpo::value<bool>(&bCheckLoginStatus)->zero_tokens()->default_value(false), "Check login status")
("list", bpo::value<std::string>(&sListFormat)->implicit_value("games"), list_format_text.c_str()) ("list", bpo::value<std::string>(&sListFormat)->implicit_value("games"), list_format_text.c_str())
("download", bpo::value<bool>(&Globals::globalConfig.bDownload)->zero_tokens()->default_value(false), "Download") ("download", bpo::value<bool>(&Globals::globalConfig.bDownload)->zero_tokens()->default_value(false), "Download")
@ -472,6 +473,11 @@ int main(int argc, char *argv[])
} }
#endif #endif
if (Globals::globalConfig.bForceBrowserLogin)
{
Globals::globalConfig.bLogin = true;
}
if (Globals::globalConfig.bLogin) if (Globals::globalConfig.bLogin)
{ {
std::string login_conf = Globals::globalConfig.sConfigDirectory + "/login.txt"; std::string login_conf = Globals::globalConfig.sConfigDirectory + "/login.txt";

View File

@ -28,6 +28,9 @@ Login (force GUI login)
.br .br
Implies \fB\-\-enable\-login\-gui\fR Implies \fB\-\-enable\-login\-gui\fR
.TP .TP
\fB\-\-browser\-login\fR
Login (force browser login)
.TP
\fB\-\-check\-login\-status\fR \fB\-\-check\-login\-status\fR
Check login status Check login status
.TP .TP

View File

@ -265,7 +265,7 @@ int Downloader::login()
email = Globals::globalConfig.sEmail; email = Globals::globalConfig.sEmail;
password = Globals::globalConfig.sPassword; password = Globals::globalConfig.sPassword;
} }
else if (!bForceGUI) else if (!(bForceGUI || Globals::globalConfig.bForceBrowserLogin))
{ {
if (!isatty(STDIN_FILENO)) { if (!isatty(STDIN_FILENO)) {
/* Attempt to read this stuff from elsewhere */ /* Attempt to read this stuff from elsewhere */
@ -293,48 +293,49 @@ int Downloader::login()
} }
} }
if ((email.empty() || password.empty()) && (!headless && !bForceGUI)) if ((email.empty() || password.empty())
&& !(Globals::globalConfig.bForceBrowserLogin || headless || bForceGUI)
)
{ {
std::cerr << "Email and/or password empty" << std::endl; std::cerr << "Email and/or password empty" << std::endl;
return 0; return 0;
} }
else
// Login to website and Galaxy API
if (Globals::globalConfig.bLogin)
{ {
// Login to website and Galaxy API // Delete old cookies
if (Globals::globalConfig.bLogin) if (boost::filesystem::exists(Globals::globalConfig.curlConf.sCookiePath))
if (!boost::filesystem::remove(Globals::globalConfig.curlConf.sCookiePath))
std::cerr << "Failed to delete " << Globals::globalConfig.curlConf.sCookiePath << std::endl;
int iLoginResult = gogWebsite->Login(email, password);
if (iLoginResult < 1)
{ {
// Delete old cookies std::cerr << "Galaxy: Login failed" << std::endl;
if (boost::filesystem::exists(Globals::globalConfig.curlConf.sCookiePath)) return 0;
if (!boost::filesystem::remove(Globals::globalConfig.curlConf.sCookiePath)) }
std::cerr << "Failed to delete " << Globals::globalConfig.curlConf.sCookiePath << std::endl; else
{
int iLoginResult = gogWebsite->Login(email, password); std::cerr << "Galaxy: Login successful" << std::endl;
if (!Globals::galaxyConf.getJSON().empty())
if (iLoginResult < 1)
{ {
std::cerr << "Galaxy: Login failed" << std::endl; this->saveGalaxyJSON();
return 0;
}
else
{
std::cerr << "Galaxy: Login successful" << std::endl;
if (!Globals::galaxyConf.getJSON().empty())
{
this->saveGalaxyJSON();
}
}
if (gogWebsite->IsLoggedIn())
{
std::cerr << "HTTP: Login successful" << std::endl;
}
else
{
std::cerr << "HTTP: Login failed" << std::endl;
return 0;
} }
} }
if (gogWebsite->IsLoggedIn())
{
std::cerr << "HTTP: Login successful" << std::endl;
}
else
{
std::cerr << "HTTP: Login failed" << std::endl;
return 0;
}
} }
return 1; return 1;
} }

View File

@ -326,8 +326,8 @@ std::string Website::LoginGetAuthCode(const std::string& email, const std::strin
bRecaptcha = true; bRecaptcha = true;
} }
// Try normal login if GUI is not forced // Try normal login if GUI or browser is not forced
if (!bForceGUI) if (!(bForceGUI || Globals::globalConfig.bForceBrowserLogin))
{ {
auth_code = this->LoginGetAuthCodeCurl(login_form_html, email, password); auth_code = this->LoginGetAuthCodeCurl(login_form_html, email, password);
} }
@ -343,7 +343,7 @@ std::string Website::LoginGetAuthCode(const std::string& email, const std::strin
} }
#endif #endif
if (auth_code.empty() && bRecaptcha) if ((auth_code.empty() && bRecaptcha) || Globals::globalConfig.bForceBrowserLogin)
auth_code = this->LoginGetAuthCodeBrowser(auth_url); auth_code = this->LoginGetAuthCodeBrowser(auth_url);
return auth_code; return auth_code;