|
33 | 33 | #include <QSslSocket> |
34 | 34 | #include <QDesktopServices> |
35 | 35 | #include <QMessageBox> |
| 36 | +#include <QInputDialog> |
36 | 37 |
|
37 | 38 | #define LOGINFORM_LOGIN 0 |
38 | 39 | #define LOGINFORM_SITEINFO 1 |
@@ -554,21 +555,20 @@ void Login::PerformLoginPart2(WikiSite *site) |
554 | 555 | this->Statuses[site] = WaitingForToken; |
555 | 556 | this->LoginQueries.remove(site); |
556 | 557 | query->DecRef(); |
557 | | - query = new ApiQuery(ActionLogin, site); |
| 558 | + query = new ApiQuery(ClientLogin, site); |
558 | 559 | this->LoginQueries.insert(site, query); |
559 | | - query->HiddenQuery = true; |
| 560 | + //query->HiddenQuery = true; |
560 | 561 | query->IncRef(); |
561 | 562 | if (hcfg->SystemConfig_BotPassword) |
562 | 563 | { |
563 | | - query->Parameters = "lgname=" + QUrl::toPercentEncoding(hcfg->SystemConfig_BotLogin) |
564 | | - + "&lgpassword=" + QUrl::toPercentEncoding(hcfg->TemporaryConfig_Password) |
565 | | - + "&lgtoken=" + QUrl::toPercentEncoding(token); |
| 564 | + query->Parameters = "username=" + QUrl::toPercentEncoding(hcfg->SystemConfig_BotLogin) |
| 565 | + + "&password=" + QUrl::toPercentEncoding(hcfg->TemporaryConfig_Password); |
566 | 566 | } else |
567 | 567 | { |
568 | | - query->Parameters = "lgname=" + QUrl::toPercentEncoding(hcfg->SystemConfig_Username) |
569 | | - + "&lgpassword=" + QUrl::toPercentEncoding(hcfg->TemporaryConfig_Password) |
570 | | - + "&lgtoken=" + QUrl::toPercentEncoding(token); |
| 568 | + query->Parameters = "username=" + QUrl::toPercentEncoding(hcfg->SystemConfig_Username) |
| 569 | + + "&password=" + QUrl::toPercentEncoding(hcfg->TemporaryConfig_Password); |
571 | 570 | } |
| 571 | + query->Parameters = query->Parameters + "&loginreturnurl=http://example.com/&rememberMe=1&logintoken=" + QUrl::toPercentEncoding(token); |
572 | 572 | query->UsingPOST = true; |
573 | 573 | query->Process(); |
574 | 574 | } |
@@ -1269,42 +1269,71 @@ bool Login::ProcessOutput(WikiSite *site) |
1269 | 1269 | ApiQuery *query = this->LoginQueries[site]; |
1270 | 1270 | // Check what the result was |
1271 | 1271 | ApiQueryResult *result = query->GetApiQueryResult(); |
1272 | | - ApiQueryResultNode *ln = result->GetNode("login"); |
1273 | | - QString result_code = ln->GetAttribute("result"); |
1274 | | - QString reason = ln->GetAttribute("reason"); |
1275 | | - if (result_code.isEmpty()) |
| 1272 | + ApiQueryResultNode *ln = result->GetNode("clientlogin"); |
| 1273 | + QString status = ln->GetAttribute("status"); |
| 1274 | + if (status.isEmpty()) |
1276 | 1275 | { |
1277 | 1276 | this->DisplayError(_l("api.php-invalid-response")); |
1278 | 1277 | return false; |
1279 | 1278 | } |
1280 | | - if (result_code == "Success") |
| 1279 | + |
| 1280 | + if (status == "PASS") |
1281 | 1281 | return true; |
1282 | | - if (result_code == "EmptyPass") |
1283 | | - { |
1284 | | - this->DisplayError(_l("login-password-empty")); |
| 1282 | + if (status == "UI") { |
| 1283 | + // Need a user interaction like captacha or 2FA |
| 1284 | + //QString v_id = ln->ChildNodes.at(0)->GetAttribute("id", "unknown"); |
| 1285 | + //if (v_id == "TOTPAuthenticationRequest"){ |
| 1286 | + if (true){ |
| 1287 | + // 2FA is requierd (TOTP code needed) |
| 1288 | + QString totp = QInputDialog::getText(this, "Two factor authentification", "Please enter the 2FA code from your device:"); |
| 1289 | + query = new ApiQuery(ClientLogin, site); |
| 1290 | + //query->HiddenQuery = true; |
| 1291 | + query->IncRef(); |
| 1292 | + query->Parameters = "username=" + QUrl::toPercentEncoding(hcfg->SystemConfig_BotLogin) |
| 1293 | + + "&password=" + QUrl::toPercentEncoding(hcfg->TemporaryConfig_Password) |
| 1294 | + + "&OATHToken=" + totp + "&loginreturnurl=http://example.com/&rememberMe=1&logintoken=" + QUrl::toPercentEncoding(this->Tokens[site]); |
| 1295 | + query->UsingPOST = true; |
| 1296 | + query->Process(); |
| 1297 | + ApiQueryResult *result = query->GetApiQueryResult(); |
| 1298 | + ApiQueryResultNode *ln = result->GetNode("clientlogin"); |
| 1299 | + } |
1285 | 1300 | return false; |
1286 | 1301 | } |
1287 | | - if (result_code == "WrongPass") |
1288 | | - { |
1289 | | - /// \bug This sometimes doesn't work properly |
1290 | | - this->ui->lineEdit_password->setFocus(); |
1291 | | - this->DisplayError(_l("login-error-password")); |
| 1302 | + if (status == "REDIRECT") |
| 1303 | + // Need to login using another web service |
| 1304 | + this->DisplayError(_l("not-implemented")); |
1292 | 1305 | return false; |
1293 | | - } |
1294 | | - if (result_code == "NoName") |
| 1306 | + if (status == "FAIL") |
1295 | 1307 | { |
1296 | | - this->DisplayError(_l("login-fail-wrong-name")); |
1297 | | - return false; |
1298 | | - } |
1299 | | - if (result_code == "NotExists") |
1300 | | - { |
1301 | | - this->DisplayError(_l("login-username-doesnt-exist")); |
| 1308 | + QString message = ln->GetAttribute("message"); |
| 1309 | + QString message_code = ln->GetAttribute("messagecode"); |
| 1310 | + if (message_code == "wrongpassword") { |
| 1311 | + /// \bug This sometimes doesn't work properly |
| 1312 | + this->ui->lineEdit_password->setFocus(); |
| 1313 | + this->DisplayError(_l("login-error-password")); |
| 1314 | + return false; |
| 1315 | + } |
| 1316 | + /// \todo Verify these error codes |
| 1317 | + if (message_code == "EmptyPass") |
| 1318 | + { |
| 1319 | + this->DisplayError(_l("login-password-empty")); |
| 1320 | + return false; |
| 1321 | + } |
| 1322 | + if (message_code == "NoName") |
| 1323 | + { |
| 1324 | + this->DisplayError(_l("login-fail-wrong-name")); |
| 1325 | + return false; |
| 1326 | + } |
| 1327 | + if (message_code == "NotExists") |
| 1328 | + { |
| 1329 | + this->DisplayError(_l("login-username-doesnt-exist")); |
| 1330 | + return false; |
| 1331 | + } |
| 1332 | + if (message.isEmpty()) |
| 1333 | + message = message_code; |
| 1334 | + this->DisplayError(_l("login-api", message)); |
1302 | 1335 | return false; |
1303 | 1336 | } |
1304 | | - if (reason.isEmpty()) |
1305 | | - reason = result_code; |
1306 | | - this->DisplayError(_l("login-api", reason)); |
1307 | | - return false; |
1308 | 1337 | } |
1309 | 1338 |
|
1310 | 1339 | void Login::on_ButtonOK_clicked() |
|
0 commit comments