javascript token things
This commit is contained in:
@ -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 = `
|
||||
<div id="message-win">
|
||||
<p>Test Message</p>
|
||||
</div>
|
||||
<input id="sendMessage" name="message" placeholder="Very important message..." type="text">
|
||||
`;
|
||||
|
||||
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);
|
||||
|
@ -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,
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user