native: fix login button

fixes #20
This commit is contained in:
jopejoe1 2024-07-11 11:41:24 +02:00
parent ffae1c2ed7
commit a6118791b1
2 changed files with 22 additions and 20 deletions

View file

@ -71,25 +71,27 @@ Rectangle {
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);
}
onClicked: 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);
}
var data = JSON.stringify({
email: nameT.text,
password: passwordT.text
});
xhr.send(data);
}
}

View file

@ -31,9 +31,9 @@ Window {
Component {
id: loginPageComponent
LoginScreen {
onLoginSuccess: {
authToken = token
stackView.push(mainPageComponent)
onLoginSuccess: function(token) {
authToken = token;
stackView.push(mainPageComponent);
}
}
}