first commit
This commit is contained in:
168
templates/spa_test/activate.html
Normal file
168
templates/spa_test/activate.html
Normal file
@@ -0,0 +1,168 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Activating Account...</title>
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.container {
|
||||
background: white;
|
||||
border-radius: 20px;
|
||||
box-shadow: 0 20px 60px rgba(0,0,0,0.3);
|
||||
padding: 3rem;
|
||||
max-width: 500px;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.spinner {
|
||||
border: 4px solid #f3f3f3;
|
||||
border-top: 4px solid #667eea;
|
||||
border-radius: 50%;
|
||||
width: 60px;
|
||||
height: 60px;
|
||||
animation: spin 1s linear infinite;
|
||||
margin: 0 auto 2rem;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
0% { transform: rotate(0deg); }
|
||||
100% { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
.success {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.success-icon {
|
||||
font-size: 64px;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.error {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.error-icon {
|
||||
font-size: 64px;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
h1 {
|
||||
color: #333;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
p {
|
||||
color: #666;
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.btn {
|
||||
display: inline-block;
|
||||
padding: 1rem 2rem;
|
||||
background: #667eea;
|
||||
color: white;
|
||||
text-decoration: none;
|
||||
border-radius: 8px;
|
||||
font-weight: 600;
|
||||
transition: background 0.3s;
|
||||
}
|
||||
|
||||
.btn:hover {
|
||||
background: #5568d3;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div id="loading">
|
||||
<div class="spinner"></div>
|
||||
<h1>Activating Your Account...</h1>
|
||||
<p>Please wait while we activate your account.</p>
|
||||
</div>
|
||||
|
||||
<div id="success" class="success">
|
||||
<div class="success-icon">✅</div>
|
||||
<h1>Account Activated!</h1>
|
||||
<p>Your account has been successfully activated. You can now log in.</p>
|
||||
<a href="/api/v1/spa/" class="btn">Go to Login</a>
|
||||
</div>
|
||||
|
||||
<div id="error" class="error">
|
||||
<div class="error-icon">❌</div>
|
||||
<h1>Activation Failed</h1>
|
||||
<p id="errorMessage">The activation link is invalid or has expired.</p>
|
||||
<a href="/api/v1/spa/" class="btn">Back to Login</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Get uid and token from Django template context
|
||||
const finalUid = '{{ uid }}';
|
||||
const finalToken = '{{ token }}';
|
||||
|
||||
console.log('Activating with:', { uid: finalUid, token: finalToken });
|
||||
|
||||
// Activate account
|
||||
async function activateAccount() {
|
||||
try {
|
||||
const response = await fetch('http://localhost:8000/api/v1/auth/users/activation/', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
uid: finalUid,
|
||||
token: finalToken
|
||||
})
|
||||
});
|
||||
|
||||
document.getElementById('loading').style.display = 'none';
|
||||
|
||||
if (response.ok || response.status === 204) {
|
||||
document.getElementById('success').style.display = 'block';
|
||||
} else {
|
||||
const data = await response.json().catch(() => ({}));
|
||||
document.getElementById('error').style.display = 'block';
|
||||
if (data.detail || data.token || data.uid) {
|
||||
document.getElementById('errorMessage').textContent =
|
||||
data.detail || data.token?.[0] || data.uid?.[0] || 'Activation failed.';
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Activation error:', error);
|
||||
document.getElementById('loading').style.display = 'none';
|
||||
document.getElementById('error').style.display = 'block';
|
||||
document.getElementById('errorMessage').textContent = 'Network error. Please try again.';
|
||||
}
|
||||
}
|
||||
|
||||
// Start activation
|
||||
if (finalUid && finalToken) {
|
||||
activateAccount();
|
||||
} else {
|
||||
document.getElementById('loading').style.display = 'none';
|
||||
document.getElementById('error').style.display = 'block';
|
||||
document.getElementById('errorMessage').textContent = 'Missing activation parameters.';
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
205
templates/spa_test/index.html
Normal file
205
templates/spa_test/index.html
Normal file
@@ -0,0 +1,205 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Django Auth - SPA Test (Token-Based)</title>
|
||||
<link rel="stylesheet" href="/static/spa-test.css">
|
||||
<!-- Google OAuth2 -->
|
||||
<script src="https://accounts.google.com/gsi/client" async defer></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app">
|
||||
<!-- Navigation -->
|
||||
<nav class="navbar" id="navbar" style="display: none;">
|
||||
<div class="nav-container">
|
||||
<div class="nav-brand">🔐 Django Auth</div>
|
||||
<div class="nav-menu">
|
||||
<span id="userEmail" class="user-email"></span>
|
||||
<button onclick="logout()" class="btn-logout">Logout</button>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<!-- Login Page -->
|
||||
<div id="loginPage" class="page">
|
||||
<div class="container">
|
||||
<div class="card">
|
||||
<h1>Welcome Back! 👋</h1>
|
||||
<p class="subtitle">Sign in to continue</p>
|
||||
|
||||
<!-- Email/Password Login -->
|
||||
<form id="loginForm" onsubmit="handleLogin(event)">
|
||||
<div class="form-group">
|
||||
<label>Email</label>
|
||||
<input type="email" id="email" placeholder="your@email.com" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Password</label>
|
||||
<input type="password" id="password" placeholder="••••••••" required>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">
|
||||
Sign In
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<div class="divider">OR</div>
|
||||
|
||||
<!-- Social Login (Token-Based) -->
|
||||
<div class="social-buttons">
|
||||
<button onclick="loginWithGoogle()" class="btn btn-google">
|
||||
🔵 Continue with Google
|
||||
</button>
|
||||
<button onclick="loginWithGitHub()" class="btn btn-github">
|
||||
⚫ Continue with GitHub
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<p class="footer-text">
|
||||
Don't have an account? <a href="#" onclick="showRegister()">Sign up</a>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div id="errorAlert" class="alert alert-error" style="display: none;"></div>
|
||||
<div class="info-box">
|
||||
<strong>ℹ️ Token-Based Flow:</strong>
|
||||
<p>Bu sayfa Nuxt/Next.js gibi çalışır:</p>
|
||||
<ol>
|
||||
<li>Frontend'de Google/GitHub OAuth</li>
|
||||
<li>Access token alınır</li>
|
||||
<li>Token Django'ya POST edilir</li>
|
||||
<li>Django JWT token döner</li>
|
||||
<li>JWT localStorage'a kaydedilir</li>
|
||||
</ol>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Register Page -->
|
||||
<div id="registerPage" class="page" style="display: none;">
|
||||
<div class="container">
|
||||
<div class="card">
|
||||
<h1>Create Account 🎉</h1>
|
||||
<p class="subtitle">Join us today</p>
|
||||
|
||||
<form id="registerForm" onsubmit="handleRegister(event)">
|
||||
<div class="form-group">
|
||||
<label>Email</label>
|
||||
<input type="email" id="regEmail" placeholder="your@email.com" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>First Name</label>
|
||||
<input type="text" id="firstName" placeholder="John" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Last Name</label>
|
||||
<input type="text" id="lastName" placeholder="Doe" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Password</label>
|
||||
<input type="password" id="regPassword" placeholder="••••••••" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Confirm Password</label>
|
||||
<input type="password" id="regPasswordConfirm" placeholder="••••••••" required>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">
|
||||
Create Account
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<p class="footer-text">
|
||||
Already have an account? <a href="#" onclick="showLogin()">Sign in</a>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div id="registerSuccess" class="alert alert-success" style="display: none;">
|
||||
✅ Account created! Please check your email to activate your account.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Dashboard Page -->
|
||||
<div id="dashboardPage" class="page" style="display: none;">
|
||||
<div class="container">
|
||||
<div class="card">
|
||||
<h1>Dashboard 🎯</h1>
|
||||
<p class="subtitle">Welcome to your account</p>
|
||||
|
||||
<div class="profile-section">
|
||||
<div class="profile-avatar">👤</div>
|
||||
<div class="profile-info">
|
||||
<h2 id="profileName">Loading...</h2>
|
||||
<p id="profileEmail" class="text-muted">Loading...</p>
|
||||
<span id="profileStatus" class="badge"></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="stats-grid">
|
||||
<div class="stat-card">
|
||||
<div class="stat-icon">📧</div>
|
||||
<div class="stat-info">
|
||||
<h3 id="userEmailStat">-</h3>
|
||||
<p>Email Address</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-icon">🔑</div>
|
||||
<div class="stat-info">
|
||||
<h3>JWT</h3>
|
||||
<p>Authentication</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-icon">📅</div>
|
||||
<div class="stat-info">
|
||||
<h3 id="joinedDate">-</h3>
|
||||
<p>Member Since</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="token-section">
|
||||
<h3>Your JWT Tokens 🔐</h3>
|
||||
<div class="token-box">
|
||||
<label>Access Token (from Django)</label>
|
||||
<textarea id="accessToken" readonly></textarea>
|
||||
<button onclick="copyToken('access')" class="btn btn-small">Copy</button>
|
||||
</div>
|
||||
<div class="token-box">
|
||||
<label>Refresh Token (from Django)</label>
|
||||
<textarea id="refreshToken" readonly></textarea>
|
||||
<button onclick="copyToken('refresh')" class="btn btn-small">Copy</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button onclick="testProtectedEndpoint()" class="btn btn-primary">
|
||||
🧪 Test Protected Endpoint
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Loading Overlay -->
|
||||
<div id="loadingOverlay" class="loading-overlay" style="display: none;">
|
||||
<div class="spinner"></div>
|
||||
<p>Loading...</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="/static/spa-test.js"></script>
|
||||
|
||||
<!-- Google OAuth Initialization -->
|
||||
<script>
|
||||
window.onload = function() {
|
||||
// Initialize Google OAuth
|
||||
if (typeof google !== 'undefined') {
|
||||
google.accounts.id.initialize({
|
||||
client_id: '915364976256-691m0s87as2r5vdbqr96f6humblseobt.apps.googleusercontent.com',
|
||||
callback: handleGoogleCallback
|
||||
});
|
||||
}
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user