- fixed: windows http get exceptions stop cleanup.

- made premium auth errors more tidy.
This commit is contained in:
Nick Bolton
2014-02-05 16:28:29 +00:00
parent 5ca1c17549
commit 456e56d5dc
4 changed files with 179 additions and 56 deletions

View File

@@ -24,7 +24,7 @@
// we use syntool to authenticate because Qt's http library is very
// unreliable, and since we're writing platform specific code, use the
// synergy code since there we can use integ tests.
QString PremiumAuth::auth(const QString& email, const QString& password)
QString PremiumAuth::request(const QString& email, const QString& password)
{
QString program(QCoreApplication::applicationDirPath() + "/syntool");
QStringList args("--premium-auth");
@@ -40,7 +40,7 @@ QString PremiumAuth::auth(const QString& email, const QString& password)
process.write(credentials.toStdString().c_str());
if (process.waitForFinished()) {
return process.readLine();
return process.readAll();
}
}

View File

@@ -22,5 +22,5 @@
class PremiumAuth
{
public:
QString auth(const QString& email, const QString& password);
QString request(const QString& email, const QString& password);
};

View File

@@ -253,13 +253,17 @@ bool SetupWizard::isPremiumLoginValid(QMessageBox& message)
QString password = m_pLineEditPremiumPassword->text();
PremiumAuth auth;
QString responseJson = auth.auth(email, password);
QString responseJson = auth.request(email, password);
// this feels like a lot of work, but its cheaper than getting a json
// parsing library involved.
QRegExp regex(".*\"result\":\\s*([^,}\\s]+).*");
if (regex.exactMatch(responseJson)) {
QString boolString = regex.cap(1);
if (responseJson.trimmed() == "") {
message.setText(tr("Login failed, could not communicate with server."));
message.exec();
return false;
}
QRegExp resultRegex(".*\"result\".*:.*(true|false).*");
if (resultRegex.exactMatch(responseJson)) {
QString boolString = resultRegex.cap(1);
if (boolString == "true") {
return true;
}
@@ -269,8 +273,20 @@ bool SetupWizard::isPremiumLoginValid(QMessageBox& message)
return false;
}
}
else {
QRegExp errorRegex(".*\"error\".*:.*\"(.+)\".*");
if (errorRegex.exactMatch(responseJson)) {
message.setText(tr("Login failed, an error occurred.\n\nServer response:\n\n%1").arg(responseJson.trimmed()));
// replace "\n" with real new lines.
QString error = errorRegex.cap(1).replace("\\n", "\n");
message.setText(tr("Login failed, an error occurred.\n\n%1").arg(error));
message.exec();
return false;
}
}
message.setText(tr("Login failed, an error occurred.\n\nServer response:\n\n%1").arg(responseJson));
message.exec();
return false;
}