102 lines
2.4 KiB
QML
102 lines
2.4 KiB
QML
import QtQuick 2.15
|
|
import QtQuick.Controls 2.15
|
|
import QtQuick.Controls.Basic
|
|
|
|
|
|
|
|
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;
|
|
}
|
|
|
|
visible: true
|
|
|
|
signal loginSuccess(string token)
|
|
|
|
color: getColors().window
|
|
|
|
Text {
|
|
id: loginL
|
|
anchors{
|
|
verticalCenter: parent.verticalCenter
|
|
verticalCenterOffset: -70
|
|
horizontalCenter: parent.horizontalCenter
|
|
}
|
|
|
|
|
|
text: qsTr("Login")
|
|
font.pointSize: 20
|
|
font.bold: true
|
|
color: getColors().text
|
|
}
|
|
|
|
TextField {
|
|
|
|
id: nameT
|
|
anchors{
|
|
horizontalCenter: parent.horizontalCenter
|
|
topMargin: 5
|
|
top: loginL.bottom
|
|
}
|
|
|
|
placeholderText: qsTr("Name")
|
|
|
|
Keys.onReturnPressed: passwordT.focus = true
|
|
|
|
}
|
|
|
|
TextField {
|
|
id: passwordT
|
|
anchors{
|
|
horizontalCenter: parent.horizontalCenter
|
|
topMargin: 5
|
|
top: nameT.bottom
|
|
}
|
|
|
|
placeholderText: qsTr("Password")
|
|
|
|
Keys.onReturnPressed: login()
|
|
|
|
echoMode: TextInput.Password
|
|
}
|
|
|
|
Button {
|
|
id: submitB
|
|
anchors{
|
|
right: passwordT.right
|
|
topMargin: 5
|
|
top: passwordT.bottom
|
|
}
|
|
|
|
text: qsTr("Submit")
|
|
|
|
onClicked: login()
|
|
Keys.onReturnPressed: login()
|
|
}
|
|
|
|
function login() {
|
|
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);
|
|
}
|
|
}
|