mirror of
https://github.com/debauchee/barrier.git
synced 2026-07-01 01:16:39 +08:00
Task #3964 - Make premium login error more verbose
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
|
||||
#include <QProcess>
|
||||
#include <QCoreApplication>
|
||||
#include <stdexcept>
|
||||
|
||||
// we use syntool to authenticate because Qt's http library is very
|
||||
// unreliable, and since we're writing platform specific code, use the
|
||||
@@ -32,17 +33,35 @@ QString PremiumAuth::request(const QString& email, const QString& password)
|
||||
QProcess process;
|
||||
process.setReadChannel(QProcess::StandardOutput);
|
||||
process.start(program, args);
|
||||
bool success = process.waitForStarted();
|
||||
|
||||
if (process.waitForStarted())
|
||||
QString out, error;
|
||||
if (success)
|
||||
{
|
||||
// hash password in case it contains interesting chars.
|
||||
QString credentials(email + ":" + hash(password) + "\n");
|
||||
process.write(credentials.toStdString().c_str());
|
||||
|
||||
if (process.waitForFinished()) {
|
||||
return process.readAll();
|
||||
out = process.readAllStandardOutput();
|
||||
error = process.readAllStandardError();
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
out = out.trimmed();
|
||||
error = error.trimmed();
|
||||
|
||||
if (out.isEmpty() ||
|
||||
!error.isEmpty() ||
|
||||
!success ||
|
||||
process.exitCode() != 0)
|
||||
{
|
||||
throw std::runtime_error(
|
||||
QString("Code: %1\nError: %2")
|
||||
.arg(process.exitCode())
|
||||
.arg(error.isEmpty() ? "Unknown" : error)
|
||||
.toStdString());
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -252,12 +252,20 @@ bool SetupWizard::isPremiumLoginValid(QMessageBox& message)
|
||||
QString email = m_pLineEditPremiumEmail->text();
|
||||
QString password = m_pLineEditPremiumPassword->text();
|
||||
|
||||
PremiumAuth auth;
|
||||
QString responseJson = auth.request(email, password);
|
||||
|
||||
if (responseJson.trimmed() == "") {
|
||||
message.setText(tr("Login failed, could not communicate with server."));
|
||||
message.exec();
|
||||
QString responseJson;
|
||||
try
|
||||
{
|
||||
PremiumAuth auth;
|
||||
responseJson = auth.request(email, password);
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
message.critical(
|
||||
this, "Error",
|
||||
tr("Sorry, an error occured while trying to sign in. "
|
||||
"Please contact the help desk, and provide the "
|
||||
"following details.\n\n%1")
|
||||
.arg(e.what()));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -268,8 +276,9 @@ bool SetupWizard::isPremiumLoginValid(QMessageBox& message)
|
||||
return true;
|
||||
}
|
||||
else if (boolString == "false") {
|
||||
message.setText(tr("Login failed, invalid email or password."));
|
||||
message.exec();
|
||||
message.critical(
|
||||
this, "Error",
|
||||
tr("Login failed, invalid email or password."));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -280,13 +289,16 @@ bool SetupWizard::isPremiumLoginValid(QMessageBox& message)
|
||||
// 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();
|
||||
message.critical(
|
||||
this, "Error",
|
||||
tr("Login failed, an error occurred.\n\n%1").arg(error));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
message.setText(tr("Login failed, an error occurred.\n\nServer response:\n\n%1").arg(responseJson));
|
||||
message.exec();
|
||||
message.critical(
|
||||
this, "Error",
|
||||
tr("Login failed, an error occurred.\n\nServer response:\n\n%1")
|
||||
.arg(responseJson));
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user