Skip to content

Commit

Permalink
last adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
VitorVieiraZ committed Jan 31, 2025
1 parent b13b288 commit 1c9ca05
Showing 1 changed file with 38 additions and 38 deletions.
76 changes: 38 additions & 38 deletions core/merginuserauth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,26 @@ MerginUserAuth::MerginUserAuth( QObject *parent )

void MerginUserAuth::clear()
{
mUsername.clear();
mPassword.clear();
mUsername = "";
mPassword = "";
mAuthToken.clear();
mTokenExpiration = QDateTime();
mUserId = -1;

#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
deleteKey( QStringLiteral( "username" ) );
deleteKey( QStringLiteral( "password" ) );
deleteKey( QStringLiteral( "userId" ) );
deleteKey( QStringLiteral( "token" ) );
deleteKey( QStringLiteral( "expire" ) );
deleteKey( "username" );
deleteKey( "password" );
deleteKey( "userId" );
deleteKey( "token" );
deleteKey( "expire" );
#else
QSettings settings;
settings.beginGroup( QStringLiteral( "Input/" ) );
settings.remove( QStringLiteral( "username" ) );
settings.remove( QStringLiteral( "password" ) );
settings.remove( QStringLiteral( "userId" ) );
settings.remove( QStringLiteral( "token" ) );
settings.remove( QStringLiteral( "expire" ) );
settings.beginGroup( "Input/" );
settings.remove( "username" );
settings.remove( "password" );
settings.remove( "userId" );
settings.remove( "token" );
settings.remove( "expire" );
settings.endGroup();
#endif

Expand All @@ -54,9 +54,9 @@ void MerginUserAuth::clearTokenData()
deleteKey( QStringLiteral( "expire" ) );
#else
QSettings settings;
settings.beginGroup( QStringLiteral( "Input/" ) );
settings.remove( QStringLiteral( "token" ) );
settings.remove( QStringLiteral( "expire" ) );
settings.beginGroup( "Input/" );
settings.remove( "token" );
settings.remove( "expire" );
settings.endGroup();
#endif

Expand Down Expand Up @@ -85,20 +85,20 @@ void MerginUserAuth::saveAuthData()
{
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
// mobile => QtKeychain
writeKey( QStringLiteral( "username" ), mUsername );
writeKey( QStringLiteral( "password" ), mPassword );
writeKey( QStringLiteral( "userId" ), mUserId );
writeKey( QStringLiteral( "token" ), mAuthToken );
writeKey( QStringLiteral( "expire" ), mTokenExpiration );
writeKey( "username", mUsername );
writeKey( "password", mPassword );
writeKey( "userId", mUserId );
writeKey( "token", mAuthToken );
writeKey( "expire", mTokenExpiration );
#else
// desktop => QSettings
QSettings settings;
settings.beginGroup( QStringLiteral( "Input/" ) );
settings.setValue( QStringLiteral( "username" ), mUsername );
settings.setValue( QStringLiteral( "password" ), mPassword );
settings.setValue( QStringLiteral( "userId" ), mUserId );
settings.setValue( QStringLiteral( "token" ), mAuthToken );
settings.setValue( QStringLiteral( "expire" ), mTokenExpiration );
settings.beginGroup( "Input/" );
settings.setValue( "username", mUsername );
settings.setValue( "password", mPassword );
settings.setValue( "userId", mUserId );
settings.setValue( "token", mAuthToken );
settings.setValue( "expire", mTokenExpiration );
settings.endGroup();
#endif
}
Expand All @@ -107,20 +107,20 @@ void MerginUserAuth::loadAuthData()
{
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
// mobile => QtKeychain
readKey( QStringLiteral( "username" ), mUsername, []( const QString & v ) { return v; } );
readKey( QStringLiteral( "password" ), mPassword, []( const QString & v ) { return v; } );
readKey( QStringLiteral( "userId" ), mUserId, []( const QString & v ) { return v.toInt(); } );
readKey( QStringLiteral( "token" ), mAuthToken, []( const QString & v ) { return QByteArray::fromBase64( v.toUtf8() ); } );
readKey( QStringLiteral( "expire" ), mTokenExpiration, []( const QString & v ) { return QDateTime::fromString( v, Qt::ISODate ); } );
readKey( "username", mUsername, []( const QString & v ) { return v; } );
readKey( "password", mPassword, []( const QString & v ) { return v; } );
readKey( "userId", mUserId, []( const QString & v ) { return v.toInt(); } );
readKey( "token", mAuthToken, []( const QString & v ) { return QByteArray::fromBase64( v.toUtf8() ); } );
readKey( "expire", mTokenExpiration, []( const QString & v ) { return QDateTime::fromString( v, Qt::ISODate ); } );
#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.beginGroup( "Input/" );
mUsername = settings.value( "username" ).toString();
mPassword = settings.value( "password" ).toString();
mUserId = settings.value( "userId" ).toInt();
mTokenExpiration = settings.value( "expire" ).toDateTime();
mAuthToken = settings.value( "token" ).toByteArray();
settings.endGroup();
#endif
}
Expand Down

0 comments on commit 1c9ca05

Please sign in to comment.