68 lines
1.9 KiB
QML
68 lines
1.9 KiB
QML
import QtQuick 2.0
|
|
import Sailfish.Silica 1.0
|
|
|
|
Dialog {
|
|
Column {
|
|
id: column
|
|
spacing: Theme.paddingLarge
|
|
width: parent.width
|
|
|
|
DialogHeader {}
|
|
|
|
TextField {
|
|
id: pushoverEmail
|
|
inputMethodHints: Qt.ImhNoAutoUppercase
|
|
width: parent.width
|
|
label: "E-mail Address"
|
|
placeholderText: label
|
|
text: pf_username
|
|
|
|
EnterKey.iconSource: "image://theme/icon-m-enter-next"
|
|
EnterKey.onClicked: pushoverPassword.focus = true
|
|
}
|
|
|
|
PasswordField {
|
|
id: pushoverPassword
|
|
text: pf_password
|
|
|
|
EnterKey.iconSource: "image://theme/icon-m-accept"
|
|
EnterKey.onClicked: accept()
|
|
}
|
|
|
|
Label {
|
|
width: parent.width - 2 * Theme.horizontalPageMargin
|
|
x: Theme.horizontalPageMargin
|
|
font.pixelSize: Theme.fontSizeSmall
|
|
color: Theme.highlightColor
|
|
wrapMode: Text.WordWrap
|
|
text: "<br>Please enter your Pushover credentials."
|
|
}
|
|
}
|
|
|
|
canAccept: (pushoverEmail.text != "") && (pushoverPassword.text != "")
|
|
|
|
onAccepted: {
|
|
pf_username = pushoverEmail.text;
|
|
pf_password = pushoverPassword.text;
|
|
|
|
var req = new XMLHttpRequest();
|
|
req.open("POST", "https://api.pushover.net/1/users/login.json", false);
|
|
req.setRequestHeader("User-Agent", "Pusfofefe 3.0.0-alpha1");
|
|
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
|
var body = 'email=' + pf_username + '&password=' + pf_password;
|
|
req.send(body);
|
|
|
|
var res = req.responseText;
|
|
console.debug(res);
|
|
var body_json = JSON.parse(req.responseText);
|
|
if (body_json.status == 0) {
|
|
for (var i = 0; i < body_json.errors.length; i++) {
|
|
console.debug(body_json.errors[i]);
|
|
}
|
|
} else {
|
|
pf_device_id = body_json.id;
|
|
pf_secret = body_json.secret;
|
|
}
|
|
}
|
|
}
|