don't give up too fast when AWS login fails, also prevent multiple simultaneous login attempts
This commit is contained in:
parent
c294c12533
commit
d1a77654e3
@ -131,8 +131,14 @@ bool AWSClient::confirmationPending() const
|
||||
return m_confirmationPending;
|
||||
}
|
||||
|
||||
void AWSClient::login(const QString &username, const QString &password)
|
||||
void AWSClient::login(const QString &username, const QString &password, int attempt)
|
||||
{
|
||||
if (m_loginInProgress) {
|
||||
qWarning() << "Login already pending...";
|
||||
return;
|
||||
}
|
||||
m_loginInProgress = true;
|
||||
|
||||
m_username = username;
|
||||
// Due to an issue in AWS apis it's very complex to use the refresh token. Taking a shortcut here for now:
|
||||
// Will store the password in the config for now and re-login when the accessToken expires.
|
||||
@ -169,10 +175,15 @@ void AWSClient::login(const QString &username, const QString &password)
|
||||
qDebug() << "Logging in to AWS as user:" << username;
|
||||
|
||||
QNetworkReply *reply = m_nam->post(request, payload);
|
||||
connect(reply, &QNetworkReply::finished, this, [this, reply]() {
|
||||
connect(reply, &QNetworkReply::finished, this, [this, reply, username, password, attempt]() {
|
||||
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);
|
||||
return;
|
||||
}
|
||||
m_username.clear();
|
||||
m_password.clear();
|
||||
emit loginResult(LoginErrorUnknownError);
|
||||
|
||||
@ -103,7 +103,7 @@ public:
|
||||
AWSDevices* awsDevices() const;
|
||||
bool confirmationPending() const;
|
||||
|
||||
Q_INVOKABLE void login(const QString &username, const QString &password);
|
||||
Q_INVOKABLE void login(const QString &username, const QString &password, int attempt = -1);
|
||||
Q_INVOKABLE void logout();
|
||||
Q_INVOKABLE void signup(const QString &username, const QString &password);
|
||||
Q_INVOKABLE void confirmRegistration(const QString &code);
|
||||
@ -154,6 +154,8 @@ private:
|
||||
QString m_username;
|
||||
QString m_password;
|
||||
|
||||
bool m_loginInProgress = false;
|
||||
|
||||
bool m_confirmationPending = false;
|
||||
|
||||
QByteArray m_accessToken;
|
||||
|
||||
Reference in New Issue
Block a user