diff --git a/app/index.js b/app/index.js
index 8b13789..f347b7a 100644
--- a/app/index.js
+++ b/app/index.js
@@ -1 +1,42 @@
+////////////////////////////////////////////////////////////////////////
+// WebPage
+////////////////////////////////////////////////////////////////////////
+var CONFIG = require("lib/config");
+var FILE = require("lib/file");
+var OldBrowser = require("lib/oldbrowser");
+var HTTP = require("lib/http");
+var apiUrl = CONFIG.readConfig("/Config/ApiUrl").first().text;
+var token;
+
+if (FILE.fileExists("token.txt")) {
+ token = FILE.readFile("token.txt", "utf-8");
+}
+
+if (typeof(token) === "undefined") {
+ OldBrowser.setContent(FILE.readFile("app\\login.html", "utf-8"));
+
+ document.getElementById("loginform").onsubmit = function(ev) {
+ ev.preventDefault();
+ };
+
+ document.getElementById("btn_submit").onclick = function() {
+ var credential = JSON.stringify({
+ "email": document.getElementById("txt_email").value,
+ "password": document.getElementById("txt_password").value
+ });
+
+ var req = HTTP.post(apiUrl + "/netsolid/auth/authenticate", credential, {
+ "Content-Type": "application/json"
+ });
+
+ var res = JSON.parse(req.responseText);
+
+ if ("error" in res) {
+ console.error(res.error.message);
+ } else if ("data" in res) {
+ console.log("ok");
+ FILE.writeFile("token.txt", res.data.token, "utf-8");
+ }
+ };
+}
diff --git a/app/login.html b/app/login.html
new file mode 100644
index 0000000..5d18740
--- /dev/null
+++ b/app/login.html
@@ -0,0 +1,75 @@
+
diff --git a/lib/directus.js b/lib/directus.js
new file mode 100644
index 0000000..04c6297
--- /dev/null
+++ b/lib/directus.js
@@ -0,0 +1,21 @@
+////////////////////////////////////////////////////////////////////////
+// Directus API
+///////////////////////////////////////////////////////////////////////
+
+var CONFIG = require("lib/config");
+var HTTP = require("lib/http");
+
+exports.authenticate = function() {
+ var apiUrl = CONFIG.readConfig("/Config/ApiUrl").first().text;
+/*
+ var http = HTTP.post(apiUrl + "/netsolid/auth/authenticate", JSON.stringify({
+ "email": "admin@example.org",
+ "password": "1234"
+ }), {
+ "Content-Type": "application/json"
+ });
+
+ console.log(http.responseBody);
+ return http;
+*/
+};
diff --git a/lib/http.js b/lib/http.js
index 587d646..80b9b79 100644
--- a/lib/http.js
+++ b/lib/http.js
@@ -2,20 +2,18 @@
// HTTP API
////////////////////////////////////////////////////////////////////////
-var LIB = require("lib/std");
-
exports.VERSIONINFO = "HTTP Lib (http.js) version 0.1";
exports.global = global;
exports.require = global.require;
exports.create = function() {
- var http = null;
+ var http;
try {
- http = LIB.CreateObject("Microsoft.XMLHTTP");
- } catch (e) {
- http = LIB.CreateObject("WinHttp.WinHttpRequest.5.1");
- http.setTimeouts(30000, 30000, 30000, 0)
+ http = CreateObject("Microsoft.XMLHTTP");
+ } catch(e) {
+ http = CreateObject("WinHttp.WinHttpRequest.5.1");
+ http.setTimeouts(30000, 30000, 30000, 0);
}
return http;
@@ -29,12 +27,14 @@ exports.addHeaders = function(http, headers) {
var value = headers[key];
http.setRequestHeader(key, value);
- if (key.toUpperCase() == "CONTENT-TYPE")
+ if (key.toUpperCase() == "CONTENT-TYPE") {
content = true;
+ }
}
- if (!content)
+ if (!content) {
http.setRequestHeader("Content-Type", "application/octet-stream");
+ }
};
exports.post = function(url, data, headers) {
diff --git a/lib/oldbrowser.js b/lib/oldbrowser.js
index bc273d4..432333e 100644
--- a/lib/oldbrowser.js
+++ b/lib/oldbrowser.js
@@ -231,6 +231,5 @@ exports.start = function(callback) {
if (IEVersion < 10) {
exports.addScript("app/assets/js/PIE-1.0.0.js");
exports.addScript("app/assets/js/jquery.html5-placeholder-shim-5a87f05.js");
- exports.addScript("app/assets/js/jquery.form-4.3.0.min.js");
}
};
diff --git a/token.txt b/token.txt
new file mode 100644
index 0000000..9526c54
--- /dev/null
+++ b/token.txt
@@ -0,0 +1 @@
+eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6MSwiZXhwIjoxNjA0NTU0MTQ5LCJ0dGwiOjIwLCJ0eXBlIjoiYXV0aCIsImtleSI6Ijg1N2NlZDg1LTMzOWEtNDViNS04YTQ5LTJjOGM0YmE4ZDVmNCIsInByb2plY3QiOiJuZXRzb2xpZCJ9.m9DzCyaEjVhT5Z6jDS_gtUaB7AVnLjVHGqK4CxGXWnM
\ No newline at end of file
diff --git a/webloader.js b/webloader.js
index ad7f3ef..fb8bf7e 100644
--- a/webloader.js
+++ b/webloader.js
@@ -93,10 +93,14 @@ exports.IEVersion = OldBrowser.getIEVersion();
exports.main = function(args) {
// make will display contents
OldBrowser.setContent(FILE.readFile("app\\index.html", "utf-8"));
+
+ // add stylesheets
OldBrowser.addStylesheet("app/assets/css/jquery-ui-1.21.1.min.css");
OldBrowser.addStylesheet("app/assets/css/jquery.toast-1.3.2.min.css");
OldBrowser.addStylesheet("app/assets/css/cascade/production/build-full.min.css");
OldBrowser.addStylesheet("app/assets/css/style.css");
+
+ // start
OldBrowser.start(function(el) {
jQuery.support.cors = true;
@@ -109,13 +113,11 @@ exports.main = function(args) {
}
// start this app
+ OldBrowser.addScript("app/assets/js/jquery.form-4.3.0.min.js");
OldBrowser.addScript("app/index.js");
// hide loading image
document.getElementById("loading").style.display = "none";
-
- // show API server URL
- console.info(CONFIG.readConfig("/Config/ApiUrl").first().text);
}
}, function(el) {
return window.jQuery.toast;