Skip to content

Commit

Permalink
Fix wrong user/password state misrepresented as expired session
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn authored and github-actions[bot] committed Oct 19, 2023
1 parent 4e2f4f4 commit cd91c1e
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/core/qfieldcloudconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
Expand Down Expand Up @@ -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
{
Expand Down

0 comments on commit cd91c1e

Please sign in to comment.