mirror of
https://github.com/plexguide/Huntarr.git
synced 2026-01-25 20:58:48 -06:00
768 lines
29 KiB
HTML
768 lines
29 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Setup - Huntarr</title>
|
|
<!-- Inline script to prevent theme flashing -->
|
|
<script>
|
|
// Always use dark mode for setup page
|
|
document.documentElement.classList.add('dark-theme');
|
|
document.write('<style>body, html { background-color: #1a1d24 !important; color: #f8f9fa !important; } .login-container { background-color: #252a34 !important; } .login-header { background-color: #121212 !important; }</style>');
|
|
</script>
|
|
<!-- Preload logo -->
|
|
<link rel="preload" href="/static/logo/256.png" as="image" fetchpriority="high">
|
|
<link rel="stylesheet" href="/static/css/style.css">
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
|
<link rel="icon" href="/static/logo/16.png">
|
|
<!-- Preload script to prevent flashing -->
|
|
<script src="/static/js/theme-preload.js"></script>
|
|
<style>
|
|
/* Modern setup page styles */
|
|
.login-page {
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
min-height: 100vh;
|
|
background: linear-gradient(135deg, #13171f 0%, #1c2230 100%);
|
|
margin: 0;
|
|
padding: 20px;
|
|
}
|
|
|
|
.login-container {
|
|
width: 500px;
|
|
max-width: 90%;
|
|
background: linear-gradient(180deg, rgba(22, 26, 34, 0.98), rgba(18, 22, 30, 0.95));
|
|
border-radius: 15px;
|
|
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
|
|
overflow: hidden;
|
|
border: 1px solid rgba(90, 109, 137, 0.15);
|
|
}
|
|
|
|
.login-header {
|
|
background: linear-gradient(180deg, rgba(18, 22, 30, 0.98), rgba(24, 28, 37, 0.95));
|
|
padding: 25px 0;
|
|
text-align: center;
|
|
border-bottom: 1px solid rgba(90, 109, 137, 0.15);
|
|
}
|
|
|
|
.login-logo {
|
|
width: 70px;
|
|
height: 70px;
|
|
margin-bottom: 10px;
|
|
filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.2));
|
|
transition: transform 0.3s ease;
|
|
opacity: 1;
|
|
}
|
|
|
|
.login-logo:hover {
|
|
transform: scale(1.05);
|
|
}
|
|
|
|
.login-header h1 {
|
|
margin: 0;
|
|
color: #fff;
|
|
font-size: 24px;
|
|
font-weight: 600;
|
|
text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
|
|
}
|
|
|
|
.login-form {
|
|
padding: 25px;
|
|
}
|
|
|
|
/* Setup steps navigation */
|
|
.setup-steps {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
margin-bottom: 20px;
|
|
gap: 10px;
|
|
}
|
|
|
|
.step {
|
|
padding: 10px;
|
|
background: rgba(28, 36, 54, 0.6);
|
|
border-radius: 10px;
|
|
font-weight: 500;
|
|
flex: 1;
|
|
text-align: center;
|
|
margin: 0;
|
|
opacity: 0.6;
|
|
font-size: 0.85em;
|
|
transition: all 0.3s ease;
|
|
border: 1px solid rgba(90, 109, 137, 0.2);
|
|
color: rgba(255, 255, 255, 0.7);
|
|
}
|
|
|
|
.step.active {
|
|
background: linear-gradient(135deg, #3a71e4 0%, #5481e6 100%);
|
|
color: white;
|
|
opacity: 1;
|
|
border-color: rgba(90, 109, 137, 0.3);
|
|
box-shadow: 0 4px 10px rgba(58, 113, 228, 0.2);
|
|
transform: translateY(-2px);
|
|
}
|
|
|
|
.step.completed {
|
|
background: linear-gradient(135deg, #28a745 0%, #34ce57 100%);
|
|
color: white;
|
|
opacity: 1;
|
|
border-color: rgba(40, 167, 69, 0.3);
|
|
}
|
|
|
|
/* Form styling */
|
|
.setup-section {
|
|
display: none;
|
|
animation: fadeIn 0.3s ease;
|
|
}
|
|
|
|
.setup-section.active {
|
|
display: block;
|
|
}
|
|
|
|
@keyframes fadeIn {
|
|
from { opacity: 0; transform: translateY(5px); }
|
|
to { opacity: 1; transform: translateY(0); }
|
|
}
|
|
|
|
.form-group {
|
|
margin-bottom: 20px;
|
|
position: relative;
|
|
}
|
|
|
|
.form-group label {
|
|
display: flex;
|
|
align-items: center;
|
|
margin-bottom: 8px;
|
|
color: rgba(255, 255, 255, 0.9);
|
|
font-weight: 500;
|
|
}
|
|
|
|
.form-group label i {
|
|
margin-right: 8px;
|
|
color: rgba(65, 105, 225, 0.9);
|
|
}
|
|
|
|
.form-group input {
|
|
width: 100%;
|
|
padding: 12px 15px;
|
|
border: 1px solid rgba(90, 109, 137, 0.2);
|
|
border-radius: 8px;
|
|
background-color: rgba(28, 36, 54, 0.6);
|
|
color: #fff;
|
|
font-size: 16px;
|
|
transition: all 0.3s ease;
|
|
}
|
|
|
|
.form-group input:focus {
|
|
border-color: rgba(65, 105, 225, 0.6);
|
|
box-shadow: 0 0 0 3px rgba(65, 105, 225, 0.2);
|
|
outline: none;
|
|
}
|
|
|
|
.password-requirements {
|
|
margin-top: 8px;
|
|
font-size: 13px;
|
|
color: rgba(255, 255, 255, 0.7);
|
|
}
|
|
|
|
.requirement {
|
|
display: flex;
|
|
align-items: center;
|
|
margin-bottom: 3px;
|
|
}
|
|
|
|
.requirement i {
|
|
margin-right: 5px;
|
|
font-size: 12px;
|
|
}
|
|
|
|
.requirement.valid i {
|
|
color: #28a745;
|
|
}
|
|
|
|
.requirement.invalid i {
|
|
color: #dc3545;
|
|
}
|
|
|
|
.toggle-password {
|
|
position: absolute;
|
|
right: 12px;
|
|
top: 40px;
|
|
cursor: pointer;
|
|
color: rgba(255, 255, 255, 0.6);
|
|
}
|
|
|
|
.toggle-password:hover {
|
|
color: rgba(255, 255, 255, 0.9);
|
|
}
|
|
|
|
/* Buttons and actions */
|
|
.form-actions {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
margin-top: 25px;
|
|
}
|
|
|
|
.next-button, .back-button, .submit-button {
|
|
padding: 12px 24px;
|
|
border-radius: 8px;
|
|
font-weight: 600;
|
|
font-size: 16px;
|
|
transition: all 0.3s ease;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
}
|
|
|
|
.next-button, .submit-button {
|
|
background: linear-gradient(135deg, #3a71e4 0%, #5481e6 100%);
|
|
color: white;
|
|
border: none;
|
|
box-shadow: 0 4px 10px rgba(58, 113, 228, 0.3);
|
|
}
|
|
|
|
.next-button:hover, .submit-button:hover {
|
|
background: linear-gradient(135deg, #4a7deb 0%, #6491fa 100%);
|
|
transform: translateY(-2px);
|
|
box-shadow: 0 6px 15px rgba(58, 113, 228, 0.4);
|
|
}
|
|
|
|
.back-button {
|
|
background: transparent;
|
|
border: 1px solid rgba(90, 109, 137, 0.3);
|
|
color: rgba(255, 255, 255, 0.8);
|
|
}
|
|
|
|
.back-button:hover {
|
|
background: rgba(90, 109, 137, 0.1);
|
|
border-color: rgba(90, 109, 137, 0.5);
|
|
color: white;
|
|
}
|
|
|
|
.next-button:active, .back-button:active, .submit-button:active {
|
|
transform: translateY(0);
|
|
box-shadow: 0 2px 8px rgba(58, 113, 228, 0.3);
|
|
}
|
|
|
|
/* Skip button styling */
|
|
.skip-button {
|
|
padding: 12px 24px;
|
|
border-radius: 8px;
|
|
font-weight: 600;
|
|
font-size: 16px;
|
|
transition: all 0.3s ease;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
background: linear-gradient(135deg, rgba(220, 53, 69, 0.9) 0%, rgba(220, 53, 69, 0.8) 100%);
|
|
color: white;
|
|
border: none;
|
|
box-shadow: 0 4px 10px rgba(220, 53, 69, 0.3);
|
|
cursor: pointer;
|
|
}
|
|
|
|
.skip-button:hover {
|
|
background: linear-gradient(135deg, rgba(220, 53, 69, 1) 0%, rgba(220, 53, 69, 0.9) 100%);
|
|
transform: translateY(-2px);
|
|
box-shadow: 0 6px 15px rgba(220, 53, 69, 0.4);
|
|
}
|
|
|
|
.skip-button:active {
|
|
transform: translateY(0);
|
|
box-shadow: 0 2px 8px rgba(220, 53, 69, 0.3);
|
|
}
|
|
|
|
/* Error message styling */
|
|
.error-message {
|
|
background-color: rgba(220, 53, 69, 0.2);
|
|
color: #ff6b6b;
|
|
padding: 12px;
|
|
border-radius: 8px;
|
|
margin-bottom: 20px;
|
|
text-align: center;
|
|
border-left: 4px solid #dc3545;
|
|
display: none;
|
|
}
|
|
|
|
/* Success message */
|
|
.success-message {
|
|
background-color: rgba(40, 167, 69, 0.2);
|
|
color: #2ecc71;
|
|
padding: 12px;
|
|
border-radius: 8px;
|
|
margin-bottom: 20px;
|
|
text-align: center;
|
|
border-left: 4px solid #28a745;
|
|
}
|
|
|
|
/* QR code styling */
|
|
.qr-container {
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
margin: 20px 0;
|
|
}
|
|
|
|
.qr-code {
|
|
background: white;
|
|
padding: 10px;
|
|
border-radius: 8px;
|
|
margin-bottom: 15px;
|
|
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
|
|
width: 64px;
|
|
height: 64px;
|
|
margin: 0 auto 15px;
|
|
}
|
|
|
|
.qr-code img {
|
|
width: 100%;
|
|
height: 100%;
|
|
display: block;
|
|
}
|
|
|
|
/* Responsive QR code for mobile */
|
|
@media (max-width: 768px) {
|
|
.qr-code {
|
|
width: 30%;
|
|
height: auto;
|
|
}
|
|
}
|
|
|
|
.secret-key {
|
|
font-family: monospace;
|
|
padding: 10px 15px;
|
|
background: rgba(28, 36, 54, 0.8);
|
|
border-radius: 8px;
|
|
border: 1px solid rgba(90, 109, 137, 0.3);
|
|
color: rgba(255, 255, 255, 0.9);
|
|
margin-bottom: 15px;
|
|
width: 100%;
|
|
text-align: center;
|
|
font-size: 14px;
|
|
user-select: all;
|
|
}
|
|
|
|
.copy-button {
|
|
background: transparent;
|
|
border: 1px solid rgba(90, 109, 137, 0.3);
|
|
color: rgba(255, 255, 255, 0.8);
|
|
padding: 8px 15px;
|
|
border-radius: 6px;
|
|
cursor: pointer;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 6px;
|
|
font-size: 14px;
|
|
transition: all 0.2s ease;
|
|
}
|
|
|
|
.copy-button:hover {
|
|
background: rgba(90, 109, 137, 0.1);
|
|
border-color: rgba(90, 109, 137, 0.5);
|
|
color: white;
|
|
}
|
|
|
|
/* Responsive adjustments */
|
|
@media (max-width: 768px) {
|
|
.login-container {
|
|
width: 95%;
|
|
}
|
|
|
|
.login-form {
|
|
padding: 20px;
|
|
}
|
|
|
|
.login-header {
|
|
padding: 20px 0;
|
|
}
|
|
|
|
.login-logo {
|
|
width: 60px;
|
|
height: 60px;
|
|
}
|
|
|
|
.form-actions {
|
|
flex-direction: column-reverse;
|
|
gap: 10px;
|
|
}
|
|
|
|
.next-button, .back-button, .submit-button {
|
|
width: 100%;
|
|
justify-content: center;
|
|
}
|
|
|
|
.step {
|
|
font-size: 0.75em;
|
|
padding: 8px 5px;
|
|
}
|
|
}
|
|
</style>
|
|
</head>
|
|
<body class="login-page dark-mode">
|
|
<div class="login-container">
|
|
<div class="login-header">
|
|
<img src="/static/logo/256.png" alt="Huntarr Logo" class="login-logo">
|
|
<h1>Huntarr</h1>
|
|
</div>
|
|
<div class="login-form">
|
|
<div class="setup-steps">
|
|
<div id="step1" class="step active">1. Create Account</div>
|
|
<div id="step2" class="step">2. Setup 2FA</div>
|
|
<div id="step3" class="step">3. Finish</div>
|
|
</div>
|
|
|
|
<div id="accountSetup" class="setup-section active">
|
|
<h2>Create Your Account</h2>
|
|
<p>Set up your administrator credentials</p>
|
|
<div class="form-group">
|
|
<label for="username">
|
|
<i class="fas fa-user"></i>
|
|
<span>Username</span>
|
|
</label>
|
|
<input type="text" id="username" name="username" required>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="password">
|
|
<i class="fas fa-lock"></i>
|
|
<span>Password</span>
|
|
</label>
|
|
<input type="password" id="password" name="password" required>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="confirm_password">
|
|
<i class="fas fa-check-circle"></i>
|
|
<span>Confirm Password</span>
|
|
</label>
|
|
<input type="password" id="confirm_password" name="confirm_password" required>
|
|
</div>
|
|
<div class="error-message" id="errorMessage" style="display: none;"></div>
|
|
<div class="form-actions">
|
|
<button type="button" id="accountNextButton" class="next-button">
|
|
<i class="fas fa-arrow-right"></i> Next
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="twoFactorSetup" class="setup-section">
|
|
<h2>Setup Two-Factor Authentication</h2>
|
|
<div class="qr-container">
|
|
<p>Scan this QR code with your auth app:</p>
|
|
<div class="qr-code" id="qrCode">
|
|
<img src="" alt="QR Code" style="display: none;"> <!-- Add img tag, initially hidden -->
|
|
</div>
|
|
<p>Or enter this code manually in your app:</p>
|
|
<div class="secret-key" id="secretKey">Generating...</div>
|
|
|
|
<div class="form-group">
|
|
<label for="verificationCode">
|
|
<i class="fas fa-shield-alt"></i>
|
|
<span>Verification Code</span>
|
|
</label>
|
|
<input type="text" id="verificationCode" placeholder="Enter 6-digit code" maxlength="6">
|
|
</div>
|
|
|
|
<div class="form-actions">
|
|
<button type="button" id="twoFactorNextButton" class="next-button">
|
|
<i class="fas fa-check"></i> Verify & Continue
|
|
</button>
|
|
<button id="skip2FALink" class="skip-button">
|
|
<i class="fas fa-times"></i> Skip 2FA setup
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="setupComplete" class="setup-section">
|
|
<h2>Setup Complete</h2>
|
|
<p>Your Huntarr account has been created successfully!</p>
|
|
<div style="text-align: center; margin-top: 20px;">
|
|
<div style="background-color: #2c2c2c; border-radius: 8px; padding: 15px; margin-bottom: 20px;">
|
|
<p><i class="fas fa-shield-alt" style="color: #4a90e2; font-size: 24px;"></i></p>
|
|
<p style="font-weight: bold; margin-top: 10px;">Local Authentication Bypass Available</p>
|
|
<p style="margin-top: 5px;">To enable authentication bypass for local network access:</p>
|
|
<p style="color: #aaa; font-size: 0.9em; margin-top: 5px;">
|
|
Go to <strong>Settings</strong> → <strong>General</strong> and toggle on <strong>Local Network Auth Bypass</strong>
|
|
</p>
|
|
</div>
|
|
<p><i class="fas fa-check-circle" style="color: #4CAF50;"></i> You can now proceed to the main interface.</p>
|
|
</div>
|
|
<div class="form-actions" style="justify-content: center;">
|
|
<button type="button" id="finishSetupButton" class="submit-button">
|
|
<i class="fas fa-home"></i> Go to Dashboard
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
// Elements
|
|
const steps = document.querySelectorAll('.step');
|
|
const screens = document.querySelectorAll('.setup-section');
|
|
const errorMessage = document.getElementById('errorMessage');
|
|
|
|
// Account setup elements
|
|
const usernameInput = document.getElementById('username');
|
|
const passwordInput = document.getElementById('password');
|
|
const confirmPasswordInput = document.getElementById('confirm_password');
|
|
const accountNextButton = document.getElementById('accountNextButton');
|
|
|
|
// 2FA setup elements
|
|
const qrCodeElement = document.getElementById('qrCode');
|
|
const secretKeyElement = document.getElementById('secretKey');
|
|
const verificationCodeInput = document.getElementById('verificationCode');
|
|
const skip2FALink = document.getElementById('skip2FALink');
|
|
const twoFactorNextButton = document.getElementById('twoFactorNextButton');
|
|
|
|
// Complete setup elements
|
|
const finishSetupButton = document.getElementById('finishSetupButton');
|
|
|
|
// Current step tracking
|
|
let currentStep = 1;
|
|
let accountCreated = false;
|
|
let twoFactorEnabled = false;
|
|
|
|
// Store user data
|
|
let userData = {
|
|
username: '',
|
|
password: ''
|
|
};
|
|
|
|
// Show a specific step
|
|
function showStep(step) {
|
|
steps.forEach((s, index) => {
|
|
if (index + 1 < step) {
|
|
s.classList.remove('active');
|
|
s.classList.add('completed');
|
|
} else if (index + 1 === step) {
|
|
s.classList.add('active');
|
|
s.classList.remove('completed');
|
|
} else {
|
|
s.classList.remove('active');
|
|
s.classList.remove('completed');
|
|
}
|
|
});
|
|
|
|
screens.forEach((screen, index) => {
|
|
if (index + 1 === step) {
|
|
screen.classList.add('active');
|
|
} else {
|
|
screen.classList.remove('active');
|
|
}
|
|
});
|
|
|
|
currentStep = step;
|
|
}
|
|
|
|
// Show error message
|
|
function showError(message) {
|
|
errorMessage.textContent = message;
|
|
errorMessage.style.display = 'block';
|
|
|
|
// Hide after 5 seconds
|
|
setTimeout(() => {
|
|
errorMessage.style.display = 'none';
|
|
}, 5000);
|
|
}
|
|
|
|
// Password validation function
|
|
function validatePassword(password) {
|
|
// Only check for minimum length of 8 characters
|
|
if (password.length < 8) {
|
|
return 'Password must be at least 8 characters long.';
|
|
}
|
|
return null; // Password is valid
|
|
}
|
|
|
|
// Account creation
|
|
accountNextButton.addEventListener('click', function() {
|
|
const username = usernameInput.value.trim(); // Trim whitespace
|
|
const password = passwordInput.value;
|
|
const confirmPassword = confirmPasswordInput.value;
|
|
|
|
if (!username || !password || !confirmPassword) {
|
|
showError('All fields are required');
|
|
return;
|
|
}
|
|
|
|
// Add username length validation
|
|
if (username.length < 3) {
|
|
showError('Username must be at least 3 characters long');
|
|
return;
|
|
}
|
|
|
|
if (password !== confirmPassword) {
|
|
showError('Passwords do not match');
|
|
return;
|
|
}
|
|
|
|
// Validate password complexity
|
|
const passwordError = validatePassword(password);
|
|
if (passwordError) {
|
|
showError(passwordError);
|
|
return;
|
|
}
|
|
|
|
// Store user data
|
|
userData.username = username;
|
|
userData.password = password;
|
|
|
|
if (accountCreated) {
|
|
// If account already created, just move to next step
|
|
showStep(2);
|
|
return;
|
|
}
|
|
|
|
// Create user account with improved error handling
|
|
fetch('/setup', { // Corrected endpoint from /api/setup to /setup
|
|
method: 'POST',
|
|
redirect: 'error', // Add this line to prevent following redirects
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({
|
|
username: username,
|
|
password: password,
|
|
confirm_password: confirmPassword // Keep confirm_password if backend expects it, otherwise remove
|
|
})
|
|
})
|
|
.then(response => {
|
|
// Check if response is ok before parsing JSON
|
|
if (!response.ok) {
|
|
// Check content type to see if it's likely JSON
|
|
const contentType = response.headers.get("content-type");
|
|
if (contentType && contentType.indexOf("application/json") !== -1) {
|
|
// If it seems like JSON, try to parse it for an error message
|
|
return response.json().then(data => {
|
|
// Use data.error first, then data.message as fallback
|
|
throw new Error(data.error || data.message || `Server error: ${response.status}`);
|
|
});
|
|
} else {
|
|
// If not JSON (e.g., HTML error page), throw a generic HTTP error
|
|
throw new Error(`HTTP error! status: ${response.status}`);
|
|
}
|
|
}
|
|
// If response is ok, parse the JSON body
|
|
return response.json();
|
|
})
|
|
.then(data => { // This block only runs if response.ok was true and response.json() succeeded
|
|
if (data.success) {
|
|
accountCreated = true;
|
|
console.log('Account created successfully. User credentials should be saved to credentials.json');
|
|
|
|
// Generate 2FA setup - Use the correct endpoint and method
|
|
fetch('/api/user/2fa/setup', { method: 'POST' }) // Specify POST method
|
|
.then(response => {
|
|
// Check for unauthorized specifically
|
|
if (response.status === 401) {
|
|
throw new Error('Unauthorized - Session likely not established yet.');
|
|
}
|
|
if (!response.ok) {
|
|
// Try to parse error from JSON response
|
|
return response.json().then(errData => {
|
|
throw new Error(errData.error || `Server error: ${response.status}`);
|
|
}).catch(() => {
|
|
// Fallback if response is not JSON
|
|
throw new Error(`Server error: ${response.status}`);
|
|
});
|
|
}
|
|
return response.json();
|
|
})
|
|
.then(twoFactorData => {
|
|
if (twoFactorData.success) {
|
|
// Use the correct property 'qr_code_url' and set the img src directly
|
|
const qrCodeImg = qrCodeElement.querySelector('img'); // Find the img tag within the div
|
|
if (qrCodeImg) {
|
|
qrCodeImg.src = twoFactorData.qr_code_url; // Set src directly
|
|
qrCodeImg.style.display = 'block'; // Ensure it's visible
|
|
} else {
|
|
// Fallback if img tag wasn't there initially
|
|
qrCodeElement.innerHTML = `<img src="${twoFactorData.qr_code_url}" alt="QR Code" style="display: block; max-width: 100%; height: auto;">`;
|
|
}
|
|
secretKeyElement.textContent = twoFactorData.secret;
|
|
showStep(2);
|
|
} else {
|
|
// Use .error if available, otherwise provide a default
|
|
showError('Failed to generate 2FA setup: ' + (twoFactorData.error || 'Unknown error'));
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('Error generating 2FA:', error);
|
|
// Display the specific error message caught
|
|
showError('Failed to generate 2FA setup: ' + error.message);
|
|
});
|
|
} else {
|
|
showError(data.error || 'Failed to create account'); // Use .error
|
|
}
|
|
})
|
|
.catch(error => { // Catches errors thrown from the .then blocks above or network errors
|
|
console.error('Setup error:', error);
|
|
showError('Error: ' + error.message); // Display the error message
|
|
});
|
|
});
|
|
|
|
// 2FA setup navigation
|
|
twoFactorNextButton.addEventListener('click', function() {
|
|
const code = verificationCodeInput.value;
|
|
if (!code || code.length !== 6 || !/^\d{6}$/.test(code)) { // Add validation
|
|
showError('Please enter a valid 6-digit verification code');
|
|
return;
|
|
}
|
|
|
|
// Verify 2FA code - Use the correct endpoint
|
|
fetch('/api/user/2fa/verify', { // Corrected endpoint
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({ code: code })
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
twoFactorEnabled = true;
|
|
showStep(3);
|
|
} else {
|
|
showError(data.message || 'Invalid verification code');
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('Error verifying 2FA code:', error);
|
|
showError('Failed to verify code');
|
|
});
|
|
});
|
|
|
|
// Skip 2FA setup
|
|
skip2FALink.addEventListener('click', function() {
|
|
showStep(3);
|
|
});
|
|
|
|
// Complete setup navigation
|
|
finishSetupButton.addEventListener('click', function() {
|
|
window.location.href = '/';
|
|
});
|
|
|
|
// Allow pressing Enter to continue
|
|
document.addEventListener('keydown', function(e) {
|
|
if (e.key === 'Enter') {
|
|
e.preventDefault(); // Prevent form submission
|
|
if (currentStep === 1 && document.activeElement !== accountNextButton) {
|
|
accountNextButton.click();
|
|
} else if (currentStep === 2 && document.activeElement !== twoFactorNextButton) {
|
|
twoFactorNextButton.click();
|
|
} else if (currentStep === 3 && document.activeElement !== finishSetupButton) {
|
|
finishSetupButton.click();
|
|
}
|
|
}
|
|
});
|
|
|
|
// Always use dark mode
|
|
document.body.classList.add('dark-mode');
|
|
localStorage.setItem('huntarr-dark-mode', 'true');
|
|
});
|
|
</script>
|
|
</body>
|
|
</html> |