Spaces:
No application file
No application file
| {% extends "admin/base.html" %} | |
| {% block title %}Управление пользователями{% endblock %} | |
| {% block content %} | |
| <div class="admin-header"> | |
| <h1><i class="fas fa-users"></i> Управление пользователями</h1> | |
| <div class="admin-actions"> | |
| <form class="search-form" method="get" action="{{ url_for('admin_bp.manage_users') }}"> | |
| <div class="input-group"> | |
| <input type="text" class="form-control" name="search" placeholder="Поиск..." | |
| value="{{ search_query }}"> | |
| <button class="btn btn-outline-secondary" type="submit"> | |
| <i class="fas fa-search"></i> | |
| </button> | |
| </div> | |
| </form> | |
| </div> | |
| </div> | |
| <div class="card"> | |
| <div class="card-body"> | |
| <div class="table-responsive"> | |
| <table class="table table-hover"> | |
| <thead> | |
| <tr> | |
| <th>ID</th> | |
| <th>Имя</th> | |
| <th>Email</th> | |
| <th>Дата регистрации</th> | |
| <th>Статус</th> | |
| <th>Действия</th> | |
| </tr> | |
| </thead> | |
| <tbody> | |
| {% for user in users.items %} | |
| <tr> | |
| <td>{{ user.id }}</td> | |
| <td>{{ user.username }}</td> | |
| <td>{{ user.email }}</td> | |
| <td>{{ user.created_at|datetimeformat }}</td> | |
| <td> | |
| {% if user.is_admin %} | |
| <span class="badge bg-danger">Админ</span> | |
| {% else %} | |
| <span class="badge bg-secondary">Пользователь</span> | |
| {% endif %} | |
| </td> | |
| <td> | |
| <div class="btn-group"> | |
| <button class="btn btn-sm btn-{{ 'danger' if user.is_admin else 'success' }} toggle-admin" | |
| data-user-id="{{ user.id }}"> | |
| {{ 'Убрать админа' if user.is_admin else 'Сделать админом' }} | |
| </button> | |
| {% if user.id != current_user.id %} | |
| <button class="btn btn-sm btn-outline-danger delete-user" | |
| data-user-id="{{ user.id }}"> | |
| <i class="fas fa-trash"></i> | |
| </button> | |
| {% endif %} | |
| </div> | |
| </td> | |
| </tr> | |
| {% endfor %} | |
| </tbody> | |
| </table> | |
| </div> | |
| <!-- Пагинация --> | |
| <nav aria-label="Page navigation"> | |
| <ul class="pagination justify-content-center"> | |
| {% if users.has_prev %} | |
| <li class="page-item"> | |
| <a class="page-link" href="{{ url_for('admin_bp.manage_users', page=users.prev_num, search=search_query) }}"> | |
| « | |
| </a> | |
| </li> | |
| {% endif %} | |
| {% for page_num in users.iter_pages(left_edge=1, right_edge=1, left_current=2, right_current=3) %} | |
| {% if page_num %} | |
| <li class="page-item {% if page_num == users.page %}active{% endif %}"> | |
| <a class="page-link" href="{{ url_for('admin_bp.manage_users', page=page_num, search=search_query) }}"> | |
| {{ page_num }} | |
| </a> | |
| </li> | |
| {% else %} | |
| <li class="page-item disabled"><span class="page-link">...</span></li> | |
| {% endif %} | |
| {% endfor %} | |
| {% if users.has_next %} | |
| <li class="page-item"> | |
| <a class="page-link" href="{{ url_for('admin_bp.manage_users', page=users.next_num, search=search_query) }}"> | |
| » | |
| </a> | |
| </li> | |
| {% endif %} | |
| </ul> | |
| </nav> | |
| </div> | |
| </div> | |
| {% endblock %} | |
| {% block scripts %} | |
| {{ super() }} | |
| <script> | |
| document.addEventListener('DOMContentLoaded', function() { | |
| // Функция для получения CSRF-токена из cookies | |
| function getCookie(name) { | |
| const cookieValue = document.cookie | |
| .split('; ') | |
| .find(row => row.startsWith(name + '=')) | |
| ?.split('=')[1]; | |
| return cookieValue ? decodeURIComponent(cookieValue) : null; | |
| } | |
| // Обработка переключения админа | |
| document.querySelectorAll('.toggle-admin').forEach(btn => { | |
| btn.addEventListener('click', function() { | |
| const userId = this.dataset.userId; | |
| fetch(`/admin/toggle_admin/${userId}`, { | |
| method: 'POST', | |
| headers: { | |
| 'Content-Type': 'application/json', | |
| 'X-CSRFToken': getCookie('csrf_token') | |
| } | |
| }) | |
| .then(response => response.json()) | |
| .then(data => { | |
| if (data.status === 'success') { | |
| location.reload(); | |
| } | |
| }); | |
| }); | |
| }); | |
| // Обработка удаления пользователя | |
| document.querySelectorAll('.delete-user').forEach(btn => { | |
| btn.addEventListener('click', function() { | |
| if (!confirm('Вы уверены, что хотите удалить этого пользователя?')) return; | |
| const userId = this.dataset.userId; | |
| fetch(`/admin/delete_user/${userId}`, { | |
| method: 'POST', | |
| headers: { | |
| 'Content-Type': 'application/json', | |
| 'X-CSRFToken': getCookie('csrf_token') | |
| } | |
| }) | |
| .then(response => response.json()) | |
| .then(data => { | |
| if (data.status === 'success') { | |
| location.reload(); | |
| } else { | |
| alert(data.message || 'Ошибка при удалении'); | |
| } | |
| }); | |
| }); | |
| }); | |
| }); | |
| </script> | |
| {% endblock %} |