magpie/qml/Forms/Login.qml

110 lines
2.3 KiB
QML

// SPDX-FileCopyrightText: 2023 Yury Gubich <blue@macaw.me>
// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick
import QtQuick.Controls
import magpie.API
import magpie.Components as Components
Column {
signal register()
signal loggingIn(value: bool)
function login(login, password) {
if (modal.inProgress)
return;
loggingIn(true);
loginField.text = login;
passwordField.text = password;
modal.inProgress = true;
modal.status = qsTr("Logging in as") + " " + login + "...";
modal.open();
API.sendLogin(login, password, function (err, result) {
if (!modal.inProgress)
return;
modal.inProgress = false;
if (err)
modal.status = err;
else
modal.status = qsTr("Success");
loggingIn(false);
if (!!result)
modal.close();
});
}
spacing: 5
Label {
anchors.horizontalCenter: parent.horizontalCenter
text: qsTr("Please, log in to your account")
font {
pixelSize: 14
}
}
Grid {
anchors.horizontalCenter: parent.horizontalCenter
columns: 2
columnSpacing: 10
rowSpacing: 5
verticalItemAlignment: Grid.AlignVCenter
horizontalItemAlignment: Grid.AlignRight
Label {
text: qsTr("Login") + ":";
}
TextField {
id: loginField
}
Label {
text: qsTr("Password") + ":";
}
TextField {
id: passwordField
echoMode: TextField.Password
}
}
Button {
anchors.horizontalCenter: parent.horizontalCenter
text: qsTr("Login")
onClicked: login(loginField.text, passwordField.text)
}
Components.Modal {
id: modal
}
Row {
anchors.horizontalCenter: parent.horizontalCenter
spacing: 5
topPadding: 10
Label {
text: qsTr("Don't have account?")
}
Label {
text: qsTr("Sign up") + "!"
font {
italic: true
underline: true
}
MouseArea {
anchors.fill: parent
onClicked: register()
}
}
}
}