Fix AWS credentials getting lost

This commit is contained in:
Michael Zanetti 2019-07-28 01:34:39 +02:00
parent 08b0ab99bb
commit d3a8d3efa1
3 changed files with 27 additions and 10 deletions

View File

@ -152,7 +152,7 @@ bool AWSClient::confirmationPending() const
return m_confirmationPending;
}
void AWSClient::login(const QString &username, const QString &password, int attempt)
void AWSClient::login(const QString &username, const QString &password)
{
if (m_loginInProgress) {
qWarning() << "Login already pending...";
@ -196,17 +196,23 @@ void AWSClient::login(const QString &username, const QString &password, int atte
qDebug() << "Logging in to AWS as user:" << username;
QNetworkReply *reply = m_nam->post(request, payload);
connect(reply, &QNetworkReply::finished, this, [this, reply, username, password, attempt]() {
connect(reply, &QNetworkReply::finished, this, [this, reply, username, password]() {
reply->deleteLater();
m_loginInProgress = false;
if (reply->error() != QNetworkReply::NoError) {
qWarning() << "Error logging in to aws:" << reply->error() << reply->errorString();
if (attempt < 3) {
login(username, password, attempt+1);
if (reply->error() == QNetworkReply::HostNotFoundError) {
qDebug() << "Error logging in to aws due to network connection.";
emit loginResult(LoginErrorNetworkError);
return;
}
m_username.clear();
m_password.clear();
if (reply->error() == QNetworkReply::ProtocolInvalidOperationError) {
qWarning() << "Looks like a wrong password.";
m_username.clear();
m_password.clear();
emit loginResult(LoginErrorInvalidUserOrPass);
return;
}
qWarning() << "Error logging in to aws. Error:" << reply->error() << reply->errorString();
emit loginResult(LoginErrorUnknownError);
return;
}

View File

@ -94,7 +94,8 @@ public:
LoginErrorInvalidCode,
LoginErrorUserExists,
LoginErrorLimitExceeded,
LoginErrorUnknownError
LoginErrorUnknownError,
LoginErrorNetworkError
};
Q_ENUM(LoginError)
@ -106,7 +107,7 @@ public:
AWSDevices* awsDevices() const;
bool confirmationPending() const;
Q_INVOKABLE void login(const QString &username, const QString &password, int attempt = -1);
Q_INVOKABLE void login(const QString &username, const QString &password);
Q_INVOKABLE void logout();
Q_INVOKABLE void signup(const QString &username, const QString &password);
Q_INVOKABLE void confirmRegistration(const QString &code);

View File

@ -215,6 +215,17 @@ Page {
Connections {
target: AWSClient
onLoginResult: {
switch (error) {
case AWSClient.LoginErrorInvalidUserOrPass:
errorLabel.text = qsTr("Failed to log in. Please try again. Do you perhaps have <a href=\"#\">forgotten your password?</a>")
break;
case AWSClient.LoginErrorNetworkError:
errorLabel.text = qsTr("Failed to connect to the login server. Please mase sure your network connection is working.")
break;
default:
errorLabel.text = qsTr("An unexpected error happened. Please report this isse. Error code:", error)
break;
}
errorLabel.visible = (error !== AWSClient.LoginErrorNoError)
}
}
@ -224,7 +235,6 @@ Page {
Layout.fillWidth: true
Layout.leftMargin: app.margins; Layout.rightMargin: app.margins; Layout.bottomMargin: app.margins
wrapMode: Text.WordWrap
text: qsTr("Failed to log in. Please try again. Do you perhaps have <a href=\"#\">forgotten your password?</a>")
font.pixelSize: app.smallFont
color: "red"
visible: false