forked from NotNet/gluestick
62 lines
1.4 KiB
HTML
62 lines
1.4 KiB
HTML
{{ template "header.html" . }}
|
|
|
|
<script>
|
|
let source = null;
|
|
function sendToGluestick(msg) {
|
|
source.postMessage(msg, {
|
|
targetOrigin: '{{ print (extra "gluestick_url") }}'
|
|
});
|
|
}
|
|
|
|
document.addEventListener("DOMContentLoaded", () => {
|
|
window.addEventListener(
|
|
"message",
|
|
(e) => {
|
|
if (e.origin != '{{ print (extra "gluestick_url") }}') return;
|
|
|
|
switch (e.data.type) {
|
|
case "passwordSubmit":
|
|
const { username, password } = e.data;
|
|
submitLogin(username, password);
|
|
break;
|
|
}
|
|
},
|
|
false
|
|
);
|
|
|
|
const iframe = document.querySelector("iframe");
|
|
iframe.addEventListener("load", () => {
|
|
source = iframe.contentWindow;
|
|
sendToGluestick({ type: "hello" });
|
|
});
|
|
});
|
|
|
|
async function submitLogin(username, password) {
|
|
const params = new URLSearchParams();
|
|
params.append("login", username);
|
|
params.append("password", password);
|
|
|
|
const req = await fetch("{{ .PostURL }}", {
|
|
headers: {
|
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
},
|
|
body: params,
|
|
method: "POST",
|
|
redirect: "follow"
|
|
});
|
|
|
|
if (req.ok && req.redirected) {
|
|
window.location.href = req.url;
|
|
return;
|
|
}
|
|
|
|
sendToGluestick({
|
|
type: "passwordSubmitResult",
|
|
success: req.ok
|
|
});
|
|
}
|
|
</script>
|
|
<iframe src='{{ print (extra "gluestick_url") "/dex/password" }}'></iframe>
|
|
|
|
{{ template "footer.html" . }}
|