You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
109 lines
3.2 KiB
JavaScript
109 lines
3.2 KiB
JavaScript
"use strict";
|
|
|
|
require("core-js/modules/es6.regexp.replace");
|
|
|
|
require("core-js/modules/es6.string.starts-with");
|
|
|
|
/*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
*/
|
|
netsymscomurl = "https://apps.netsyms.com/notepost";
|
|
netsymsbizurl = "https://BIZID.netsyms.biz/notepost";
|
|
$('#use-security-checkbox-li').click(function () {
|
|
// Event fires before the checkbox is changed, so we need to do the opposite
|
|
if ($("#use-security").prop("checked")) {
|
|
$('#protocol-select').text("https://");
|
|
} else {
|
|
$('#protocol-select').text("http://");
|
|
}
|
|
});
|
|
/* Detect if the user typed "http[s]://" into the URL box and correct for it */
|
|
|
|
$("#url").blur(function () {
|
|
if ($('#url').val().toLowerCase().startsWith("https://")) {
|
|
$('#url').val($('#url').val().replace(/https\:\/\//ig, ""));
|
|
$('#protocol-select').text("https://");
|
|
$('#use-security').prop('checked', true);
|
|
} else if ($('#url').val().toLowerCase().startsWith("http://")) {
|
|
$('#url').val($('#url').val().replace(/http\:\/\//ig, ""));
|
|
$('#protocol-select').text("http://");
|
|
$('#use-security').prop('checked', false);
|
|
}
|
|
});
|
|
$('#username').on("keyup", function () {
|
|
$('#username').val($('#username').val().toLowerCase());
|
|
});
|
|
|
|
function checkAndSave(url, username, password, nextcloud) {
|
|
app.preloader.show();
|
|
|
|
if (typeof nextcloud === 'undefined') {
|
|
nextcloud = false;
|
|
}
|
|
|
|
var checkurl = url + "/api/ping";
|
|
|
|
if (nextcloud) {// TODO
|
|
}
|
|
|
|
$.ajax({
|
|
url: checkurl,
|
|
dataType: "json",
|
|
cache: false,
|
|
method: "POST",
|
|
beforeSend: function beforeSend(xhr) {
|
|
xhr.setRequestHeader("Authorization", "Basic " + btoa(username + ":" + password));
|
|
},
|
|
success: function success(data) {
|
|
app.preloader.hide();
|
|
|
|
if (data.status == "OK") {
|
|
localStorage.setItem("username", username);
|
|
localStorage.setItem("password", password);
|
|
localStorage.setItem("serverurl", url);
|
|
localStorage.setItem("configured", true); // Restart the app to re-read the config
|
|
|
|
restartApplication();
|
|
} else if (data.status == "ERROR") {
|
|
app.dialog.alert(data.msg, "Error");
|
|
} else {
|
|
app.dialog.alert("", "Error");
|
|
}
|
|
},
|
|
error: function error() {
|
|
app.preloader.hide();
|
|
app.dialog.alert("Could not sign in. Check your credentials and connection.", "Error");
|
|
}
|
|
});
|
|
}
|
|
|
|
function setupAccount() {
|
|
var type = $("#accttype").val();
|
|
var username = $("#username").val();
|
|
var password = $("#password").val();
|
|
|
|
switch (type) {
|
|
case "personal":
|
|
checkAndSave(netsymscomurl, username, password);
|
|
break;
|
|
|
|
case "business":
|
|
var url = netsymsbizurl.replace("BIZID", $("#bizid").val());
|
|
checkAndSave(url, username, password);
|
|
break;
|
|
|
|
case "selfhosted":
|
|
if (/^(https?:\/\/)/.test($('#url').val())) {
|
|
var url = $('#url').val();
|
|
} else {
|
|
var url = $('#protocol-select').text() + $('#url').val();
|
|
}
|
|
|
|
url = url.replace(/\/$/, ""); // Remove trailing slash
|
|
|
|
checkAndSave(url, username, password);
|
|
break;
|
|
}
|
|
} |