megacommit
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
<body>
|
||||
<div class="signup-container">
|
||||
<div class="signup-header">
|
||||
<div class="logo">DC</div>
|
||||
<img src="/static/favicon.ico" class="logo"/>
|
||||
<h1>2FA Setup</h1>
|
||||
</div>
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
<div class="form-group">
|
||||
<input
|
||||
type="text"
|
||||
id="mfa_code"
|
||||
inputmode="numeric"
|
||||
pattern="[0-9]*"
|
||||
maxlength="6"
|
||||
@@ -38,10 +39,73 @@
|
||||
</div>
|
||||
|
||||
<script>
|
||||
fetch('/api/totp.jpg')
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
document.getElementById('qr-code').src = data.qr_code;
|
||||
const form = {
|
||||
code: document.getElementById("mfa_code"),
|
||||
};
|
||||
|
||||
submitButton.addEventListener("click", async function () {
|
||||
submitButton.disabled = true;
|
||||
submitButton.innerHTML =
|
||||
'<span class="loading-spinner"></span>Creating Account...';
|
||||
|
||||
// Prepare data
|
||||
const formData = {
|
||||
code: form.code.value.trim(),
|
||||
};
|
||||
|
||||
try {
|
||||
// Replace with your actual backend endpoint
|
||||
const response = await fetch(
|
||||
"/api/totp",
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(formData),
|
||||
},
|
||||
);
|
||||
|
||||
if (response.ok) {
|
||||
// Show success message
|
||||
successMessage.classList.add("show");
|
||||
submitButton.innerHTML = "2FA Enabled";
|
||||
|
||||
// Optional: Redirect after success
|
||||
setTimeout(() => {
|
||||
window.location.href = '/chat';
|
||||
// console.log("Redirecting to chat...");
|
||||
}, 2000);
|
||||
} else {
|
||||
const error = await response.text();
|
||||
throw new Error(error || "Login failed");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Login error:", error);
|
||||
alert(
|
||||
error.message ||
|
||||
"Failed to login. Please try again.",
|
||||
);
|
||||
submitButton.disabled = false;
|
||||
submitButton.innerHTML = "Login";
|
||||
}
|
||||
});
|
||||
|
||||
fetch('/api/totp.jpg')
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
document.getElementById('qr-code').src = data.qr_code;
|
||||
});
|
||||
|
||||
// Allow Enter key to submit
|
||||
Object.values(form).forEach((input) => {
|
||||
if (input.tagName === "INPUT") {
|
||||
input.addEventListener("keypress", function (e) {
|
||||
if (e.key === "Enter") {
|
||||
submitButton.click();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user