mirror of
https://github.com/Sude-/lgogdownloader.git
synced 2024-11-20 11:49:17 +01:00
GUI: Add autofill
Make login GUI automatically fill email and password fields Users no longer need to type email and password again just because normal login method failed due to reCAPTCHA and GUI was launched
This commit is contained in:
parent
ea0ec2a9bd
commit
deb29802d2
@ -25,6 +25,7 @@ class GuiLogin : public QObject
|
||||
virtual ~GuiLogin();
|
||||
|
||||
void Login();
|
||||
void Login(const std::string& username, const std::string& password);
|
||||
std::string getCode();
|
||||
std::vector<std::string> getCookies();
|
||||
|
||||
@ -32,6 +33,8 @@ class GuiLogin : public QObject
|
||||
QWebEngineCookieStore *cookiestore;
|
||||
std::vector<std::string> cookies;
|
||||
std::string auth_code;
|
||||
std::string login_username;
|
||||
std::string login_password;
|
||||
|
||||
public slots:
|
||||
void loadFinished(bool success);
|
||||
|
@ -28,7 +28,20 @@ void GuiLogin::loadFinished(bool success)
|
||||
{
|
||||
QWebEngineView *view = qobject_cast<QWebEngineView*>(sender());
|
||||
std::string url = view->page()->url().toString().toUtf8().constData();
|
||||
if (success && url.find("https://embed.gog.com/on_login_success") != std::string::npos)
|
||||
|
||||
// Autofill login form
|
||||
if (success && url.find("https://login.gog.com/auth?client_id=") != std::string::npos)
|
||||
{
|
||||
if (!this->login_username.empty() && !this->login_password.empty())
|
||||
{
|
||||
std::string js_fill_username = "document.getElementById(\"login_username\").value = \"" + this->login_username + "\";";
|
||||
std::string js_fill_password = "document.getElementById(\"login_password\").value = \"" + this->login_password + "\";";
|
||||
std::string js = js_fill_username + js_fill_password;
|
||||
view->page()->runJavaScript(QString::fromStdString(js));
|
||||
}
|
||||
}
|
||||
// Get auth code
|
||||
else if (success && url.find("https://embed.gog.com/on_login_success") != std::string::npos)
|
||||
{
|
||||
std::string find_str = "code=";
|
||||
auto pos = url.find(find_str);
|
||||
@ -67,10 +80,17 @@ void GuiLogin::cookieAdded(const QNetworkCookie& cookie)
|
||||
}
|
||||
|
||||
void GuiLogin::Login()
|
||||
{
|
||||
this->Login(std::string(), std::string());
|
||||
}
|
||||
|
||||
void GuiLogin::Login(const std::string& username, const std::string& password)
|
||||
{
|
||||
QByteArray redirect_uri = QUrl::toPercentEncoding(QString::fromStdString(Globals::galaxyConf.getRedirectUri()));
|
||||
std::string auth_url = "https://auth.gog.com/auth?client_id=" + Globals::galaxyConf.getClientId() + "&redirect_uri=" + redirect_uri.toStdString() + "&response_type=code";
|
||||
QUrl url = QString::fromStdString(auth_url);
|
||||
this->login_username = username;
|
||||
this->login_password = password;
|
||||
|
||||
std::vector<char> version_string(
|
||||
Globals::globalConfig.sVersionString.c_str(),
|
||||
|
@ -323,7 +323,7 @@ int Website::Login(const std::string& email, const std::string& password)
|
||||
return res = 0;
|
||||
}
|
||||
GuiLogin gl;
|
||||
gl.Login();
|
||||
gl.Login(email, password);
|
||||
|
||||
auto cookies = gl.getCookies();
|
||||
for (auto cookie : cookies)
|
||||
|
Loading…
Reference in New Issue
Block a user