diff --git a/app/main.cpp b/app/main.cpp index b7911356c..663311030 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -567,18 +567,18 @@ int main( int argc, char *argv[] ) syncManager.syncProject( project, SyncOptions::Authorized, SyncOptions::Retry ); } ); - QObject::connect( &activeProject, &ActiveProject::projectReloaded, &lambdaContext, [merginApi = ma.get(), &activeProject]() - { - merginApi->reloadProjectRole( activeProject.projectFullName() ); - } ); - - QObject::connect( ma.get(), &MerginApi::authChanged, &lambdaContext, [merginApi = ma.get(), &activeProject]() - { - if ( activeProject.isProjectLoaded() ) - { - merginApi->reloadProjectRole( activeProject.projectFullName() ); - } - } ); + // QObject::connect( &activeProject, &ActiveProject::projectReloaded, &lambdaContext, [merginApi = ma.get(), &activeProject]() + // { + // merginApi->reloadProjectRole( activeProject.projectFullName() ); + // } ); + + // QObject::connect( ma.get(), &MerginApi::authChanged, &lambdaContext, [merginApi = ma.get(), &activeProject]() + // { + // if ( activeProject.isProjectLoaded() ) + // { + // merginApi->reloadProjectRole( activeProject.projectFullName() ); + // } + // } ); QObject::connect( ma.get(), &MerginApi::projectRoleUpdated, &activeProject, [&activeProject]( const QString & projectFullName, const QString & role ) { diff --git a/core/credentialstore.h b/core/credentialstore.h index 53e61bff3..f8b80728c 100644 --- a/core/credentialstore.h +++ b/core/credentialstore.h @@ -37,6 +37,7 @@ class CredentialStore : public QObject signals: //! Emitted when a key is read, with both key and its retrieved value. void keyRead( const QString &key, const QString &value ); + //void credentialsLoaded(); }; diff --git a/core/merginapi.cpp b/core/merginapi.cpp index 8b95139a5..807aba8ef 100644 --- a/core/merginapi.cpp +++ b/core/merginapi.cpp @@ -114,6 +114,7 @@ MerginApi::MerginApi( LocalProjectsManager &localProjects, QObject *parent ) QObject::connect( mUserAuth, &MerginUserAuth::credentialsLoaded, this, [this]() { + qDebug() << "REACHED HERE! "; QObject::connect( this, &MerginApi::pingMerginFinished, this, &MerginApi::getUserInfo, Qt::SingleShotConnection ); QObject::connect( this, &MerginApi::userInfoReplyFinished, this, &MerginApi::getWorkspaceInfo, Qt::SingleShotConnection ); } ); diff --git a/core/merginuserauth.cpp b/core/merginuserauth.cpp index a4fa79ce0..8bc409524 100644 --- a/core/merginuserauth.cpp +++ b/core/merginuserauth.cpp @@ -108,150 +108,60 @@ void MerginUserAuth::saveAuthData() #endif } -// void MerginUserAuth::loadAuthData() -// { -// #if defined(Q_OS_ANDROID) || defined(Q_OS_IOS) -// // mobile => QtKeychain -// connect( mCredentialStore, &CredentialStore::keyRead, this, [this]( const QString & key, const QVariant & value ) //read credentials in chain to emit authChanged only -// { -// if ( key == "username" ) -// { -// mUsername = value.toString(); -// mCredentialStore->readKey( "password" ); -// } -// else if ( key == "password" ) -// { -// mPassword = value.toString(); -// mCredentialStore->readKey( "userId" ); -// } -// else if ( key == "userId" ) -// { -// mUserId = value.toInt(); -// mCredentialStore->readKey( "token" ); -// } -// else if ( key == "token" ) -// { -// mAuthToken = value.toByteArray(); -// mCredentialStore->readKey( "expire" ); -// } -// else if ( key == "expire" ) -// { -// mTokenExpiration = value.toDateTime(); - -// if ( mTokenExpiration < QDateTime::currentDateTimeUtc() ) -// { -// clearTokenData(); -// } - -// emit authChanged(); -// } -// } ); - -// mCredentialStore->readKey( "username" ); -// #else -// // desktop => QSettings -// QSettings settings; -// settings.beginGroup( QStringLiteral( "Input/" ) ); -// mUsername = settings.value( QStringLiteral( "username" ) ).toString(); -// mPassword = settings.value( QStringLiteral( "password" ) ).toString(); -// mUserId = settings.value( QStringLiteral( "userId" ) ).toInt(); -// mTokenExpiration = settings.value( QStringLiteral( "expire" ) ).toDateTime(); -// mAuthToken = settings.value( QStringLiteral( "token" ) ).toByteArray(); -// settings.endGroup(); - -// emit authChanged(); -// #endif -// } - void MerginUserAuth::loadAuthData() { - qDebug() << "TESTLOADAUTHDATA: Starting loadAuthData()"; - #if defined(Q_OS_ANDROID) || defined(Q_OS_IOS) // mobile => QtKeychain via CredentialStore asynchronous chain if ( mCredentialStore ) { - qDebug() << "TESTLOADAUTHDATA: Using CredentialStore for authentication"; - connect( mCredentialStore, &CredentialStore::keyRead, this, [this]( const QString & key, const QString & value ) { - qDebug() << "TESTLOADAUTHDATA: keyRead signal received - key:" << key << ", value:" << value; - if ( key == "username" ) { mUsername = value; - qDebug() << "TESTLOADAUTHDATA: Username set to" << mUsername; mCredentialStore->readKey( QStringLiteral( "password" ) ); } else if ( key == "password" ) { mPassword = value; - qDebug() << "TESTLOADAUTHDATA: Password set"; mCredentialStore->readKey( QStringLiteral( "userId" ) ); } else if ( key == "userId" ) { mUserId = value.toInt(); - qDebug() << "TESTLOADAUTHDATA: UserId set to" << mUserId; mCredentialStore->readKey( QStringLiteral( "token" ) ); } else if ( key == "token" ) { mAuthToken = QByteArray::fromBase64( value.toUtf8() ); - qDebug() << "TESTLOADAUTHDATA: Token set (Base64 decoded)"; mCredentialStore->readKey( QStringLiteral( "expire" ) ); } else if ( key == "expire" ) { mTokenExpiration = QDateTime::fromString( value, Qt::ISODate ); - qDebug() << "TESTLOADAUTHDATA: Token expiration set to" << mTokenExpiration.toString(Qt::ISODate); - if ( mTokenExpiration < QDateTime::currentDateTimeUtc() ) { - qDebug() << "TESTLOADAUTHDATA: Token is expired."; CoreUtils::log( "Auth", "Token is expired." ); } - emit authChanged(); - qDebug() << "TESTLOADAUTHDATA: authChanged() emitted"; - emit credentialsLoaded(); - qDebug() << "TESTLOADAUTHDATA: credentialsLoaded() emitted"; } } ); - - qDebug() << "TESTLOADAUTHDATA: Reading username from CredentialStore"; mCredentialStore->readKey( QStringLiteral( "username" ) ); } - else - { - qDebug() << "TESTLOADAUTHDATA: mCredentialStore is null!"; - } #else // desktop => QSettings - qDebug() << "TESTLOADAUTHDATA: Using QSettings for authentication"; QSettings settings; settings.beginGroup( QStringLiteral( "Input/" ) ); mUsername = settings.value( QStringLiteral( "username" ) ).toString(); - qDebug() << "TESTLOADAUTHDATA: Username set to" << mUsername; - mPassword = settings.value( QStringLiteral( "password" ) ).toString(); - qDebug() << "TESTLOADAUTHDATA: Password set"; - mUserId = settings.value( QStringLiteral( "userId" ) ).toInt(); - qDebug() << "TESTLOADAUTHDATA: UserId set to" << mUserId; - mTokenExpiration = settings.value( QStringLiteral( "expire" ) ).toDateTime(); - qDebug() << "TESTLOADAUTHDATA: Token expiration set to" << mTokenExpiration.toString(Qt::ISODate); - mAuthToken = settings.value( QStringLiteral( "token" ) ).toByteArray(); - qDebug() << "TESTLOADAUTHDATA: Token set (raw bytes)"; settings.endGroup(); #endif - - qDebug() << "TESTLOADAUTHDATA: Finished loadAuthData()"; } QString MerginUserAuth::username() const