some fixes

This commit is contained in:
Michael Zanetti 2020-02-26 17:09:08 +01:00
parent 5086d1373a
commit 4d6ba26a59
6 changed files with 23 additions and 4 deletions

View File

@ -164,7 +164,7 @@ void NymeaDiscovery::cacheHost(NymeaHost *host)
settings.beginGroup(QString::number(i++)); settings.beginGroup(QString::number(i++));
settings.setValue("url", connection->url()); settings.setValue("url", connection->url());
settings.setValue("bearerType", connection->bearerType()); settings.setValue("bearerType", connection->bearerType());
settings.value("secure", connection->secure()); settings.setValue("secure", connection->secure());
settings.setValue("displayName", connection->displayName()); settings.setValue("displayName", connection->displayName());
settings.endGroup(); settings.endGroup();
} }

View File

@ -161,6 +161,7 @@ Connection *NymeaConnection::currentConnection() const
if (!m_currentHost || !m_currentTransport) { if (!m_currentHost || !m_currentTransport) {
return nullptr; return nullptr;
} }
qDebug() << "secure:" << m_transportCandidates.value(m_currentTransport)->secure();
return m_transportCandidates.value(m_currentTransport); return m_transportCandidates.value(m_currentTransport);
} }

View File

@ -189,6 +189,11 @@ bool JsonRpcClient::pushButtonAuthAvailable() const
return m_pushButtonAuthAvailable; return m_pushButtonAuthAvailable;
} }
bool JsonRpcClient::authenticated() const
{
return m_authenticated;
}
JsonRpcClient::CloudConnectionState JsonRpcClient::cloudConnectionState() const JsonRpcClient::CloudConnectionState JsonRpcClient::cloudConnectionState() const
{ {
return m_cloudConnectionState; return m_cloudConnectionState;
@ -297,6 +302,9 @@ void JsonRpcClient::processAuthenticate(const QVariantMap &data)
settings.endGroup(); settings.endGroup();
emit authenticationRequiredChanged(); emit authenticationRequiredChanged();
m_authenticated = true;
emit authenticated();
setNotificationsEnabled(); setNotificationsEnabled();
} else { } else {
qWarning() << "Authentication failed" << data; qWarning() << "Authentication failed" << data;
@ -376,6 +384,7 @@ void JsonRpcClient::onInterfaceConnectedChanged(bool connected)
qDebug() << "JsonRpcClient: Transport disconnected."; qDebug() << "JsonRpcClient: Transport disconnected.";
m_initialSetupRequired = false; m_initialSetupRequired = false;
m_authenticationRequired = false; m_authenticationRequired = false;
m_authenticated = false;
m_serverQtVersion.clear(); m_serverQtVersion.clear();
m_serverQtBuildVersion.clear(); m_serverQtBuildVersion.clear();
if (m_connected) { if (m_connected) {
@ -442,6 +451,8 @@ void JsonRpcClient::dataReceived(const QByteArray &data)
settings.setValue(m_serverUuid, m_token); settings.setValue(m_serverUuid, m_token);
settings.endGroup(); settings.endGroup();
emit authenticationRequiredChanged(); emit authenticationRequiredChanged();
m_authenticated = false;
emit authenticatedChanged();
} }
if (!reply->caller().isNull() && !reply->callback().isEmpty()) { if (!reply->caller().isNull() && !reply->callback().isEmpty()) {
@ -508,11 +519,13 @@ void JsonRpcClient::helloReply(const QVariantMap &params)
if (m_token.isEmpty()) { if (m_token.isEmpty()) {
return; return;
} }
m_authenticated = true;
emit authenticatedChanged();
} }
setNotificationsEnabled(); setNotificationsEnabled();
getCloudConnectionStatus(); getCloudConnectionStatus();
} }
} }

View File

@ -50,6 +50,7 @@ class JsonRpcClient : public JsonHandler
Q_PROPERTY(bool initialSetupRequired READ initialSetupRequired NOTIFY initialSetupRequiredChanged) Q_PROPERTY(bool initialSetupRequired READ initialSetupRequired NOTIFY initialSetupRequiredChanged)
Q_PROPERTY(bool authenticationRequired READ authenticationRequired NOTIFY authenticationRequiredChanged) Q_PROPERTY(bool authenticationRequired READ authenticationRequired NOTIFY authenticationRequiredChanged)
Q_PROPERTY(bool pushButtonAuthAvailable READ pushButtonAuthAvailable NOTIFY pushButtonAuthAvailableChanged) Q_PROPERTY(bool pushButtonAuthAvailable READ pushButtonAuthAvailable NOTIFY pushButtonAuthAvailableChanged)
Q_PROPERTY(bool authenticated READ authenticated NOTIFY authenticatedChanged)
Q_PROPERTY(CloudConnectionState cloudConnectionState READ cloudConnectionState NOTIFY cloudConnectionStateChanged) Q_PROPERTY(CloudConnectionState cloudConnectionState READ cloudConnectionState NOTIFY cloudConnectionStateChanged)
Q_PROPERTY(QString serverVersion READ serverVersion NOTIFY handshakeReceived) Q_PROPERTY(QString serverVersion READ serverVersion NOTIFY handshakeReceived)
Q_PROPERTY(QString jsonRpcVersion READ jsonRpcVersion NOTIFY handshakeReceived) Q_PROPERTY(QString jsonRpcVersion READ jsonRpcVersion NOTIFY handshakeReceived)
@ -81,6 +82,7 @@ public:
bool initialSetupRequired() const; bool initialSetupRequired() const;
bool authenticationRequired() const; bool authenticationRequired() const;
bool pushButtonAuthAvailable() const; bool pushButtonAuthAvailable() const;
bool authenticated() const;
CloudConnectionState cloudConnectionState() const; CloudConnectionState cloudConnectionState() const;
void deployCertificate(const QByteArray &rootCA, const QByteArray &certificate, const QByteArray &publicKey, const QByteArray &privateKey, const QString &endpoint); void deployCertificate(const QByteArray &rootCA, const QByteArray &certificate, const QByteArray &publicKey, const QByteArray &privateKey, const QString &endpoint);
@ -103,6 +105,7 @@ signals:
void initialSetupRequiredChanged(); void initialSetupRequiredChanged();
void authenticationRequiredChanged(); void authenticationRequiredChanged();
void pushButtonAuthAvailableChanged(); void pushButtonAuthAvailableChanged();
void authenticatedChanged();
void connectedChanged(bool connected); void connectedChanged(bool connected);
void tokenChanged(); void tokenChanged();
void invalidProtocolVersion(const QString &actualVersion, const QString &minimumVersion); void invalidProtocolVersion(const QString &actualVersion, const QString &minimumVersion);
@ -135,6 +138,7 @@ private:
bool m_initialSetupRequired = false; bool m_initialSetupRequired = false;
bool m_authenticationRequired = false; bool m_authenticationRequired = false;
bool m_pushButtonAuthAvailable = false; bool m_pushButtonAuthAvailable = false;
bool m_authenticated = false;
CloudConnectionState m_cloudConnectionState = CloudConnectionStateDisabled; CloudConnectionState m_cloudConnectionState = CloudConnectionStateDisabled;
int m_pendingPushButtonTransaction = -1; int m_pendingPushButtonTransaction = -1;
QString m_serverUuid; QString m_serverUuid;

View File

@ -75,6 +75,7 @@ Page {
Material.elevation: layout.isGrid ? 1 : 0 Material.elevation: layout.isGrid ? 1 : 0
padding: 0 padding: 0
visible: engine.jsonRpcClient.ensureServerVersion("4.2") visible: engine.jsonRpcClient.ensureServerVersion("4.2")
&& engine.jsonRpcClient.authenticated
NymeaListItemDelegate { NymeaListItemDelegate {
width: parent.width width: parent.width
iconName: "../images/account.svg" iconName: "../images/account.svg"

View File

@ -53,7 +53,7 @@ Page {
popup.open(); popup.open();
} }
onCreateUserSucceeded: { onCreateUserSucceeded: {
engine.jsonRpcClient.authenticate(usernameTextField.text, passwordTextField.password, "nymea-app (" + PlatformHelper.device + ")"); engine.jsonRpcClient.authenticate(usernameTextField.text, passwordTextField.password, "nymea-app (" + PlatformHelper.deviceModel + ")");
} }
onCreateUserFailed: { onCreateUserFailed: {
@ -153,7 +153,7 @@ Page {
engine.jsonRpcClient.createUser(usernameTextField.text, passwordTextField.password); engine.jsonRpcClient.createUser(usernameTextField.text, passwordTextField.password);
} else { } else {
print("authenticate", usernameTextField.text, passwordTextField.text, "nymea-app") print("authenticate", usernameTextField.text, passwordTextField.text, "nymea-app")
engine.jsonRpcClient.authenticate(usernameTextField.text, passwordTextField.password, "nymea-app (" + PlatformHelper.device + ")"); engine.jsonRpcClient.authenticate(usernameTextField.text, passwordTextField.password, "nymea-app (" + PlatformHelper.deviceModel + ")");
} }
} }
} }