void LoginDialog::OnLoginPageFinished() { QNetworkReply *reply = qobject_cast<QNetworkReply *>(QObject::sender()); if (reply->error()) { DisplayError("Network error: " + reply->errorString()); return; } switch (ui->loginTabs->currentIndex()) { case LOGIN_PASSWORD: { QByteArray bytes = reply->readAll(); std::string page(bytes.constData(), bytes.size()); std::string hash = Util::GetCsrfToken(page, "hash"); if (hash.empty()) { DisplayError("Failed to log in (can't extract form hash from page)"); return; } QUrlQuery query; query.addQueryItem("login_email", EncodeSpecialCharacters(ui->emailLineEdit->text())); query.addQueryItem("login_password", EncodeSpecialCharacters(ui->passwordLineEdit->text())); query.addQueryItem("hash", QString(hash.c_str())); query.addQueryItem("login", "Login"); QUrl url(POE_LOGIN_URL); QByteArray data(query.query().toUtf8()); QNetworkRequest request(url); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); QNetworkReply *logged_in = login_manager_->post(request, data); connect(logged_in, SIGNAL(finished()), this, SLOT(OnLoggedIn())); break; } case LOGIN_STEAM: { if (!steam_login_dialog_) InitSteamDialog(); steam_login_dialog_->show(); steam_login_dialog_->Init(); break; } case LOGIN_SESSIONID: { LoginWithCookie(ui->sessionIDLineEdit->text()); break; } } }
void LoginDialog::OnLoginButtonClicked() { ui->loginButton->setEnabled(false); ui->loginButton->setText("Logging in..."); switch (ui->loginTabs->currentIndex()) { case LOGIN_PASSWORD: { // Get POE_LOGIN_URL to retrieve the csrf token QNetworkReply *login_page = login_manager_->get(QNetworkRequest(QUrl(POE_LOGIN_URL))); connect(login_page, SIGNAL(finished()), this, SLOT(OnLoginPageFinished())); break; } case LOGIN_STEAM: { if (!steam_login_dialog_) InitSteamDialog(); steam_login_dialog_->show(); steam_login_dialog_->Init(); break; } case LOGIN_SESSIONID: { LoginWithCookie(ui->sessionIDLineEdit->text()); break; } } }