diff --git a/src/huggle_core/apiquery.cpp b/src/huggle_core/apiquery.cpp index 96ffdf5c3..49e593f7b 100644 --- a/src/huggle_core/apiquery.cpp +++ b/src/huggle_core/apiquery.cpp @@ -419,6 +419,10 @@ void ApiQuery::SetAction(const Action action) this->actionPart = "login"; this->EnforceLogin = false; return; + case ActionClientLogin: + this->ActionPart = "clientlogin"; + this->EnforceLogin = false; + return; case ActionLogout: this->actionPart = "logout"; return; diff --git a/src/huggle_core/apiquery.hpp b/src/huggle_core/apiquery.hpp index e75a1acf3..0a66ae52a 100644 --- a/src/huggle_core/apiquery.hpp +++ b/src/huggle_core/apiquery.hpp @@ -32,6 +32,7 @@ namespace Huggle ActionCompare, ActionQuery, ActionLogin, + ActionClientLogin, ActionLogout, //ActionTokens, ActionPurge, diff --git a/src/huggle_l10n/Localization/en.xml b/src/huggle_l10n/Localization/en.xml index 806beb362..8260fe0a1 100644 --- a/src/huggle_l10n/Localization/en.xml +++ b/src/huggle_l10n/Localization/en.xml @@ -315,6 +315,7 @@ Unable to download a db of wikis: $1 There are no projects defined in a list you need to set up some on global wiki the api query returned no data + This functionality is not yet implemented. Please contact developers at huggle@lists.wikimedia.org. $1 edits per minute, $2 reverts per minute, level $3 Stop provider Resume provider diff --git a/src/huggle_ui/loginform.cpp b/src/huggle_ui/loginform.cpp index db039a272..236d587c1 100644 --- a/src/huggle_ui/loginform.cpp +++ b/src/huggle_ui/loginform.cpp @@ -579,21 +579,20 @@ void LoginForm::performLoginPart2(WikiSite *site) this->Statuses[site] = WaitingForToken; this->LoginQueries.remove(site); query->DecRef(); - query = new ApiQuery(ActionLogin, site); + query = new ApiQuery(ActionClientLogin, site); this->LoginQueries.insert(site, query); - query->HiddenQuery = true; + //query->HiddenQuery = true; query->IncRef(); if (hcfg->SystemConfig_BotPassword) { - query->Parameters = "lgname=" + QUrl::toPercentEncoding(hcfg->SystemConfig_BotLogin) - + "&lgpassword=" + QUrl::toPercentEncoding(hcfg->TemporaryConfig_Password) - + "&lgtoken=" + QUrl::toPercentEncoding(token); + query->Parameters = "username=" + QUrl::toPercentEncoding(hcfg->SystemConfig_BotLogin) + + "&password=" + QUrl::toPercentEncoding(hcfg->TemporaryConfig_Password); } else { - query->Parameters = "lgname=" + QUrl::toPercentEncoding(hcfg->SystemConfig_Username) - + "&lgpassword=" + QUrl::toPercentEncoding(hcfg->TemporaryConfig_Password) - + "&lgtoken=" + QUrl::toPercentEncoding(token); + query->Parameters = "username=" + QUrl::toPercentEncoding(hcfg->SystemConfig_Username) + + "&password=" + QUrl::toPercentEncoding(hcfg->TemporaryConfig_Password); } + query->Parameters = query->Parameters + "&loginreturnurl=http://example.com/&rememberMe=1&logintoken=" + QUrl::toPercentEncoding(token); query->UsingPOST = true; query->Process(); } @@ -1338,9 +1337,10 @@ bool LoginForm::processOutput(WikiSite *site) ApiQuery *query = this->LoginQueries[site]; // Check what the result was ApiQueryResult *result = query->GetApiQueryResult(); - ApiQueryResultNode *ln = result->GetNode("login"); + ApiQueryResultNode *ln = result->GetNode("clientlogin"); QString result_code = ln->GetAttribute("result"); QString reason = ln->GetAttribute("reason"); + QString status = ln->GetAttribute("status"); if (result_code.isEmpty()) { this->displayError(_l("api.php-invalid-response")); @@ -1348,32 +1348,72 @@ bool LoginForm::processOutput(WikiSite *site) } if (result_code == "Success") return true; - if (result_code == "EmptyPass") - { - this->displayError(_l("login-password-empty")); - return false; - } - if (result_code == "WrongPass") + + if (status == "PASS") + return true; + + if (status == "UI") { - /// \bug This sometimes doesn't work properly - this->ui->lineEdit_password->setFocus(); - this->displayError(_l("login-error-password")); + // Need a user interaction like captacha or 2FA + //QString v_id = ln->ChildNodes.at(0)->GetAttribute("id", "unknown"); + //if (v_id == "TOTPAuthenticationRequest"){ + if (true) + { + // 2FA is requierd (TOTP code needed) + QString totp = QInputDialog::getText(this, "Two factor authentification", "Please enter the 2FA code from your device:"); + query = new ApiQuery(ActionClientLogin, site); + //query->HiddenQuery = true; + query->IncRef(); + query->Parameters = "username=" + QUrl::toPercentEncoding(hcfg->SystemConfig_BotLogin) + + "&password=" + QUrl::toPercentEncoding(hcfg->TemporaryConfig_Password) + + "&OATHToken=" + totp + + + "&logintoken=" + QUrl::toPercentEncoding(this->Tokens[site]) + + "&logincontinue=1&rememberMe=1"; + query->UsingPOST = true; + query->Process(); + ApiQueryResult *result = query->GetApiQueryResult(); + ApiQueryResultNode *ln = result->GetNode("clientlogin"); + } return false; } - if (result_code == "NoName") + if (status == "REDIRECT") { - this->displayError(_l("login-fail-wrong-name")); + // Need to login using another web service + this->DisplayError(_l("not-implemented")); return false; } - if (result_code == "NotExists") + if (status == "FAIL") { - this->displayError(_l("login-username-doesnt-exist")); + QString message = ln->GetAttribute("message"); + QString message_code = ln->GetAttribute("messagecode"); + if (message_code == "wrongpassword") + { + /// \bug This sometimes doesn't work properly + this->ui->lineEdit_password->setFocus(); + this->DisplayError(_l("login-error-password")); + return false; + } + /// \todo Verify these error codes + if (message_code == "EmptyPass") + { + this->DisplayError(_l("login-password-empty")); + return false; + } + if (message_code == "NoName") + { + this->DisplayError(_l("login-fail-wrong-name")); + return false; + } + if (message_code == "NotExists") + { + this->DisplayError(_l("login-username-doesnt-exist")); + return false; + } + if (message.isEmpty()) + message = message_code; + this->DisplayError(_l("login-api", message)); return false; } - if (reason.isEmpty()) - reason = result_code; - this->displayError(_l("login-api", reason)); - return false; } void LoginForm::on_ButtonOK_clicked()