Task #3964 - Make premium login error more verbose
This commit is contained in:
parent
44a98c6c9d
commit
f9fe1130ac
|
@ -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();
|
||||
|
||||
QString responseJson;
|
||||
try
|
||||
{
|
||||
PremiumAuth auth;
|
||||
QString responseJson = auth.request(email, password);
|
||||
|
||||
if (responseJson.trimmed() == "") {
|
||||
message.setText(tr("Login failed, could not communicate with server."));
|
||||
message.exec();
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -25,16 +25,48 @@
|
|||
//#define PREMIUM_AUTH_URL "http://localhost/synergy/premium/json/auth/"
|
||||
#define PREMIUM_AUTH_URL "https://synergy-foss.org/premium/json/auth/"
|
||||
|
||||
int
|
||||
enum {
|
||||
kErrorOk,
|
||||
kErrorArgs,
|
||||
kErrorException,
|
||||
kErrorUnknown
|
||||
};
|
||||
|
||||
UInt32
|
||||
CToolApp::run(int argc, char** argv)
|
||||
{
|
||||
if (argc <= 1) {
|
||||
std::cerr << "no args" << std::endl;
|
||||
return 1;
|
||||
return kErrorArgs;
|
||||
}
|
||||
|
||||
try {
|
||||
for (int i = 1; i < argc; i++) {
|
||||
if (strcmp(argv[i], "--premium-auth") == 0) {
|
||||
premiumAuth();
|
||||
return kErrorOk;
|
||||
}
|
||||
else {
|
||||
std::cerr << "unknown arg: " << argv[i] << std::endl;
|
||||
return kErrorArgs;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (std::exception& e) {
|
||||
std::cerr << e.what() << std::endl;
|
||||
return kErrorException;
|
||||
}
|
||||
catch (...) {
|
||||
std::cerr << "unknown error" << std::endl;
|
||||
return kErrorUnknown;
|
||||
}
|
||||
|
||||
return kErrorOk;
|
||||
}
|
||||
|
||||
void
|
||||
CToolApp::premiumAuth()
|
||||
{
|
||||
CString credentials;
|
||||
std::cin >> credentials;
|
||||
|
||||
|
@ -48,13 +80,4 @@ CToolApp::run(int argc, char** argv)
|
|||
ss << "&password=" << password;
|
||||
|
||||
std::cout << ARCH->internet().get(ss.str()) << std::endl;
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
std::cerr << "unknown arg: " << argv[i] << std::endl;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,12 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "common/basic_types.h"
|
||||
|
||||
class CToolApp {
|
||||
public:
|
||||
int run(int argc, char** argv);
|
||||
UInt32 run(int argc, char** argv);
|
||||
|
||||
private:
|
||||
void premiumAuth();
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue