108 lines
4.5 KiB
HTML
108 lines
4.5 KiB
HTML
{% extends "admin/base.html" %}
|
|
|
|
{% block admin_title %}Gerenciamento de Usuários{% endblock %}
|
|
|
|
{% block admin_content %}
|
|
<div class="card shadow mb-4">
|
|
<div class="card-header py-3">
|
|
<h6 class="m-0 font-weight-bold text-primary">Lista de Usuários</h6>
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="table-responsive">
|
|
<table class="table table-bordered" id="usersTable" width="100%" cellspacing="0">
|
|
<thead>
|
|
<tr>
|
|
<th>Email</th>
|
|
<th>Nome</th>
|
|
<th>Status</th>
|
|
<th>Último Login</th>
|
|
<th>Ações</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{% for user in users %}
|
|
<tr>
|
|
<td>{{ user.email }}</td>
|
|
<td>{{ user.militante.nome if user.militante else 'N/A' }}</td>
|
|
<td>
|
|
<span class="badge {% if user.is_active %}bg-success{% else %}bg-danger{% endif %}">
|
|
{{ 'Ativo' if user.is_active else 'Inativo' }}
|
|
</span>
|
|
</td>
|
|
<td>{{ user.ultimo_login.strftime('%d/%m/%Y %H:%M') if user.ultimo_login else 'Nunca' }}</td>
|
|
<td>
|
|
<div class="btn-group" role="group">
|
|
<!-- Botão de Reset OTP -->
|
|
<form action="{{ url_for('admin.reset_user_otp', user_id=user.id) }}" method="POST" class="d-inline">
|
|
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
|
<button type="submit" class="btn btn-warning btn-sm" title="Resetar OTP"
|
|
onclick="return confirm('Tem certeza que deseja resetar o OTP deste usuário?')">
|
|
<i class="fas fa-key"></i>
|
|
</button>
|
|
</form>
|
|
|
|
<!-- Botão de Reset Senha -->
|
|
<form action="{{ url_for('admin.reset_user_password', user_id=user.id) }}" method="POST" class="d-inline ms-1">
|
|
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
|
<button type="submit" class="btn btn-danger btn-sm" title="Resetar Senha"
|
|
onclick="return confirm('Tem certeza que deseja resetar a senha deste usuário?')">
|
|
<i class="fas fa-lock"></i>
|
|
</button>
|
|
</form>
|
|
|
|
<!-- Botão de Ativar/Desativar -->
|
|
<button class="btn btn-primary btn-sm ms-1" title="{{ 'Desativar' if user.is_active else 'Ativar' }} Usuário"
|
|
onclick="toggleUserStatus({{ user.id }})">
|
|
<i class="fas {% if user.is_active %}fa-user-times{% else %}fa-user-check{% endif %}"></i>
|
|
</button>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
{% endfor %}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{% endblock %}
|
|
|
|
{% block extra_js %}
|
|
<script>
|
|
function toggleUserStatus(userId) {
|
|
if (!confirm('Tem certeza que deseja alterar o status deste usuário?')) {
|
|
return;
|
|
}
|
|
|
|
fetch(`/admin/users/${userId}/toggle-status`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'X-CSRFToken': '{{ csrf_token() }}'
|
|
}
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
// Recarregar a página para mostrar as mudanças
|
|
location.reload();
|
|
} else {
|
|
alert(data.message || 'Erro ao alterar status do usuário');
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('Error:', error);
|
|
alert('Erro ao alterar status do usuário');
|
|
});
|
|
}
|
|
|
|
// Inicializar DataTable
|
|
$(document).ready(function() {
|
|
$('#usersTable').DataTable({
|
|
language: {
|
|
url: '//cdn.datatables.net/plug-ins/1.10.24/i18n/Portuguese-Brasil.json'
|
|
},
|
|
order: [[1, 'asc']]
|
|
});
|
|
});
|
|
</script>
|
|
{% endblock %} |