fix: Correções na página de administração e suas dependências
This commit is contained in:
@@ -1,63 +1,75 @@
|
||||
{% extends 'base.html' %}
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Dashboard Administrativo{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="container">
|
||||
<h1 class="mb-4">Dashboard Administrativo</h1>
|
||||
|
||||
{% with messages = get_flashed_messages(with_categories=true) %}
|
||||
{% if messages %}
|
||||
{% for category, message in messages %}
|
||||
<div class="alert alert-{{ category }}">{{ message }}</div>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
|
||||
<div class="card mb-4">
|
||||
<div class="card-header">
|
||||
<h5 class="card-title mb-0">Gerenciamento de Usuários</h5>
|
||||
<div class="container mt-4">
|
||||
<div class="card">
|
||||
<div class="card-header bg-dark text-white">
|
||||
<h3 class="mb-0"><i class="fas fa-users-cog"></i> Administração de Usuários</h3>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="alert alert-info" role="alert">
|
||||
<i class="fas fa-info-circle"></i> Aqui você pode gerenciar todos os usuários do sistema. Use os controles abaixo para ativar/desativar contas ou alterar níveis de acesso.
|
||||
</div>
|
||||
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<table class="table table-hover">
|
||||
<thead class="thead-light">
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Usuário</th>
|
||||
<th>Email</th>
|
||||
<th>Admin</th>
|
||||
<th>OTP Configurado</th>
|
||||
<th>Nome</th>
|
||||
<th>Último Acesso</th>
|
||||
<th>Status</th>
|
||||
<th>Nível</th>
|
||||
<th>Ações</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for usuario in usuarios %}
|
||||
<tr>
|
||||
<td>{{ usuario.id }}</td>
|
||||
<td>{{ usuario.username }}</td>
|
||||
<td>{{ usuario.email }}</td>
|
||||
<td>{{ usuario.nome }}</td>
|
||||
<td>{{ usuario.last_login }}</td>
|
||||
<td>
|
||||
<span class="badge {% if usuario.ativo %}badge-success{% else %}badge-danger{% endif %}">
|
||||
{{ "Ativo" if usuario.ativo else "Inativo" }}
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
{% if usuario.is_admin %}
|
||||
<span class="badge bg-success">Sim</span>
|
||||
Administrador
|
||||
{% else %}
|
||||
<span class="badge bg-secondary">Não</span>
|
||||
{{ usuario.nivel }}
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{% if usuario.otp_secret %}
|
||||
<span class="badge bg-success">Sim</span>
|
||||
{% else %}
|
||||
<span class="badge bg-danger">Não</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
<form action="{{ url_for('reset_otp', user_id=usuario.id) }}" method="POST" class="d-inline">
|
||||
<button type="submit" class="btn btn-warning btn-sm"
|
||||
onclick="return confirm('Tem certeza que deseja resetar o OTP deste usuário?')">
|
||||
Resetar OTP
|
||||
<div class="btn-group" role="group">
|
||||
<button class="btn btn-sm btn-outline-primary"
|
||||
onclick="toggleStatus('{{ usuario.id }}')"
|
||||
data-toggle="tooltip"
|
||||
title="{{ 'Desativar' if usuario.ativo else 'Ativar' }} usuário">
|
||||
<i class="fas {% if usuario.ativo %}fa-user-times{% else %}fa-user-check{% endif %}"></i>
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<button class="btn btn-sm btn-outline-warning"
|
||||
onclick="resetarSenha('{{ usuario.id }}')"
|
||||
data-toggle="tooltip"
|
||||
title="Resetar senha">
|
||||
<i class="fas fa-key"></i>
|
||||
</button>
|
||||
|
||||
{% if not usuario.is_admin %}
|
||||
<button class="btn btn-sm btn-outline-info"
|
||||
onclick="alterarNivel('{{ usuario.id }}')"
|
||||
data-toggle="tooltip"
|
||||
title="Alterar nível">
|
||||
<i class="fas fa-level-up-alt"></i>
|
||||
</button>
|
||||
{% endif %}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
@@ -66,18 +78,127 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h5 class="card-title mb-0">Ações Rápidas</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="d-grid gap-2">
|
||||
<a href="{{ url_for('novo_usuario') }}" class="btn btn-primary">
|
||||
Criar Novo Usuário
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<!-- Modal de Feedback -->
|
||||
<div class="modal fade" id="feedbackModal" tabindex="-1" role="dialog">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">Aviso</h5>
|
||||
<button type="button" class="close" data-dismiss="modal">
|
||||
<span>×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p id="feedbackMessage"></p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Fechar</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script>
|
||||
function showFeedback(message, type = 'info') {
|
||||
const modal = document.getElementById('feedbackModal');
|
||||
const messageElement = document.getElementById('feedbackMessage');
|
||||
messageElement.textContent = message;
|
||||
messageElement.className = `alert alert-${type}`;
|
||||
$(modal).modal('show');
|
||||
}
|
||||
|
||||
function handleResponse(response) {
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
return response.json();
|
||||
}
|
||||
|
||||
function toggleStatus(userId) {
|
||||
if (!confirm('Tem certeza que deseja alterar o status deste usuário?')) {
|
||||
return;
|
||||
}
|
||||
|
||||
fetch(`/usuarios/${userId}/toggle_status`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRFToken': document.querySelector('meta[name="csrf-token"]').content
|
||||
}
|
||||
})
|
||||
.then(handleResponse)
|
||||
.then(data => {
|
||||
showFeedback(data.message || 'Status alterado com sucesso!', data.success ? 'success' : 'danger');
|
||||
if (data.success) {
|
||||
setTimeout(() => location.reload(), 1500);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
showFeedback('Erro ao alterar status do usuário. Por favor, tente novamente.', 'danger');
|
||||
});
|
||||
}
|
||||
|
||||
function resetarSenha(userId) {
|
||||
if (!confirm('Tem certeza que deseja resetar a senha deste usuário?')) {
|
||||
return;
|
||||
}
|
||||
|
||||
fetch(`/reset_password/${userId}`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRFToken': document.querySelector('meta[name="csrf-token"]').content
|
||||
}
|
||||
})
|
||||
.then(handleResponse)
|
||||
.then(data => {
|
||||
showFeedback(data.message || 'Senha resetada com sucesso!', data.success ? 'success' : 'danger');
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
showFeedback('Erro ao resetar senha. Por favor, tente novamente.', 'danger');
|
||||
});
|
||||
}
|
||||
|
||||
function alterarNivel(userId) {
|
||||
const novoNivel = prompt('Digite o novo nível do usuário (1-5):');
|
||||
if (!novoNivel) return;
|
||||
|
||||
if (!/^[1-5]$/.test(novoNivel)) {
|
||||
showFeedback('Por favor, insira um nível válido entre 1 e 5.', 'warning');
|
||||
return;
|
||||
}
|
||||
|
||||
fetch(`/usuarios/${userId}/alterar_nivel`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRFToken': document.querySelector('meta[name="csrf-token"]').content
|
||||
},
|
||||
body: JSON.stringify({ nivel: parseInt(novoNivel) })
|
||||
})
|
||||
.then(handleResponse)
|
||||
.then(data => {
|
||||
showFeedback(data.message || 'Nível alterado com sucesso!', data.success ? 'success' : 'danger');
|
||||
if (data.success) {
|
||||
setTimeout(() => location.reload(), 1500);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
showFeedback('Erro ao alterar nível. Por favor, tente novamente.', 'danger');
|
||||
});
|
||||
}
|
||||
|
||||
// Inicializa os tooltips do Bootstrap
|
||||
$(function () {
|
||||
$('[data-toggle="tooltip"]').tooltip();
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user