Skip to content

Commit

Permalink
Add option to force browser login
Browse files Browse the repository at this point in the history
  • Loading branch information
Sude- committed Aug 22, 2024
1 parent 5c4b201 commit b4c6638
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 34 deletions.
1 change: 1 addition & 0 deletions include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ class Config

// Booleans
bool bLogin;
bool bForceBrowserLogin;
bool bSaveConfig;
bool bResetConfig;

Expand Down
6 changes: 6 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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";
Expand Down
3 changes: 3 additions & 0 deletions man/lgogdownloader.1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
63 changes: 32 additions & 31 deletions src/downloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
// 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);
int iLoginResult = gogWebsite->Login(email, password);

if (iLoginResult < 1)
{
std::cerr << "Galaxy: Login failed" << std::endl;
return 0;
}
else
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 successful" << std::endl;
if (!Globals::galaxyConf.getJSON().empty())
{
this->saveGalaxyJSON();
}
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;
}

Expand Down
6 changes: 3 additions & 3 deletions src/website.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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;
Expand Down

0 comments on commit b4c6638

Please sign in to comment.