@@ -20,34 +20,6 @@ WsAuthenticator::WsAuthenticator(WsRemoteConnector *connector, Defaults *default
2020
2121WsAuthenticator::~WsAuthenticator () {}
2222
23- void WsAuthenticator::exportUserDataImpl (QIODevice *device) const
24- {
25- QJsonObject data;
26- data[QStringLiteral (" key" )] = QString::fromUtf8 (d->connector ->cryptor ()->key ().toBase64 ());
27- data[QStringLiteral (" identity" )] = QString::fromUtf8 (userIdentity ());
28-
29- device->write (QJsonDocument (data).toJson (QJsonDocument::Indented));
30- }
31-
32- GenericTask<void > WsAuthenticator::importUserDataImpl (QIODevice *device)
33- {
34- QJsonParseError error;
35- auto data = QJsonDocument::fromJson (device->readAll (), &error);
36- if (error.error != QJsonParseError::NoError) {
37- QFutureInterface<QVariant> futureInterface;
38- futureInterface.reportStarted ();
39- futureInterface.reportException (InvalidDataException (error.errorString ()));
40- futureInterface.reportFinished ();
41- return futureInterface;
42- }
43-
44- auto obj = data.object ();
45- auto key = QByteArray::fromBase64 (obj[QStringLiteral (" key" )].toString ().toUtf8 ());
46- QMetaObject::invokeMethod (d->connector ->cryptor (), " setKey" , Qt::QueuedConnection,
47- Q_ARG (QByteArray, key));
48- return setUserIdentity (obj[QStringLiteral (" identity" )].toString ().toUtf8 ());
49- }
50-
5123QUrl WsAuthenticator::remoteUrl () const
5224{
5325 return d->settings ->value (WsRemoteConnector::keyRemoteUrl).toUrl ();
@@ -111,13 +83,22 @@ void WsAuthenticator::setValidateServerCertificate(bool validateServerCertificat
11183 d->settings ->sync ();
11284}
11385
86+ GenericTask<void > WsAuthenticator::resetUserData (bool clearLocalStore)
87+ {
88+ return resetIdentity (QVariant (), clearLocalStore);
89+ }
90+
11491GenericTask<void > WsAuthenticator::setUserIdentity (QByteArray userIdentity, bool clearLocalStore)
11592{
93+ qWarning () << " Method setUserIdentity is unsafe, as it does not set the key."
94+ << " Use importUserData instead!" ;
11695 return resetIdentity (userIdentity, clearLocalStore);
11796}
11897
11998GenericTask<void > WsAuthenticator::resetUserIdentity (bool clearLocalStore)
12099{
100+ qWarning () << " Method resetUserIdentity is unsafe, as it does not reset the key."
101+ << " Use resetUserData instead!" ;
121102 return resetIdentity (QVariant (), clearLocalStore);
122103}
123104
@@ -132,6 +113,34 @@ RemoteConnector *WsAuthenticator::connector()
132113 return d->connector ;
133114}
134115
116+ void WsAuthenticator::exportUserDataImpl (QIODevice *device) const
117+ {
118+ QJsonObject data;
119+ data[QStringLiteral (" key" )] = QString::fromUtf8 (d->connector ->cryptor ()->key ().toBase64 ());
120+ data[QStringLiteral (" identity" )] = QString::fromUtf8 (userIdentity ());
121+
122+ device->write (QJsonDocument (data).toJson (QJsonDocument::Indented));
123+ }
124+
125+ GenericTask<void > WsAuthenticator::importUserDataImpl (QIODevice *device)
126+ {
127+ QJsonParseError error;
128+ auto data = QJsonDocument::fromJson (device->readAll (), &error);
129+ if (error.error != QJsonParseError::NoError) {
130+ QFutureInterface<QVariant> futureInterface;
131+ futureInterface.reportStarted ();
132+ futureInterface.reportException (InvalidDataException (error.errorString ()));
133+ futureInterface.reportFinished ();
134+ return futureInterface;
135+ }
136+
137+ auto obj = data.object ();
138+ auto key = QByteArray::fromBase64 (obj[QStringLiteral (" key" )].toString ().toUtf8 ());
139+ QMetaObject::invokeMethod (d->connector ->cryptor (), " setKey" , Qt::QueuedConnection,
140+ Q_ARG (QByteArray, key));
141+ return resetIdentity (obj[QStringLiteral (" identity" )].toString ().toUtf8 (), true );
142+ }
143+
135144void WsAuthenticator::updateConnected (int connected)
136145{
137146 auto cOld = d->connected ;
0 commit comments