* Add email OTP authentication system and private room management ## Authentication System - Implement email OTP-based authentication with User and OTPToken models - Add auth.py module with OTP generation, email sending, and session management - Create authentication endpoints: /auth/send-otp, /auth/verify-otp, /auth/claim-name, /auth/status, /auth/logout - Add authentication modal UI with email verification and display name claiming - Support SMTP configuration via environment variables (optional) ## Room Privacy & Ownership - Add is_private, is_archived, owner_id, and forked_from_id fields to Room model - Implement private rooms (single-user, owner-only access) - Add room forking: users can fork public rooms to public or private - Add room archive/delete endpoints (owner-only operations) - Implement access control for private room viewing ## UI Improvements - Add public/private room tabs in sidebar - Show authentication prompt in private rooms tab for non-authenticated users - Add room action buttons (fork, archive, delete) with proper permissions - Update homepage with statistics (public/private rooms, active users, active rooms) - Remove model/voice from URL query strings, use localStorage exclusively ## Database Migration - Create migration 2025011100 for User, OTPToken tables and Room model updates - Add indexes for email, display_name, is_private, is_archived, owner_id ## Breaking Changes - URL parameters now only include username (model/voice moved to localStorage) - Private rooms require authentication to access - Room creation can now require authentication (for private rooms) * Update README with authentication and private room documentation * Simplify README to be less verbose * Add missing session import to fix linter errors * Fix migration dependency to resolve multiple heads conflict * asdf * Fix SQLAlchemy auto-correlation error in homepage statistics query * Change tagline from AI-Powered to Machine Learning Powered * Add dedicated authentication page instead of modal - Create new /auth route with full-page authentication flow - Remove modal code from index.html - Update Sign in link to point to /auth page - Auth page has 4-step flow: email, OTP, display name, success - Better UX with gradient background and cleaner design * Fix migration: remove batch_alter_table to avoid circular dependency - Use op.add_column() directly instead of batch_alter_table() - Remove foreign key constraints (defined in models, not needed in migration) - User and OTPToken tables created by db.create_all() in make init-db - Fixes CircularDependencyError during migration * Fix migration: check if columns exist before adding - Use inspector to check existing columns and indexes - Only add columns/indexes if they don't already exist - Handles case where db.create_all() was run before migration - Fixes 'duplicate column name' error * Add profile page, room browsing, and updated_at timestamp Features: - Profile page with username change and dark/light mode settings - Browse page for discovering public and private rooms - Room updated_at timestamp (integer Unix epoch) that updates on new messages - Dynamic room tabs based on current room type (public/private) - Fork and delete room actions moved to right sidebar utility belt - Remove archive feature and success alerts from room actions Technical changes: - Add updated_at column to Room model (integer timestamp) - Add /profile route with authentication requirement - Add /browse route for room discovery - Add API endpoints for username availability check and update - Update room.updated_at on message creation in app.py:1189 - Wider right sidebar (25% instead of 15%) for better button layout - Profile link on homepage and browse page for authenticated users --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: russell@unturf. <russell@unturf.com>
290 lines
9.6 KiB
HTML
290 lines
9.6 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Sign In - OpenCompletion</title>
|
|
<link rel="icon" href="{{ url_for('static', filename='favicon.ico') }}">
|
|
<style>
|
|
body {
|
|
font-family: Arial, sans-serif;
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
display: flex;
|
|
flex-direction: column;
|
|
justify-content: center;
|
|
align-items: center;
|
|
min-height: 100vh;
|
|
margin: 0;
|
|
padding: 20px;
|
|
}
|
|
.auth-container {
|
|
background-color: #ffffff;
|
|
border-radius: 10px;
|
|
padding: 40px;
|
|
width: 100%;
|
|
max-width: 450px;
|
|
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
|
|
}
|
|
.logo {
|
|
text-align: center;
|
|
margin-bottom: 30px;
|
|
}
|
|
.logo h1 {
|
|
color: #667eea;
|
|
margin: 0;
|
|
font-size: 32px;
|
|
}
|
|
.logo p {
|
|
color: #666;
|
|
margin: 5px 0 0 0;
|
|
font-size: 14px;
|
|
}
|
|
.auth-step {
|
|
display: none;
|
|
}
|
|
.auth-step.active {
|
|
display: block;
|
|
}
|
|
.auth-step h2 {
|
|
margin-top: 0;
|
|
color: #333;
|
|
text-align: center;
|
|
}
|
|
.auth-step p {
|
|
color: #666;
|
|
text-align: center;
|
|
margin-bottom: 25px;
|
|
}
|
|
.auth-step input {
|
|
width: 100%;
|
|
padding: 14px;
|
|
margin-bottom: 15px;
|
|
border: 2px solid #e1e1e1;
|
|
border-radius: 5px;
|
|
font-size: 16px;
|
|
box-sizing: border-box;
|
|
}
|
|
.auth-step input:focus {
|
|
outline: none;
|
|
border-color: #667eea;
|
|
}
|
|
.auth-step button {
|
|
width: 100%;
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
color: white;
|
|
border: none;
|
|
border-radius: 5px;
|
|
padding: 14px;
|
|
font-size: 16px;
|
|
cursor: pointer;
|
|
transition: transform 0.2s;
|
|
margin-bottom: 10px;
|
|
}
|
|
.auth-step button:hover {
|
|
transform: translateY(-2px);
|
|
}
|
|
.auth-step button.secondary-btn {
|
|
background: #6c757d;
|
|
}
|
|
.error-message {
|
|
color: #dc3545;
|
|
font-size: 14px;
|
|
margin-top: -10px;
|
|
margin-bottom: 15px;
|
|
text-align: center;
|
|
}
|
|
.back-link {
|
|
text-align: center;
|
|
margin-top: 20px;
|
|
}
|
|
.back-link a {
|
|
color: #667eea;
|
|
text-decoration: none;
|
|
font-weight: bold;
|
|
}
|
|
.back-link a:hover {
|
|
text-decoration: underline;
|
|
}
|
|
.success-icon {
|
|
text-align: center;
|
|
font-size: 64px;
|
|
margin-bottom: 20px;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="auth-container">
|
|
<div class="logo">
|
|
<h1>🚀 OpenCompletion</h1>
|
|
<p>Machine Learning Powered Collaboration</p>
|
|
</div>
|
|
|
|
<!-- Step 1: Enter email -->
|
|
<div id="auth-step-email" class="auth-step active">
|
|
<h2>Sign In / Sign Up</h2>
|
|
<p>Enter your email to receive a verification code</p>
|
|
<input type="email" id="auth-email" placeholder="your@email.com" />
|
|
<button onclick="sendOTP()">Send Code</button>
|
|
<div id="auth-email-error" class="error-message"></div>
|
|
</div>
|
|
|
|
<!-- Step 2: Enter OTP -->
|
|
<div id="auth-step-otp" class="auth-step">
|
|
<h2>Enter Verification Code</h2>
|
|
<p>We sent a 6-digit code to <strong><span id="auth-email-display"></span></strong></p>
|
|
<input type="text" id="auth-otp" placeholder="123456" maxlength="6" />
|
|
<button onclick="verifyOTP()">Verify</button>
|
|
<button class="secondary-btn" onclick="backToEmailStep()">Back</button>
|
|
<div id="auth-otp-error" class="error-message"></div>
|
|
</div>
|
|
|
|
<!-- Step 3: Claim display name (new users only) -->
|
|
<div id="auth-step-name" class="auth-step">
|
|
<h2>Choose Display Name</h2>
|
|
<p>Pick a unique display name (3-50 characters)</p>
|
|
<input type="text" id="auth-display-name" placeholder="username" maxlength="50" />
|
|
<button onclick="claimName()">Complete Sign Up</button>
|
|
<div id="auth-name-error" class="error-message"></div>
|
|
</div>
|
|
|
|
<!-- Success -->
|
|
<div id="auth-step-success" class="auth-step">
|
|
<div class="success-icon">✅</div>
|
|
<h2>Success!</h2>
|
|
<p>Welcome, <strong><span id="auth-success-name"></span></strong>!</p>
|
|
<button onclick="redirectToChatRooms()">Go to Chat Rooms</button>
|
|
</div>
|
|
|
|
<div class="back-link">
|
|
<a href="/">← Back to Home</a>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
let pendingEmail = '';
|
|
|
|
function showAuthStep(step) {
|
|
document.querySelectorAll('.auth-step').forEach(el => el.classList.remove('active'));
|
|
document.getElementById('auth-step-' + step).classList.add('active');
|
|
clearAuthErrors();
|
|
}
|
|
|
|
function clearAuthErrors() {
|
|
document.querySelectorAll('.error-message').forEach(el => el.textContent = '');
|
|
}
|
|
|
|
function backToEmailStep() {
|
|
showAuthStep('email');
|
|
}
|
|
|
|
function redirectToChatRooms() {
|
|
window.location.href = '/chat/general';
|
|
}
|
|
|
|
async function sendOTP() {
|
|
const email = document.getElementById('auth-email').value.trim();
|
|
const errorEl = document.getElementById('auth-email-error');
|
|
|
|
if (!email) {
|
|
errorEl.textContent = 'Please enter your email';
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const response = await fetch('/auth/send-otp', {
|
|
method: 'POST',
|
|
headers: {'Content-Type': 'application/json'},
|
|
body: JSON.stringify({email})
|
|
});
|
|
|
|
const data = await response.json();
|
|
|
|
if (response.ok) {
|
|
pendingEmail = email;
|
|
document.getElementById('auth-email-display').textContent = email;
|
|
showAuthStep('otp');
|
|
} else {
|
|
errorEl.textContent = data.error || 'Failed to send code';
|
|
}
|
|
} catch (error) {
|
|
errorEl.textContent = 'Network error. Please try again.';
|
|
}
|
|
}
|
|
|
|
async function verifyOTP() {
|
|
const otpCode = document.getElementById('auth-otp').value.trim();
|
|
const errorEl = document.getElementById('auth-otp-error');
|
|
|
|
if (!otpCode) {
|
|
errorEl.textContent = 'Please enter the code';
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const response = await fetch('/auth/verify-otp', {
|
|
method: 'POST',
|
|
headers: {'Content-Type': 'application/json'},
|
|
body: JSON.stringify({email: pendingEmail, otp_code: otpCode})
|
|
});
|
|
|
|
const data = await response.json();
|
|
|
|
if (response.ok) {
|
|
if (data.needs_display_name) {
|
|
showAuthStep('name');
|
|
} else {
|
|
document.getElementById('auth-success-name').textContent = data.user.display_name;
|
|
showAuthStep('success');
|
|
}
|
|
} else {
|
|
errorEl.textContent = data.error || 'Invalid code';
|
|
}
|
|
} catch (error) {
|
|
errorEl.textContent = 'Network error. Please try again.';
|
|
}
|
|
}
|
|
|
|
async function claimName() {
|
|
const displayName = document.getElementById('auth-display-name').value.trim();
|
|
const errorEl = document.getElementById('auth-name-error');
|
|
|
|
if (!displayName) {
|
|
errorEl.textContent = 'Please enter a display name';
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const response = await fetch('/auth/claim-name', {
|
|
method: 'POST',
|
|
headers: {'Content-Type': 'application/json'},
|
|
body: JSON.stringify({display_name: displayName})
|
|
});
|
|
|
|
const data = await response.json();
|
|
|
|
if (response.ok) {
|
|
document.getElementById('auth-success-name').textContent = data.user.display_name;
|
|
showAuthStep('success');
|
|
} else {
|
|
errorEl.textContent = data.error || 'Failed to claim name';
|
|
}
|
|
} catch (error) {
|
|
errorEl.textContent = 'Network error. Please try again.';
|
|
}
|
|
}
|
|
|
|
// Allow Enter key to submit on each step
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
document.getElementById('auth-email').addEventListener('keypress', function(e) {
|
|
if (e.key === 'Enter') sendOTP();
|
|
});
|
|
document.getElementById('auth-otp').addEventListener('keypress', function(e) {
|
|
if (e.key === 'Enter') verifyOTP();
|
|
});
|
|
document.getElementById('auth-display-name').addEventListener('keypress', function(e) {
|
|
if (e.key === 'Enter') claimName();
|
|
});
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|