diff --git a/include/config.h b/include/config.h index 5567073..804b8ea 100644 --- a/include/config.h +++ b/include/config.h @@ -232,6 +232,7 @@ class Config // Booleans bool bLogin; + bool bForceBrowserLogin; bool bSaveConfig; bool bResetConfig; diff --git a/main.cpp b/main.cpp index f3076a7..3b3050f 100644 --- a/main.cpp +++ b/main.cpp @@ -206,6 +206,7 @@ int main(int argc, char *argv[]) #ifdef USE_QT_GUI_LOGIN ("gui-login", bpo::value(&Globals::globalConfig.bForceGUILogin)->zero_tokens()->default_value(false), "Login (force GUI login)\nImplies --enable-login-gui") #endif + ("browser-login", bpo::value(&Globals::globalConfig.bForceBrowserLogin)->zero_tokens()->default_value(false), "Login (force browser login)") ("check-login-status", bpo::value(&bCheckLoginStatus)->zero_tokens()->default_value(false), "Check login status") ("list", bpo::value(&sListFormat)->implicit_value("games"), list_format_text.c_str()) ("download", bpo::value(&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"; diff --git a/man/lgogdownloader.1 b/man/lgogdownloader.1 index 54abdc8..65b20d0 100644 --- a/man/lgogdownloader.1 +++ b/man/lgogdownloader.1 @@ -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 diff --git a/src/downloader.cpp b/src/downloader.cpp index 535f0ff..d743295 100644 --- a/src/downloader.cpp +++ b/src/downloader.cpp @@ -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; } diff --git a/src/website.cpp b/src/website.cpp index cc1645e..a414e83 100644 --- a/src/website.cpp +++ b/src/website.cpp @@ -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;