Sending register, handling register result, sending login
This commit is contained in:
parent
89aa830bfa
commit
73e91e658f
15 changed files with 295 additions and 90 deletions
|
@ -1,8 +1,9 @@
|
|||
qt_add_qml_module(magpieQml
|
||||
URI qml
|
||||
URI magpie
|
||||
VERSION 1.0
|
||||
STATIC
|
||||
RESOURCE_PREFIX /
|
||||
OUTPUT_DIRECTORY magpie
|
||||
NO_PLUGIN
|
||||
QML_FILES
|
||||
main.qml
|
||||
|
@ -10,6 +11,10 @@ qt_add_qml_module(magpieQml
|
|||
Welcome.qml
|
||||
)
|
||||
|
||||
list(APPEND QML_DIRS ${CMAKE_CURRENT_BINARY_DIR})
|
||||
set(QML_IMPORT_PATH "${QML_DIRS}" CACHE STRING "Qt Creator 11 extra qml import paths")
|
||||
|
||||
target_link_libraries(magpie PRIVATE magpieQml)
|
||||
|
||||
add_subdirectory(Forms)
|
||||
add_subdirectory(Components)
|
||||
|
|
12
qml/Components/CMakeLists.txt
Normal file
12
qml/Components/CMakeLists.txt
Normal file
|
@ -0,0 +1,12 @@
|
|||
qt_add_qml_module(magpieComponents
|
||||
URI magpie.Components
|
||||
VERSION 1.0
|
||||
STATIC
|
||||
RESOURCE_PREFIX /
|
||||
OUTPUT_DIRECTORY ../magpie/Components
|
||||
NO_PLUGIN
|
||||
QML_FILES
|
||||
Modal.qml
|
||||
)
|
||||
|
||||
target_link_libraries(magpie PRIVATE magpieComponents)
|
61
qml/Components/Modal.qml
Normal file
61
qml/Components/Modal.qml
Normal file
|
@ -0,0 +1,61 @@
|
|||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
|
||||
Popup {
|
||||
property bool inProgress: false
|
||||
property string status: ""
|
||||
|
||||
id: modal
|
||||
anchors.centerIn: parent
|
||||
modal: true
|
||||
focus: true
|
||||
width: column.width + 60
|
||||
height: column.height + 60
|
||||
closePolicy: Popup.CloseOnEscape
|
||||
onClosed: inProgress = false
|
||||
|
||||
Column {
|
||||
id: column
|
||||
anchors.centerIn: parent
|
||||
spacing: 10
|
||||
Label {
|
||||
text: status
|
||||
width: 300
|
||||
wrapMode: Label.WordWrap
|
||||
horizontalAlignment: Label.AlignHCenter
|
||||
}
|
||||
BusyIndicator {
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
visible: inProgress
|
||||
running: inProgress
|
||||
}
|
||||
Button {
|
||||
text: qsTr("Close")
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
visible: !inProgress
|
||||
onClicked: modal.close()
|
||||
focus: true
|
||||
Keys.onReturnPressed: {
|
||||
if (!inProgress)
|
||||
modal.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enter: Transition {
|
||||
NumberAnimation {
|
||||
property: "opacity"
|
||||
from: 0.0
|
||||
to: 1.0
|
||||
duration: 200
|
||||
}
|
||||
}
|
||||
exit: Transition {
|
||||
NumberAnimation {
|
||||
property: "opacity"
|
||||
from: 1.0
|
||||
to: 0.0
|
||||
duration: 200
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,8 +1,9 @@
|
|||
qt_add_qml_module(magpieForms
|
||||
URI "qml.Forms"
|
||||
URI magpie.Forms
|
||||
VERSION 1.0
|
||||
STATIC
|
||||
RESOURCE_PREFIX /
|
||||
OUTPUT_DIRECTORY ../magpie/Forms
|
||||
NO_PLUGIN
|
||||
QML_FILES
|
||||
Login.qml
|
||||
|
|
|
@ -2,10 +2,37 @@ import QtQuick
|
|||
import QtQuick.Controls
|
||||
|
||||
import magpie.API
|
||||
import magpie.Components as Components
|
||||
|
||||
Column {
|
||||
signal register()
|
||||
|
||||
function login(login, password) {
|
||||
if (modal.inProgress)
|
||||
return;
|
||||
|
||||
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");
|
||||
|
||||
if (!!result)
|
||||
modal.close();
|
||||
});
|
||||
}
|
||||
|
||||
spacing: 5
|
||||
|
||||
Label {
|
||||
|
@ -29,7 +56,7 @@ Column {
|
|||
}
|
||||
|
||||
TextField {
|
||||
id: login
|
||||
id: loginField
|
||||
}
|
||||
|
||||
Label {
|
||||
|
@ -37,7 +64,7 @@ Column {
|
|||
}
|
||||
|
||||
TextField {
|
||||
id: password
|
||||
id: passwordField
|
||||
echoMode: TextField.Password
|
||||
}
|
||||
}
|
||||
|
@ -45,9 +72,11 @@ Column {
|
|||
Button {
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
text: qsTr("Login")
|
||||
onClicked: function () {
|
||||
console.log("Not implemented");
|
||||
}
|
||||
onClicked: login(loginField.text, passwordField.text)
|
||||
}
|
||||
|
||||
Components.Modal {
|
||||
id: modal
|
||||
}
|
||||
|
||||
Row {
|
||||
|
|
|
@ -2,9 +2,11 @@ import QtQuick
|
|||
import QtQuick.Controls
|
||||
|
||||
import magpie.API
|
||||
import magpie.Components as Components
|
||||
|
||||
Column {
|
||||
signal login()
|
||||
signal success(login: string, password: string)
|
||||
|
||||
spacing: 5
|
||||
|
||||
|
@ -45,12 +47,35 @@ Column {
|
|||
Button {
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
text: qsTr("Register")
|
||||
onClicked: API.sendRegister(newLogin.text, newPassword.text, function (err, result) {
|
||||
if (err)
|
||||
console.error("err")
|
||||
onClicked: modal.check()
|
||||
}
|
||||
|
||||
console.log(result);
|
||||
})
|
||||
Components.Modal {
|
||||
id: modal
|
||||
function check () {
|
||||
if (inProgress)
|
||||
return;
|
||||
|
||||
inProgress = true;
|
||||
status = qsTr("Registering") + " " + newLogin.text + "...";
|
||||
open()
|
||||
|
||||
API.sendRegister(newLogin.text, newPassword.text, function (err, result) {
|
||||
if (!modal.inProgress)
|
||||
return;
|
||||
|
||||
modal.inProgress = false;
|
||||
if (err)
|
||||
modal.status = err;
|
||||
else
|
||||
modal.status = qsTr("Success");
|
||||
|
||||
if (!!result) {
|
||||
modal.close();
|
||||
success(newLogin.text, newPassword.text);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Row {
|
||||
|
|
|
@ -3,6 +3,7 @@ import QtQuick.Controls
|
|||
import QtQuick.Layouts
|
||||
|
||||
import magpie.API
|
||||
import magpie.Components as Components
|
||||
|
||||
Page {
|
||||
property string address
|
||||
|
@ -47,71 +48,14 @@ Page {
|
|||
}
|
||||
}
|
||||
|
||||
Popup {
|
||||
property bool inProgress: false
|
||||
|
||||
Components.Modal {
|
||||
id: modal
|
||||
anchors.centerIn: parent
|
||||
modal: true
|
||||
focus: true
|
||||
width: column.width + 60
|
||||
height: column.height + 60
|
||||
closePolicy: Popup.CloseOnEscape
|
||||
onClosed: modal.inProgress = false
|
||||
|
||||
Column {
|
||||
id: column
|
||||
anchors.centerIn: parent
|
||||
spacing: 10
|
||||
Label {
|
||||
id: status
|
||||
width: 300
|
||||
wrapMode: Label.WordWrap
|
||||
horizontalAlignment: Label.AlignHCenter
|
||||
}
|
||||
BusyIndicator {
|
||||
id: indicator
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
visible: modal.inProgress
|
||||
running: modal.inProgress
|
||||
}
|
||||
Button {
|
||||
id: button
|
||||
text: qsTr("Close")
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
visible: !modal.inProgress
|
||||
onClicked: modal.close()
|
||||
focus: true
|
||||
Keys.onReturnPressed: {
|
||||
if (!modal.inProgress)
|
||||
modal.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enter: Transition {
|
||||
NumberAnimation {
|
||||
property: "opacity"
|
||||
from: 0.0
|
||||
to: 1.0
|
||||
duration: 200
|
||||
}
|
||||
}
|
||||
exit: Transition {
|
||||
NumberAnimation {
|
||||
property: "opacity"
|
||||
from: 1.0
|
||||
to: 0.0
|
||||
duration: 200
|
||||
}
|
||||
}
|
||||
|
||||
function check () {
|
||||
if (modal.inProgress)
|
||||
return;
|
||||
|
||||
modal.inProgress = true;
|
||||
status.text = qsTr("Checking") + " " + address + "...";
|
||||
modal.status = qsTr("Checking") + " " + address + "...";
|
||||
modal.open()
|
||||
|
||||
API.test(input.text, function (err, success) {
|
||||
|
@ -120,9 +64,9 @@ Page {
|
|||
|
||||
modal.inProgress = false;
|
||||
if (err)
|
||||
status.text = err;
|
||||
modal.status = err;
|
||||
else
|
||||
status.text = qsTr("Success");
|
||||
modal.status = qsTr("Success");
|
||||
|
||||
if (!!success)
|
||||
modal.close()
|
||||
|
|
|
@ -3,7 +3,7 @@ import QtQuick.Controls
|
|||
import QtQuick.Layouts
|
||||
|
||||
import magpie.API
|
||||
import "Forms" as Forms
|
||||
import magpie.Forms as Forms
|
||||
|
||||
Page {
|
||||
id: page
|
||||
|
@ -55,6 +55,9 @@ Page {
|
|||
height: stack.currentItem ? stack.currentItem.implicitHeight: 0
|
||||
|
||||
StackView {
|
||||
property string pendingLogin: ""
|
||||
property string pendingPassword: ""
|
||||
|
||||
id: stack
|
||||
initialItem: loginForm
|
||||
anchors.fill: parent
|
||||
|
@ -64,6 +67,13 @@ Page {
|
|||
id: loginForm
|
||||
Forms.Login {
|
||||
onRegister: stack.replace(registerForm)
|
||||
Component.onCompleted: {
|
||||
if (stack.pendingLogin && stack.pendingPassword)
|
||||
this.login(stack.pendingLogin, stack.pendingPassword)
|
||||
|
||||
stack.pendingLogin = "";
|
||||
stack.pendingPassword = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -71,6 +81,11 @@ Page {
|
|||
id: registerForm
|
||||
Forms.Register {
|
||||
onLogin: stack.replace(loginForm, StackView.PopTransition)
|
||||
onSuccess: function(login, password) {
|
||||
stack.pendingLogin = login;
|
||||
stack.pendingPassword = password;
|
||||
stack.replace(loginForm, StackView.PopTransition);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue