From cd91c1ea5bb356e81c4c4b977cf0cbc7423f555a Mon Sep 17 00:00:00 2001 From: Mathieu Pellerin Date: Thu, 19 Oct 2023 10:01:20 +0700 Subject: [PATCH] Fix wrong user/password state misrepresented as expired session --- src/core/qfieldcloudconnection.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/core/qfieldcloudconnection.cpp b/src/core/qfieldcloudconnection.cpp index e73cde231f..99e2117c59 100644 --- a/src/core/qfieldcloudconnection.cpp +++ b/src/core/qfieldcloudconnection.cpp @@ -138,7 +138,8 @@ CloudUserInformation QFieldCloudConnection::userInformation() const void QFieldCloudConnection::login() { - NetworkReply *reply = ( !mToken.isEmpty() && ( mPassword.isEmpty() || mUsername.isEmpty() ) ) + const bool loginUsingToken = !mToken.isEmpty() && ( mPassword.isEmpty() || mUsername.isEmpty() ); + NetworkReply *reply = loginUsingToken ? get( QStringLiteral( "/api/v1/auth/user/" ) ) : post( QStringLiteral( "/api/v1/auth/token/" ), QVariantMap( { @@ -181,14 +182,16 @@ void QFieldCloudConnection::login() { emit loginFailed( tr( "Timeout error, please retry" ) ); } - else if ( httpCode == 400 ) + else if ( httpCode == 400 || httpCode == 401 ) { - emit loginFailed( tr( "Wrong username or password" ) ); - } - else if ( httpCode == 401 ) - { - emit loginFailed( tr( "Session expired" ) ); - invalidateToken(); + if ( !loginUsingToken ) + { + emit loginFailed( tr( "Wrong username or password" ) ); + } + else + { + emit loginFailed( tr( "Session expired" ) ); + } } else {