Skip to content

Commit

Permalink
Small fixes for password change feature
Browse files Browse the repository at this point in the history
  • Loading branch information
raoulh committed Jun 10, 2024
1 parent 5eed6a5 commit 886cd04
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 20 deletions.
5 changes: 5 additions & 0 deletions qml/SharedComponents/SingleShotTimer.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import QtQuick

Timer {
//A simple timer that is instanciated by Utils.js
}
26 changes: 26 additions & 0 deletions qml/SharedComponents/calaos.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.pragma library
.import QtQuick as QtQuick

function getRoomTypeIcon(room) {
var rname;
Expand Down Expand Up @@ -32,3 +33,28 @@ function getRoomTypeIcon(room) {

return rname;
}

function singleshotTimer(interval, callback) {
var component = Qt.createComponent("SingleShotTimer.qml")
if (component.status === QtQuick.Component.Ready || component.status === QtQuick.Component.Error) {
singleshotTimerCreated(component, interval, callback)
} else {
component.statusChanged.connect(function() {
singleshotTimerCreated(component, interval, callback)
})
}
}

function singleshotTimerCreated(component, interval, callback) {
if (component.status === QtQuick.Component.Ready) {
var obj = component.createObject(null, { "interval": interval })
obj.triggered.connect( function () {
callback();
obj.destroy();
} );
obj.start();
} else if (component.status === QtQuick.Component.Error) {
console.log("Error loading component SingleShotTimer.qml:", component.errorString());
}
}

31 changes: 18 additions & 13 deletions qml/desktop/ConfigUserInfoView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,6 @@ Item {
opacity: 0.6
}

AppListener {
Filter {
type: ActionTypes.changeLogin
onDispatched: (filtertype, message) => {
calaosApp.changeLogin()
}
}
}

ColumnLayout {

anchors {
Expand Down Expand Up @@ -109,11 +100,25 @@ Item {
onButtonClicked: AppActions.openKeyboard(qsTr("Password"),
qsTr("Enter your new password"),
"",
TextInput.PasswordEchoOnEdit,
TextInput.Password,
false,
function(txt) {
if (!calaosApp.changePassword(txt))
AppActions.showNotificationMsg(qsTr("Password change failed"), qsTr("The password was not changed. Please try again."), qsTr("Close"))
function(pass1) {
Calaos.singleshotTimer(200, function() {
AppActions.openKeyboard(qsTr("Password"),
qsTr("Enter your new password again to validate it"),
"",
TextInput.Password,
false,
function(pass2) {
if (pass1 !== pass2) {
AppActions.showNotificationMsg(qsTr("Password change failed"), qsTr("The two passwords you entered are not the same. Please try again."), qsTr("Close"))
return
}

if (!calaosApp.changePassword(pass2))
AppActions.showNotificationMsg(qsTr("Password change failed"), qsTr("The password was not changed. Please try again."), qsTr("Close"))
})
})
})
hoverEnabled: false
disabled: calaosApp.settingsLocked
Expand Down
1 change: 1 addition & 0 deletions qml_shared.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@
<file>qml/SharedComponents/IOBoiler.qml</file>
<file>qml/SharedComponents/IOHeater.qml</file>
<file>qml/SharedComponents/IOAnalogStyled.qml</file>
<file>qml/SharedComponents/SingleShotTimer.qml</file>
</qresource>
</RCC>
20 changes: 15 additions & 5 deletions src/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ void Application::createQmlApp()
update_isSnapshotBoot(false);
#endif

update_settingsLocked(true);
update_settingsLocked(false);

update_applicationStatus(Common::NotConnected);

Expand All @@ -186,6 +186,7 @@ void Application::createQmlApp()
connect(calaosConnect, &CalaosConnection::disconnected, this, [=]()
{
update_applicationStatus(Common::NotConnected);
update_settingsLocked(false);

#ifdef CALAOS_DESKTOP
HardwareUtils::Instance()->showAlertMessage(tr("Network error"),
Expand All @@ -209,11 +210,18 @@ void Application::createQmlApp()
tr("Credentials were not changed. Please try again."),
tr("Close"));
});
connect(calaosConnect, &CalaosConnection::changeCredsSuccess, this, [=]()
connect(calaosConnect, &CalaosConnection::changeCredsSuccess, this, [=](QString username, QString password)
{
HardwareUtils::Instance()->showAlertMessage(tr("Credentials changed"),
tr("Credentials were successfully changed."),
tr("Close"));
update_username(username);
update_password(password);
HardwareUtils::Instance()->saveAuthKeychain(get_username(), get_password());

QTimer::singleShot(1000, []()
{
HardwareUtils::Instance()->showAlertMessage(tr("Credentials changed"),
tr("Credentials were successfully changed."),
tr("Close"));
});
});

scenarioModel = new ScenarioModel(&engine, calaosConnect, this);
Expand Down Expand Up @@ -392,6 +400,7 @@ void Application::resetAllData()

void Application::homeLoaded(const QVariantMap &homeData)
{
update_settingsLocked(true);
homeModel->load(homeData);
audioModel->load(homeData);
favHomeModel->load(homeData);
Expand Down Expand Up @@ -456,6 +465,7 @@ void Application::homeLoaded(const QVariantMap &homeData)

void Application::loginFailed()
{
update_settingsLocked(false);
homeModel->clear();
audioModel->clear();
scenarioModel->clear();
Expand Down
2 changes: 1 addition & 1 deletion src/CalaosConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ void CalaosConnection::onWsTextMessageReceived(const QString &message)
{
username = username_temp;
password = password_temp;
emit changeCredsSuccess();
emit changeCredsSuccess(username, password);

//reconnect
logout();
Expand Down
2 changes: 1 addition & 1 deletion src/CalaosConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class CalaosConnection : public QObject
void eventTouchscreenCamera(QString camid);
void logEventLoaded(const QVariantMap &data);
void audioCoverDownloaded(const QString &camid, const QByteArray &data);
void changeCredsSuccess();
void changeCredsSuccess(QString uname, QString pass);
void changeCredsFailed();

public slots:
Expand Down

0 comments on commit 886cd04

Please sign in to comment.