33 lines
1.1 KiB
JavaScript
33 lines
1.1 KiB
JavaScript
|
|
// Attempt to log in using ambient authority (e.g., Kerberos, SSL, etc)
|
|
async function tryLoginAmbient() {
|
|
let resp = await fetch("/login/krb5" + window.location.search, {method: "POST", redirect: "manual"})
|
|
if (resp.ok) {
|
|
window.location = await resp.text()
|
|
}
|
|
}
|
|
|
|
async function tryLoginPassword() {
|
|
let userField = document.getElementById("user")
|
|
let passwordField = document.getElementById("password")
|
|
let doit = document.getElementById("doit")
|
|
try {
|
|
userField.enabled = passwordField.enabled = doit.enabled = false
|
|
let resp = await fetch("/login/password" + window.location.search, {method: "POST"})
|
|
if (resp.ok) {
|
|
window.location = await resp.text()
|
|
}
|
|
} catch (e) {
|
|
userField.enabled = passwordField.enabled = doit.enabled = true
|
|
throw e
|
|
}
|
|
}
|
|
|
|
tryLoginAmbient() // don't bother awaiting, just let 'er go
|
|
document.addEventListener("load", () => {
|
|
document.getElementById("doit").form.addEventListener("submit", function (e) {
|
|
e.preventDefault()
|
|
tryLoginPassword()
|
|
return false
|
|
})
|
|
}) |