diff --git a/desktop/rnkeychainmanager.cpp b/desktop/rnkeychainmanager.cpp index e125e06..c5c2ee0 100644 --- a/desktop/rnkeychainmanager.cpp +++ b/desktop/rnkeychainmanager.cpp @@ -34,6 +34,7 @@ struct RegisterQMLMetaType { class RNKeychainManagerPrivate { public: Bridge* bridge = nullptr; + QString username; }; RNKeychainManager::RNKeychainManager(QObject* parent) : QObject(parent), d_ptr(new RNKeychainManagerPrivate) {} @@ -65,6 +66,7 @@ void RNKeychainManager::getGenericPasswordForOptions(QVariantList options, ReadPasswordJob rjob( keychainJobName ); rjob.setAutoDelete( false ); + rjob.setKey( d->username ); QEventLoop loop; rjob.connect( &rjob, SIGNAL(finished(QKeychain::Job*)), &loop, SLOT(quit()) ); rjob.start(); @@ -88,6 +90,8 @@ void RNKeychainManager::setGenericPasswordForOptions(QVariantList options, Q_D(RNKeychainManager); qDebug()<<"invoked RNKeychainManager::setGenericPasswordForOptions"; + d->username = username; + WritePasswordJob wjob( keychainJobName); wjob.setAutoDelete( false ); wjob.setKey( username ); @@ -111,6 +115,8 @@ void RNKeychainManager::resetGenericPasswordForOptions(QVariantList options, Q_D(RNKeychainManager); qDebug()<<"invoked RNKeychainManager::resetGenericPasswordForOptions"; + d->username = ""; + DeletePasswordJob wjob( keychainJobName); wjob.setAutoDelete( false ); QEventLoop loop; @@ -126,6 +132,14 @@ void RNKeychainManager::resetGenericPasswordForOptions(QVariantList options, resolve(d->bridge, QVariantList{}); } - +void RNKeychainManager::setUsername(const QString &username, + const ModuleInterface::ListArgumentBlock &resolve, + const ModuleInterface::ListArgumentBlock &reject) { + Q_D(RNKeychainManager); + qDebug()<<"invoked RNKeychainManager::setUsername with username = " << username; + d->username = username; + + resolve(d->bridge, QVariantList{QVariant(true)}); +} diff --git a/desktop/rnkeychainmanager.h b/desktop/rnkeychainmanager.h index 7812835..4ef80bf 100644 --- a/desktop/rnkeychainmanager.h +++ b/desktop/rnkeychainmanager.h @@ -44,12 +44,12 @@ public: Q_INVOKABLE REACT_PROMISE void resetGenericPasswordForOptions(QVariantList options, const ModuleInterface::ListArgumentBlock& resolve, const ModuleInterface::ListArgumentBlock& reject); + Q_INVOKABLE REACT_PROMISE void setUsername(const QString& username, + const ModuleInterface::ListArgumentBlock& resolve, + const ModuleInterface::ListArgumentBlock& reject); private: QScopedPointer d_ptr; - - bool copyRecursively(const QString& src, const QString& dst); - bool removeRecursively(const QString& path); }; #endif // RNKEYCHAINMANAGER_H diff --git a/index.js b/index.js index cadec3d..0fd244a 100644 --- a/index.js +++ b/index.js @@ -164,6 +164,19 @@ export function setGenericPassword( ); } +/** + * Saves the `username` for further use on get requests. + * @param {string} username Associated username or e-mail to be saved. + * @return {Promise} Resolves to `true` when successful + */ +export function setUsername( + username: string +): Promise { + return RNKeychainManager.setUsername( + username + ); +} + /** * Fetches login combination for `service`. * @param {string|object} serviceOrOptions Reverse domain name qualifier for the service, defaults to `bundleId` or an options object.