78 lines
2.0 KiB
HTML
78 lines
2.0 KiB
HTML
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>MASI 3DSecure</title>
|
|
|
|
<style>
|
|
body {
|
|
font-family: Arial, sans-serif;
|
|
margin: 0;
|
|
padding: 0;
|
|
}
|
|
header, footer {
|
|
background: #f4f4f4;
|
|
padding: 15px;
|
|
text-align: center;
|
|
}
|
|
main {
|
|
padding: 20px;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<main>
|
|
<input id="username-field" placeholder="Username">
|
|
<br>
|
|
<input id="password-field" placeholder="Password">
|
|
<br>
|
|
<button id="connect-button">Connect</button>
|
|
</main>
|
|
|
|
<script>
|
|
|
|
function redirectToProtectedRoute(route) {
|
|
let data = JSON.parse(localStorage.getItem("creds"));
|
|
|
|
fetch(route, {
|
|
headers: {
|
|
"Authorization": `Basic ${data.username}:${data.password}`
|
|
}
|
|
})
|
|
.then(r => r.text())
|
|
.then(html => document.body.innerHTML = html);
|
|
}
|
|
|
|
let btn = document.getElementById("connect-button");
|
|
btn.addEventListener("click", async () => {
|
|
let username = document.getElementById("username-field").value;
|
|
let pwd = document.getElementById("password-field").value;
|
|
|
|
let data = {
|
|
username: username,
|
|
password: pwd
|
|
};
|
|
|
|
await fetch("/login", {
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json"
|
|
},
|
|
body: JSON.stringify(data)})
|
|
.then(response => {
|
|
if(response.ok) {
|
|
localStorage.setItem("creds", JSON.stringify(data));
|
|
redirectToProtectedRoute("/payment");
|
|
} else {
|
|
throw new Error("Authentication request failed")
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error(error);
|
|
});
|
|
});
|
|
|
|
</script>
|
|
</body>
|
|
</html> |