diff --git a/www/res/js/locutus.js b/www/res/js/locutus.js
index 8e0cb01..66bd938 100644
--- a/www/res/js/locutus.js
+++ b/www/res/js/locutus.js
@@ -3,6 +3,10 @@
let main, windows;
let defaultLocation = '/welcome';
+let token = "";
+let domain = "";
+let dest = "";
+
function createWelcomeWindow() {
let win = document.createElement("div");
win.id = "welcome-win";
@@ -15,6 +19,43 @@ function createWelcomeWindow() {
windows.appendChild(win);
}
+function createChatWindow() {
+ let win = document.createElement("div");
+ win.id = "chat-win";
+
+ win.innerHTML = `
+
+
+ `;
+
+ win.getElementById("sendMessage").addEventListener("keyup", (evt) => {
+ if (evt.keyCode === 13) {
+ evt.preventDefault();
+ //TODO: Send Message
+ }
+ });
+
+
+ main.appendChild(win);
+}
+
+async function sendEvent(message) {
+ let res = await fetch(dest, {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Authorization': `usimp ${token}`,
+ },
+ body: message
+ });
+
+ let result = await res;
+ alert(result.message);
+}
+
+
function createLoginWindow() {
let win = document.createElement("div");
win.id = "login-win";
@@ -52,6 +93,15 @@ function createLoginWindow() {
console.log(data["domain"]);
let domainServer = usimp.chooseDomainServer(data["domain_servers"]);
console.log(domainServer);
+ dest = "http://" + domainServer.host + ':' + domainServer.protocols.http + "/"
+
+ usimp.login(domainServer, data["domain"].id, form.elements["account"].value, form.elements["password"].value)
+ .then(res => res.json())
+ .then(data => {
+ token = data.token;
+ console.log(data.token);
+ })
+
})
.catch(reason => {
console.error(reason);
diff --git a/www/res/js/usimp.js b/www/res/js/usimp.js
index 5beb350..e7b5a15 100644
--- a/www/res/js/usimp.js
+++ b/www/res/js/usimp.js
@@ -32,6 +32,18 @@ usimp.chooseDomainServer = function (domainServers, invalidDomainServers = []) {
return domainServers[0];
}
-usimp.login = function (domainServer, accountName, password) {
- return fetch(``)
+usimp.login = function (domainServer, domain, account, password) {
+ return fetch('http://' + domainServer.host + ':' + domainServer.protocols.http + '/_usimp/authenticate', {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ 'To-Domain': domain,
+ 'From-Domain': domain
+ },
+ body: JSON.stringify({
+ type: "password",
+ name: account,
+ password: password,
+ }),
+ });
}