Capability to store username for further usage
This commit is contained in:
parent
6b6dc512d2
commit
878d5491d2
|
@ -34,6 +34,7 @@ struct RegisterQMLMetaType {
|
||||||
class RNKeychainManagerPrivate {
|
class RNKeychainManagerPrivate {
|
||||||
public:
|
public:
|
||||||
Bridge* bridge = nullptr;
|
Bridge* bridge = nullptr;
|
||||||
|
QString username;
|
||||||
};
|
};
|
||||||
|
|
||||||
RNKeychainManager::RNKeychainManager(QObject* parent) : QObject(parent), d_ptr(new RNKeychainManagerPrivate) {}
|
RNKeychainManager::RNKeychainManager(QObject* parent) : QObject(parent), d_ptr(new RNKeychainManagerPrivate) {}
|
||||||
|
@ -65,6 +66,7 @@ void RNKeychainManager::getGenericPasswordForOptions(QVariantList options,
|
||||||
|
|
||||||
ReadPasswordJob rjob( keychainJobName );
|
ReadPasswordJob rjob( keychainJobName );
|
||||||
rjob.setAutoDelete( false );
|
rjob.setAutoDelete( false );
|
||||||
|
rjob.setKey( d->username );
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
rjob.connect( &rjob, SIGNAL(finished(QKeychain::Job*)), &loop, SLOT(quit()) );
|
rjob.connect( &rjob, SIGNAL(finished(QKeychain::Job*)), &loop, SLOT(quit()) );
|
||||||
rjob.start();
|
rjob.start();
|
||||||
|
@ -88,6 +90,8 @@ void RNKeychainManager::setGenericPasswordForOptions(QVariantList options,
|
||||||
Q_D(RNKeychainManager);
|
Q_D(RNKeychainManager);
|
||||||
qDebug()<<"invoked RNKeychainManager::setGenericPasswordForOptions";
|
qDebug()<<"invoked RNKeychainManager::setGenericPasswordForOptions";
|
||||||
|
|
||||||
|
d->username = username;
|
||||||
|
|
||||||
WritePasswordJob wjob( keychainJobName);
|
WritePasswordJob wjob( keychainJobName);
|
||||||
wjob.setAutoDelete( false );
|
wjob.setAutoDelete( false );
|
||||||
wjob.setKey( username );
|
wjob.setKey( username );
|
||||||
|
@ -111,6 +115,8 @@ void RNKeychainManager::resetGenericPasswordForOptions(QVariantList options,
|
||||||
Q_D(RNKeychainManager);
|
Q_D(RNKeychainManager);
|
||||||
qDebug()<<"invoked RNKeychainManager::resetGenericPasswordForOptions";
|
qDebug()<<"invoked RNKeychainManager::resetGenericPasswordForOptions";
|
||||||
|
|
||||||
|
d->username = "";
|
||||||
|
|
||||||
DeletePasswordJob wjob( keychainJobName);
|
DeletePasswordJob wjob( keychainJobName);
|
||||||
wjob.setAutoDelete( false );
|
wjob.setAutoDelete( false );
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
|
@ -126,6 +132,14 @@ void RNKeychainManager::resetGenericPasswordForOptions(QVariantList options,
|
||||||
resolve(d->bridge, QVariantList{});
|
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)});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -44,12 +44,12 @@ public:
|
||||||
Q_INVOKABLE REACT_PROMISE void resetGenericPasswordForOptions(QVariantList options,
|
Q_INVOKABLE REACT_PROMISE void resetGenericPasswordForOptions(QVariantList options,
|
||||||
const ModuleInterface::ListArgumentBlock& resolve,
|
const ModuleInterface::ListArgumentBlock& resolve,
|
||||||
const ModuleInterface::ListArgumentBlock& reject);
|
const ModuleInterface::ListArgumentBlock& reject);
|
||||||
|
Q_INVOKABLE REACT_PROMISE void setUsername(const QString& username,
|
||||||
|
const ModuleInterface::ListArgumentBlock& resolve,
|
||||||
|
const ModuleInterface::ListArgumentBlock& reject);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QScopedPointer<RNKeychainManagerPrivate> d_ptr;
|
QScopedPointer<RNKeychainManagerPrivate> d_ptr;
|
||||||
|
|
||||||
bool copyRecursively(const QString& src, const QString& dst);
|
|
||||||
bool removeRecursively(const QString& path);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // RNKEYCHAINMANAGER_H
|
#endif // RNKEYCHAINMANAGER_H
|
||||||
|
|
13
index.js
13
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`.
|
* Fetches login combination for `service`.
|
||||||
* @param {string|object} serviceOrOptions Reverse domain name qualifier for the service, defaults to `bundleId` or an options object.
|
* @param {string|object} serviceOrOptions Reverse domain name qualifier for the service, defaults to `bundleId` or an options object.
|
||||||
|
|
Loading…
Reference in New Issue