diff --git a/native/CMakeLists.txt b/native/CMakeLists.txt index 2a53f2f..d8f2e91 100644 --- a/native/CMakeLists.txt +++ b/native/CMakeLists.txt @@ -18,6 +18,7 @@ qt_add_qml_module(alisa Main.qml Data.qml Test.qml + MainPage.qml LoginScreen.qml RESOURCES diff --git a/native/LoginScreen.qml b/native/LoginScreen.qml index 3e36365..d3a509c 100644 --- a/native/LoginScreen.qml +++ b/native/LoginScreen.qml @@ -19,6 +19,8 @@ Window { height: 400 visible: true + signal loginSuccess(string token) + color: getColors().window Text { @@ -71,5 +73,26 @@ Window { } text: qsTr("Submit") + + onClicked: { + var xhr = new XMLHttpRequest(); + xhr.open("POST", "https://api.clan-war.net/api/v1/auth/login"); + xhr.setRequestHeader("Content-Type", "application/json"); + xhr.onreadystatechange = function() { + if (xhr.readyState === XMLHttpRequest.DONE) { + if (xhr.status === 200) { + var token = xhr.responseText.trim(); // Trim to remove any leading/trailing whitespace + loginSuccess(token); + } else { + console.log("Login failed: " + xhr.status); + } + } + } + var data = JSON.stringify({ + email: nameT.text, + password: passwordT.text + }); + xhr.send(data); + } } } diff --git a/native/Main.qml b/native/Main.qml index f271ad9..cff0dbb 100644 --- a/native/Main.qml +++ b/native/Main.qml @@ -1,4 +1,4 @@ - import QtQuick 2.15 +import QtQuick 2.15 import QtQuick.Window 2.15 import QtQuick.Layouts 2.15 import QtQuick.Controls 2.15 @@ -20,117 +20,28 @@ Window { title: qsTr("Alisa - License Managment") - Rectangle { - id: s1 - anchors { - top: parent.top - left: parent.left - right: parent.right - } - radius: 0 - height: 50 - color: getColors().midlight + property string authToken: "" - TextField { - anchors{ - verticalCenter: s1.verticalCenter - rightMargin: 5 - right: logginB.left - } + StackView { + id: stackView + anchors.fill: parent + initialItem: loginPageComponent + } - placeholderText: qsTr("Seach") - - } - - Button{ - id: logginB - anchors{ - verticalCenter: s1.verticalCenter - rightMargin: 10 - right: s1.right - } - text: qsTr("Login") - - onClicked: { - var component = Qt.createComponent("LoginScreen.qml") - var window = component.createObject(root) - window.show() + Component { + id: loginPageComponent + LoginScreen { + onLoginSuccess: { + authToken = token + stackView.push(mainPageComponent) } } } - Rectangle{ - id: s2 - anchors { - top: s1.bottom - left: parent.left - right: parent.right - bottom: parent.bottom - } - radius: 0 - color: getColors().window - - TableView { - anchors { - topMargin: 5 - fill: s2 - } - columnSpacing: 0 - rowSpacing: 1 - clip: true - boundsBehavior: Flickable.StopAtBounds - - model: Data {} - delegate: Rectangle { - id: r - anchors{ - } - color: getColors().base - implicitWidth: 100 - implicitHeight: 50 - border.width: 0 - - Text { - anchors { - horizontalCenter: r.horizontalCenter - verticalCenter: r.verticalCenter - } - text: display - color: getColors().text - anchors.centerIn: parent - } - } - } - } - - - Button { - id: testB - anchors { - bottom: parent.bottom - left: parent.left - } - text: qsTr("Test Window") - - onClicked: { - var component = Qt.createComponent("Test.qml") - var window = component.createObject(root) - window.show() - } - } - Button { - id: loginScreenB - anchors { - left: testB.right - bottom: parent.bottom - - - } - text: qsTr("Login Screen") - onClicked: { - var component = Qt.createComponent("LoginScreen.qml") - var window = component.createObject(root) - window.show() + Component { + id: mainPageComponent + MainPage { + authToken: authToken } } } diff --git a/native/MainPage.qml b/native/MainPage.qml new file mode 100644 index 0000000..1d6fba3 --- /dev/null +++ b/native/MainPage.qml @@ -0,0 +1,130 @@ +import QtQuick 2.15 +import QtQuick.Window 2.15 +import QtQuick.Layouts 2.15 +import QtQuick.Controls 2.15 + +Rectangle { + SystemPalette { id: activeColors; colorGroup: SystemPalette.Active } + SystemPalette { id: inactiveColors; colorGroup: SystemPalette.Inactive } + SystemPalette { id: disabledColors; colorGroup: SystemPalette.Disabled } + + function getColors() { + return root.active ? activeColors : inactiveColors; + } + + property string authToken: "" + + Rectangle { + id: s1 + anchors { + top: parent.top + left: parent.left + right: parent.right + } + radius: 0 + height: 50 + color: getColors().midlight + + TextField { + anchors{ + verticalCenter: s1.verticalCenter + rightMargin: 5 + right: logginB.left + } + + placeholderText: qsTr("Seach") + + } + + Button{ + id: logginB + anchors{ + verticalCenter: s1.verticalCenter + rightMargin: 10 + right: s1.right + } + text: qsTr("Login") + + onClicked: { + var component = Qt.createComponent("LoginScreen.qml") + var window = component.createObject(root) + window.show() + } + } + } + + Rectangle{ + id: s2 + anchors { + top: s1.bottom + left: parent.left + right: parent.right + bottom: parent.bottom + } + radius: 0 + color: getColors().window + + TableView { + anchors { + topMargin: 5 + fill: s2 + } + columnSpacing: 0 + rowSpacing: 1 + clip: true + boundsBehavior: Flickable.StopAtBounds + + model: Data {} + delegate: Rectangle { + id: r + anchors{ + } + color: getColors().base + implicitWidth: 100 + implicitHeight: 50 + border.width: 0 + + Text { + anchors { + horizontalCenter: r.horizontalCenter + verticalCenter: r.verticalCenter + } + text: display + color: getColors().text + anchors.centerIn: parent + } + } + } + } + + + Button { + id: testB + anchors { + bottom: parent.bottom + left: parent.left + } + text: qsTr("Test Window") + + onClicked: { + var component = Qt.createComponent("Test.qml") + var window = component.createObject(root) + window.show() + } + } + Button { + id: loginScreenB + anchors { + left: testB.right + bottom: parent.bottom + + + } + text: qsTr("Login Screen") + onClicked: { + var component = Qt.createComponent("LoginScreen.qml") + var window = component.createObject(root) + window.show() + } + } +}