Добавлена кастомная страница ошибки CSRF и увеличено время сессии
- Создан шаблон templates/403_csrf.html с дружелюбным интерфейсом для пользователей * Красивый дизайн с градиентом и анимациями * Понятное объяснение причин ошибки (истёкшая сессия, кнопка Назад) * Кнопка обновления страницы для быстрого решения * Адаптивная вёрстка для мобильных устройств - Увеличено время жизни сессии в settings.py: * SESSION_COOKIE_AGE = 28 дней (было по умолчанию 2 недели) * SESSION_SAVE_EVERY_REQUEST = True (продлевать при активности) * CSRF_COOKIE_AGE = 1 год (чтобы токен не устаревал быстро) * Добавлены флаги безопасности SECURE для прода (HTTPS-only) Теперь на проде пользователи не увидят технический текст ошибки CSRF, а получат понятное сообщение с инструкцией по решению проблемы.
This commit is contained in:
137
myproject/templates/403_csrf.html
Normal file
137
myproject/templates/403_csrf.html
Normal file
@@ -0,0 +1,137 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Сессия истекла</title>
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, 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: 12px;
|
||||
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
|
||||
max-width: 500px;
|
||||
width: 100%;
|
||||
padding: 40px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.icon {
|
||||
font-size: 64px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
color: #333;
|
||||
font-size: 28px;
|
||||
margin-bottom: 16px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
p {
|
||||
color: #666;
|
||||
font-size: 16px;
|
||||
line-height: 1.6;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.reason {
|
||||
background: #f8f9fa;
|
||||
border-left: 4px solid #ffc107;
|
||||
padding: 16px;
|
||||
margin: 24px 0;
|
||||
text-align: left;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.reason strong {
|
||||
color: #333;
|
||||
display: block;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.reason ul {
|
||||
margin-left: 20px;
|
||||
color: #555;
|
||||
}
|
||||
|
||||
.reason li {
|
||||
margin: 6px 0;
|
||||
}
|
||||
|
||||
.btn {
|
||||
display: inline-block;
|
||||
background: #667eea;
|
||||
color: white;
|
||||
padding: 14px 32px;
|
||||
border-radius: 6px;
|
||||
text-decoration: none;
|
||||
font-weight: 500;
|
||||
font-size: 16px;
|
||||
transition: all 0.3s ease;
|
||||
cursor: pointer;
|
||||
border: none;
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.btn:hover {
|
||||
background: #5568d3;
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
|
||||
}
|
||||
|
||||
.btn:active {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
.container {
|
||||
padding: 30px 20px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.icon {
|
||||
font-size: 48px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="icon">🔒</div>
|
||||
<h1>Сессия истекла</h1>
|
||||
<p>Ваша форма была открыта слишком давно, и защитный токен безопасности устарел.</p>
|
||||
|
||||
<div class="reason">
|
||||
<strong>Возможные причины:</strong>
|
||||
<ul>
|
||||
<li>Страница была открыта более 30 минут</li>
|
||||
<li>Использована кнопка "Назад" в браузере</li>
|
||||
<li>Открыто несколько вкладок с этой формой</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<p><strong>Решение простое:</strong> обновите страницу и попробуйте снова.</p>
|
||||
|
||||
<button class="btn" onclick="location.reload()">🔄 Обновить страницу</button>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user