You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

402 lines
12 KiB

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Swagger Authentication - Imam Javad API</title>
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
<style>
:root {
--primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
--success-color: #28a745;
--warning-color: #f39c12;
--danger-color: #e74c3c;
--info-color: #17a2b8;
}
body {
background: var(--primary-gradient);
min-height: 100vh;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
.auth-container {
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
padding: 20px;
}
.auth-card {
background: white;
border-radius: 16px;
box-shadow: 0 20px 60px rgba(0,0,0,0.1);
overflow: hidden;
max-width: 500px;
width: 100%;
}
.auth-header {
background: var(--primary-gradient);
color: white;
padding: 30px;
text-align: center;
}
.auth-header h1 {
margin: 0 0 10px 0;
font-size: 1.8rem;
font-weight: 600;
}
.auth-header p {
margin: 0;
opacity: 0.9;
font-size: 0.95rem;
}
.auth-body {
padding: 30px;
}
.form-group {
margin-bottom: 20px;
}
.form-label {
font-weight: 600;
color: #2c3e50;
margin-bottom: 8px;
display: block;
}
.form-control {
border: 2px solid #e9ecef;
border-radius: 8px;
padding: 12px 16px;
font-size: 0.95rem;
transition: all 0.3s ease;
}
.form-control:focus {
border-color: #667eea;
box-shadow: 0 0 0 0.2rem rgba(102, 126, 234, 0.25);
}
.btn-auth {
background: var(--primary-gradient);
border: none;
color: white;
padding: 12px 24px;
border-radius: 8px;
font-weight: 600;
font-size: 0.95rem;
width: 100%;
transition: all 0.3s ease;
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
}
.btn-auth:hover {
background: linear-gradient(135deg, #5a6fd8 0%, #6a4190 100%);
color: white;
transform: translateY(-1px);
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}
.btn-secondary {
background: #6c757d;
border: none;
color: white;
padding: 10px 20px;
border-radius: 6px;
font-weight: 500;
text-decoration: none;
display: inline-flex;
align-items: center;
gap: 6px;
transition: all 0.3s ease;
}
.btn-secondary:hover {
background: #5a6268;
color: white;
text-decoration: none;
}
.user-info-card {
background: #f8f9fa;
border-radius: 8px;
padding: 20px;
margin-bottom: 20px;
}
.user-info-header {
display: flex;
align-items: center;
gap: 12px;
margin-bottom: 15px;
}
.user-avatar {
width: 48px;
height: 48px;
border-radius: 50%;
background: var(--primary-gradient);
color: white;
display: flex;
align-items: center;
justify-content: center;
font-weight: bold;
font-size: 1.2rem;
}
.user-details h4 {
margin: 0;
color: #2c3e50;
font-size: 1.1rem;
}
.user-details p {
margin: 0;
color: #6c757d;
font-size: 0.9rem;
}
.user-badges {
display: flex;
gap: 8px;
flex-wrap: wrap;
}
.badge {
padding: 4px 8px;
border-radius: 4px;
font-size: 0.75rem;
font-weight: 500;
}
.badge-staff {
background: var(--info-color);
color: white;
}
.badge-superuser {
background: var(--warning-color);
color: white;
}
.help-section {
background: #e3f2fd;
border-radius: 8px;
padding: 20px;
margin-top: 20px;
}
.help-section h5 {
color: #1976d2;
margin-bottom: 10px;
display: flex;
align-items: center;
gap: 8px;
}
.help-section p {
margin: 0;
color: #1565c0;
font-size: 0.9rem;
line-height: 1.5;
}
.navigation-links {
display: flex;
gap: 10px;
justify-content: center;
margin-top: 20px;
flex-wrap: wrap;
}
.alert {
border-radius: 8px;
border: none;
padding: 12px 16px;
margin-bottom: 20px;
}
.alert-success {
background: #d4edda;
color: #155724;
}
.alert-danger {
background: #f8d7da;
color: #721c24;
}
.alert-warning {
background: #fff3cd;
color: #856404;
}
@media (max-width: 576px) {
.auth-container {
padding: 10px;
}
.auth-header {
padding: 20px;
}
.auth-body {
padding: 20px;
}
.navigation-links {
flex-direction: column;
}
.btn-secondary {
width: 100%;
justify-content: center;
}
}
</style>
</head>
<body>
<div class="auth-container">
<div class="auth-card">
<div class="auth-header">
<h1><i class="fas fa-key"></i> API Authentication</h1>
<p>Enter your API token to access Swagger UI</p>
</div>
<div class="auth-body">
<!-- Display Messages -->
{% if messages %}
{% for message in messages %}
<div class="alert alert-{{ message.tags }}">
{{ message }}
</div>
{% endfor %}
{% endif %}
<!-- Current User Info (if authenticated) -->
{% if user_info %}
<div class="user-info-card">
<div class="user-info-header">
<div class="user-avatar">
{{ user_info.fullname|first|upper }}
</div>
<div class="user-details">
<h4>{{ user_info.fullname }}</h4>
<p>{{ user_info.email }}</p>
</div>
</div>
<div class="user-badges">
{% if user_info.is_staff %}
<span class="badge badge-staff">Staff</span>
{% endif %}
{% if user_info.is_superuser %}
<span class="badge badge-superuser">Superuser</span>
{% endif %}
<span class="badge bg-success text-white">Authenticated</span>
</div>
</div>
{% endif %}
<!-- Token Authentication Form -->
<form method="post">
{% csrf_token %}
<div class="form-group">
<label for="token" class="form-label">
<i class="fas fa-key"></i> API Token
</label>
<input
type="text"
class="form-control"
id="token"
name="token"
placeholder="Enter your 40-character API token"
value="{{ current_token|default:'' }}"
maxlength="40"
required
>
<small class="form-text text-muted">
Token must be exactly 40 characters long
</small>
</div>
<button type="submit" class="btn-auth">
<i class="fas fa-sign-in-alt"></i>
Authenticate
</button>
</form>
<!-- Help Section -->
<div class="help-section">
<h5>
<i class="fas fa-question-circle"></i>
How to get your API token?
</h5>
<p>
Your API token can be found in your user profile or generated through the Django admin panel.
Contact your system administrator if you need assistance obtaining your token.
</p>
</div>
<!-- Navigation Links -->
<div class="navigation-links">
<a href="{% url 'docs-index' %}" class="btn-secondary">
<i class="fas fa-book"></i>
Documentation
</a>
{% if current_token %}
<a href="{% url 'schema-swagger-ui' %}" class="btn-secondary">
<i class="fas fa-code"></i>
Swagger UI
</a>
<a href="{% url 'clear-swagger-auth' %}" class="btn-secondary">
<i class="fas fa-sign-out-alt"></i>
Clear Token
</a>
{% endif %}
</div>
</div>
</div>
</div>
<!-- Bootstrap JavaScript -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
// Auto-focus on token input
document.addEventListener('DOMContentLoaded', function() {
const tokenInput = document.getElementById('token');
if (tokenInput && !tokenInput.value) {
tokenInput.focus();
}
});
// Token validation
document.getElementById('token').addEventListener('input', function(e) {
const token = e.target.value;
const submitBtn = document.querySelector('.btn-auth');
if (token.length === 40) {
submitBtn.style.background = 'linear-gradient(135deg, #28a745 0%, #20c997 100%)';
submitBtn.innerHTML = '<i class="fas fa-check"></i> Ready to Authenticate';
} else {
submitBtn.style.background = 'var(--primary-gradient)';
submitBtn.innerHTML = '<i class="fas fa-sign-in-alt"></i> Authenticate';
}
});
</script>
</body>
</html>