more progress on TOTP/2FA

This commit is contained in:
2025-10-10 01:45:02 +01:00
parent b13cb5086a
commit 4a6c3bc49c
12 changed files with 189 additions and 197 deletions
+30 -38
View File
@@ -3,54 +3,46 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Discord Clone - Group Chat</title>
<title>Discord Clone - Sign Up</title>
<link rel="stylesheet" href="static/css/index.css"/>
</head>
<body>
<div class="chat-container">
<!--<div class="chat-container" style="background-image: url('cdn/background.png'); backdrop-filter: blur(10px); background-size: cover; background-position: center; background-repeat: no-repeat;">-->
<!-- Chat Header -->
<div class="chat-header">
<div class="chat-title">
<img class="user-avatar" src="cdn/profile/0"></img>
<h1>Chat title</h1>
</div>
<div class="signup-container">
<div class="signup-header">
<div class="logo">DC</div>
<h1>2FA Setup</h1>
</div>
<!-- Live Location Notification Bubble -->
<div class="notification-container">
<div class="live-location-bubble" id="locationBubble">
<div class="map-container">
<img src="cdn/map.png" alt="Map" />
</div>
<div class="location-content">
<div class="location-icon">
<img src="cdn/icons/location.svg" alt="Location"></img>
</div>
<button class="join-button" id="joinButton">
Join
</button>
<div class="location-text">Live Location</div>
<div class="location-users" id="locationUsers">
<!-- Users will be added dynamically -->
</div>
</div>
<div class="signup-form">
<div class="success-message" id="successMessage">
Login successful, Redirecting
</div>
</div>
<!-- Messages Container -->
<!--<div class="messages-container" style="background-image: url('cdn/background.png'); backdrop-filter: blur(10px); background-size: cover; background-position: center; background-repeat: no-repeat;">-->
<div class="messages-container"></div>
<img id="qr-code" alt="QR Code" style="width: 100%; height: auto; filter: brightness(0.925) invert(1);">
<!-- Input Container -->
<div class="input-container">
<div class="input-wrapper">
<input type="text" placeholder="Start Typing..." />
<button class="send-button">
<img src="cdn/icons/send.svg" alt="Send" />
</button>
<div class="form-group">
<input
type="text"
inputmode="numeric"
pattern="[0-9]*"
maxlength="6"
placeholder="000000"
style="font-size: 24px; letter-spacing: 0.5em; text-align: center; width: 100%;"
>
</div>
<button type="button" class="submit-button" id="submitButton">
Confirm!
</button>
</div>
</div>
<script>
fetch('/api/totp.jpg')
.then(response => response.json())
.then(data => {
document.getElementById('qr-code').src = data.qr_code;
});
</script>
</body>
</html>
+22 -77
View File
@@ -5,6 +5,9 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Discord Clone - Group Chat</title>
<link rel="stylesheet" href="static/css/index.css"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.1/styles/default.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.1/highlight.min.js"></script>
</head>
<body>
<div class="chat-container">
@@ -13,7 +16,7 @@
<div class="chat-header">
<div class="chat-title">
<img class="user-avatar" src="cdn/profile/0"></img>
<h1>Chat title</h1>
<h1>Wish.com Discord frfr</h1>
</div>
</div>
@@ -53,84 +56,26 @@
</div>
</div>
<script>
<script type="module">
import markdownit from 'https://cdn.jsdelivr.net/npm/markdown-it@14.1.0/+esm';
const md = markdownit({
html: true,
linkify: true,
typographer: true,
highlight: function (str, lang) {
if (lang && hljs.getLanguage(lang)) {
try {
return hljs.highlight(str, { language: lang }).value;
} catch (__) {}
}
return ''; // use external default escaping
}
})
const user_id = {{ user_id }};
var users = {};
// Location tracker state
const locationUsers = [
{ id: 1, color: "linear-gradient(135deg, #ff6b6b, #ff8e8e)" },
{ id: 2, color: "linear-gradient(135deg, #4ecdc4, #7fdbda)" },
{ id: 3, color: "linear-gradient(135deg, #45b7d1, #6cc5e0)" },
];
let hiddenUsersCount = 5; // Users not shown in the visible stack
let currentUserInLocation = false;
function updateLocationUsers() {
const container = document.getElementById("locationUsers");
container.innerHTML = "";
const maxVisible = 3;
const visibleUsers = locationUsers.slice(0, maxVisible);
visibleUsers.forEach((user) => {
const pic = document.createElement("div");
pic.className = "location-user-pic";
pic.style.background = user.color;
container.appendChild(pic);
});
// Calculate total hidden users (hidden users + current user if tracking)
const totalHidden =
hiddenUsersCount + (currentUserInLocation ? 1 : 0);
// Add count indicator if there are more users
if (totalHidden > 0) {
const count = document.createElement("div");
count.className = "location-count";
count.textContent = `+${totalHidden}`;
container.appendChild(count);
}
}
// Toggle location tracking
// const locationBubble = document.getElementById("locationBubble");
// const joinButton = document.getElementById("joinButton");
// let isExpanded = false;
// locationBubble.addEventListener("click", function (e) {
// // Don't toggle expanded state if clicking the join button
// if (e.target.id === "joinButton") return;
// isExpanded = !isExpanded;
// this.classList.toggle("expanded", isExpanded);
// });
// joinButton.addEventListener("click", function (e) {
// e.stopPropagation();
// currentUserInLocation = !currentUserInLocation;
// this.classList.toggle("active", currentUserInLocation);
// this.textContent = currentUserInLocation ? "Leave" : "Join";
// locationBubble.classList.toggle(
// "active",
// currentUserInLocation,
// );
// // Animate click
// this.style.transform = "scale(0.95)";
// setTimeout(() => {
// this.style.transform = "";
// }, 150);
// updateLocationUsers();
// });
// // Initialize location users
// updateLocationUsers();
// Handle message sending
const input = document.querySelector("input");
const sendButton = document.querySelector(".send-button");
@@ -154,7 +99,7 @@
<span class="username">${message.display_name}</span>
<span class="timestamp">${date}</span>
</div>
<div class="message-text">${message.text}</div>
<div class="message-text">${md.render(message.text)}</div>
</div>
`;
messagesContainer.appendChild(messageEl);
+2 -2
View File
@@ -126,8 +126,8 @@
// Optional: Redirect after success
setTimeout(() => {
// window.location.href = '/chat';
console.log("Redirecting to chat...");
window.location.href = '/chat';
// console.log("Redirecting to chat...");
}, 2000);
} else {
const error = await response.json();
+2 -2
View File
@@ -242,8 +242,8 @@
// Optional: Redirect after success
setTimeout(() => {
// window.location.href = '/chat';
console.log("Redirecting to chat...");
window.location.href = '/chat';
// console.log("Redirecting to chat...");
}, 2000);
} else {
const error = await response.json();