File: webdav.js

package info (click to toggle)
lomiri-cloudsync-app 0.8.1%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,560 kB
  • sloc: cpp: 1,053; python: 67; javascript: 25; makefile: 21; sh: 9
file content (33 lines) | stat: -rw-r--r-- 1,068 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
var QmlObject = Qt.createQmlObject('import QtQuick 2.0; QtObject { signal credentialsValid(bool valid) }', Qt.application, 'QmlObject');

function emit_validation_complete(valid) {
    console.log("[webdav.js - emit_validation_complete]")
    QmlObject.credentialsValid(valid);
}

function validateCredentials(username, password, serverURL){

    var req = new XMLHttpRequest();
    var protocol = serverURL.toLowerCase().indexOf("http://") === -1 ? "https://" : "http://"
    var url = serverURL.replace(/^https?\:\/\//i, "")

    var location = protocol + username + ":" + password + "@" +
            url + "/remote.php/webdav/"

    req.open("GET", location, true);
    req.send(null);

    //wait until the readyState is 4, which means the json is ready
    req.onreadystatechange = function()
    {
        if (req.readyState == 4){
            if (req.status == 200){
                console.log(req.responseText)
                emit_validation_complete(true)
            }else{
                emit_validation_complete(false)
            }
        }
    }
}