Add option to force GUI login

This commit is contained in:
Sude 2024-03-30 19:18:32 +02:00
parent d463c02af5
commit 93fb18f1d9
4 changed files with 51 additions and 21 deletions

View File

@ -252,6 +252,7 @@ class Config
bool bPlatformDetection;
#ifdef USE_QT_GUI_LOGIN
bool bEnableLoginGUI;
bool bForceGUILogin;
#endif
bool bUseFastCheck;
bool bTrustAPIForExtras;

View File

@ -204,6 +204,9 @@ int main(int argc, char *argv[])
("help,h", "Print help message")
("version", "Print version information")
("login", bpo::value<bool>(&Globals::globalConfig.bLogin)->zero_tokens()->default_value(false), "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")
#endif
("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")
("repair", bpo::value<bool>(&Globals::globalConfig.bRepair)->zero_tokens()->default_value(false), "Repair downloaded files\nUse --repair --download to redownload files when filesizes don't match (possibly different version). Redownload will rename the old file (appends .old to filename)")
@ -460,6 +463,14 @@ int main(int argc, char *argv[])
}
}
#ifdef USE_QT_GUI_LOGIN
if (Globals::globalConfig.bForceGUILogin)
{
Globals::globalConfig.bLogin = true;
Globals::globalConfig.bEnableLoginGUI = true;
}
#endif
if (Globals::globalConfig.bLogin)
{
std::string login_conf = Globals::globalConfig.sConfigDirectory + "/login.txt";
@ -649,20 +660,19 @@ int main(int argc, char *argv[])
Downloader downloader;
int iLoginTries = 0;
bool bLoginOK = false;
// Login because --login was used
if (Globals::globalConfig.bLogin)
{
bLoginOK = downloader.login();
}
else
{
bool bIsLoggedin = downloader.isLoggedIn();
if (!bIsLoggedin)
Globals::globalConfig.bLogin = true;
// Login because we are not logged in
while (iLoginTries++ < Globals::globalConfig.iRetries && !bIsLoggedin)
{
Globals::globalConfig.bLogin = true;
bLoginOK = downloader.login();
if (bLoginOK)
{
@ -675,6 +685,7 @@ int main(int argc, char *argv[])
{
return 1;
}
}
// Make sure that config file and cookie file are only readable/writable by owner
if (!Globals::globalConfig.bRespectUmask)

View File

@ -257,13 +257,17 @@ int Downloader::login()
std::string email;
std::string password;
bool headless = false;
bool bForceGUI = false;
#ifdef USE_QT_GUI_LOGIN
bForceGUI = Globals::globalConfig.bForceGUILogin;
#endif
if (!Globals::globalConfig.sEmail.empty() && !Globals::globalConfig.sPassword.empty())
{
email = Globals::globalConfig.sEmail;
password = Globals::globalConfig.sPassword;
}
else
else if (!bForceGUI)
{
if (!isatty(STDIN_FILENO)) {
/* Attempt to read this stuff from elsewhere */
@ -291,7 +295,7 @@ int Downloader::login()
}
}
if ((email.empty() || password.empty()) && !headless)
if ((email.empty() || password.empty()) && (!headless && !bForceGUI))
{
std::cerr << "Email and/or password empty" << std::endl;
return 0;

View File

@ -307,6 +307,10 @@ std::string Website::LoginGetAuthCode(const std::string& email, const std::strin
{
std::string auth_code;
bool bRecaptcha = false;
bool bForceGUI = false;
#ifdef USE_QT_GUI_LOGIN
bForceGUI = Globals::globalConfig.bForceGUILogin;
#endif
std::string auth_url = "https://auth.gog.com/auth?client_id=" + Globals::galaxyConf.getClientId() + "&redirect_uri=" + (std::string)curl_easy_escape(curlhandle, Globals::galaxyConf.getRedirectUri().c_str(), Globals::galaxyConf.getRedirectUri().size()) + "&response_type=code&layout=default&brand=gog";
@ -322,11 +326,21 @@ std::string Website::LoginGetAuthCode(const std::string& email, const std::strin
bRecaptcha = true;
}
// Try normal login if GUI is not forced
if (!bForceGUI)
{
auth_code = this->LoginGetAuthCodeCurl(login_form_html, email, password);
}
#ifdef USE_QT_GUI_LOGIN
if (Globals::globalConfig.bEnableLoginGUI && auth_code.empty())
if ((Globals::globalConfig.bEnableLoginGUI && auth_code.empty()) || bForceGUI)
{
auth_code = this->LoginGetAuthCodeGUI(email, password);
// If GUI is forced then stop here and don't offer browser login
if (bForceGUI)
return auth_code;
}
#endif
if (auth_code.empty() && bRecaptcha)