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
bool bLogin;
bool bForceBrowserLogin;
bool bSaveConfig;
bool bResetConfig;

View File

@ -206,6 +206,7 @@ int main(int argc, char *argv[])
#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")
#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")
("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")
@ -472,6 +473,11 @@ int main(int argc, char *argv[])
}
#endif
if (Globals::globalConfig.bForceBrowserLogin)
{
Globals::globalConfig.bLogin = true;
}
if (Globals::globalConfig.bLogin)
{
std::string login_conf = Globals::globalConfig.sConfigDirectory + "/login.txt";

View File

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

View File

@ -265,7 +265,7 @@ int Downloader::login()
email = Globals::globalConfig.sEmail;
password = Globals::globalConfig.sPassword;
}
else if (!bForceGUI)
else if (!(bForceGUI || Globals::globalConfig.bForceBrowserLogin))
{
if (!isatty(STDIN_FILENO)) {
/* 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;
return 0;
}
else
// Login to website and Galaxy API
if (Globals::globalConfig.bLogin)
{
// Login to website and Galaxy API
if (Globals::globalConfig.bLogin)
// Delete old cookies
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
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)
std::cerr << "Galaxy: Login failed" << std::endl;
return 0;
}
else
{
std::cerr << "Galaxy: Login successful" << std::endl;
if (!Globals::galaxyConf.getJSON().empty())
{
std::cerr << "Galaxy: Login failed" << std::endl;
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;
this->saveGalaxyJSON();
}
}
if (gogWebsite->IsLoggedIn())
{
std::cerr << "HTTP: Login successful" << std::endl;
}
else
{
std::cerr << "HTTP: Login failed" << std::endl;
return 0;
}
}
return 1;
}

View File

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