Vous avez reçu un message "Your GitLab account has been locked ..." ? Pas d'inquiétude : lisez cet article https://docs.gricad-pages.univ-grenoble-alpes.fr/help/unlock/

Commit 5478a06a authored by Sylvain Coulange's avatar Sylvain Coulange
Browse files

test affichage traces utilisateur

parent 9a23455d
......@@ -30,6 +30,7 @@ urlpatterns = [
path('login/', auth_views.LoginView.as_view(template_name="users/login.html"), name='login'),
path('logout/', auth_views.LogoutView.as_view(template_name="users/logout.html"), name='logout'),
path('profile/', user_views.profile, name='profile'),
path('profile/delete', user_views.delete_account, name='delete_account'),
path('player/createSerie/', user_views.createSerie, name='createSerie'),
path('player/uploadAudio/', user_views.uploadAudio, name='uploadAudio'),
path('player/uploadImage/', user_views.uploadImage, name='uploadImage'),
......@@ -52,6 +53,7 @@ urlpatterns = [
path('_getStats/', csrf_exempt(user_views.getTracesStats)),
path('users/', user_views.usersPage, name='users'),
path('users/<str:username>/', user_views.userInfo, name='userInfo')
# path('getActivity/', csrf_exempt(clavier_views.getActivity)),
# path('switchstress/', clavier_views.openSwitchStress),
......
......@@ -13,9 +13,6 @@
<!-- BOOTSTRAP -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BmbxuPwQa2lc/FVzBcNJ7UAyJxM6wuqIj61tLrc4wSX0szH/Ev+nYRRuWlolflfl" crossorigin="anonymous">
<link rel="stylesheet" href="{% static 'styles/fa/css/font-awesome.min.css' %}">
<link rel="stylesheet" type="text/css" href="{% static 'styles/main.css'%}">
<link rel="stylesheet" type="text/css" href="{% static 'styles/phonochromie_alem_v3.css'%}">
<link rel="stylesheet" type="text/css" href="{% static 'styles/popup.css'%}">
......
......@@ -4,6 +4,12 @@
{% block content %}
<div class="content-section" style="text-align: left; max-width: 800px; margin:auto">
<div class="d-flex flex-row-reverse">
<form method="POST" action="{% url 'delete_account' %}">
{% csrf_token %}
<button type="submit" class="btn btn-danger">Supprimer mon compte</button>
</form>
</div>
<div class="media text-center">
<img class="rounded-circle account-img" src="{{ user.profile.image.url }}">
<div class="media-body">
......
......@@ -2,7 +2,7 @@
{% load crispy_forms_tags %}
{% block content %}
<div class="content-section registerBlock">
<div class="container content-section registerBlock">
<form method="POST">
{% csrf_token %}
<fieldset class="form-group">
......@@ -16,7 +16,7 @@
</form>
<div class="border-top pt-3">
<small class="text-muted">Vous avez déjà un compte ? <a href="{% url 'register' %}" class="ml-2">Se connecter</a></small>
<small class="text-muted">Vous avez déjà un compte ? <a href="{% url 'login' %}" class="ml-2">Se connecter</a></small>
</div>
</div>
......
{% extends "base.html" %}
{% load static %}
{% block styles %}
<link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.24/css/jquery.dataTables.min.css">
<link rel="stylesheet" type="text/css" href="{% static 'styles/main.css'%}">
{% endblock %}
{% block content %}
<div style="text-align: left; background-color: cornsilk;">
<h1>Traces de {{ data.username }}</h1>
<table class="table table-hover" id="tracesTable">
<thead>
<tr>
<th scope="col">Id</th>
<th scope="col">Date</th>
<th scope="col">Appli</th>
<th scope="col">Content</th>
<th scope="col">Ip</th>
<th scope="col">Agent</th>
</tr>
</thead>
<tbody>
{% for trace in data.traces %}
<tr>
<th scope="row">{{ trace.id }}</th>
<td>{{ trace.date | date:'d/m/Y e H:i:s' }}</td>
<td>{{ trace.appli }}</td>
<td>{{ trace.content}}</td>
<td>{{ trace.userIp}}</td>
<td>{{ trace.userAgent}}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<script>
$(document).ready( function () {
$('#tracesTable').DataTable();
} );
</script>
{% endblock content %}
{% block javascript %}
<script type="text/javascript" src="//cdn.datatables.net/1.10.24/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="{% static 'js/interface_basic.js' %}"></script>
{% endblock %}
\ No newline at end of file
......@@ -23,7 +23,7 @@
</thead>
<tbody>
{% for user in users %}
<tr>
<tr onclick="document.location = `{% url 'userInfo' user.username %}`;">
<th scope="row">{{ user.id }}</th>
<td>{{ user.username }}</td>
<td>{{ user.first_name }} {{ user.last_name }}</td>
......
......@@ -7,9 +7,18 @@ from .models import Profile
class UserRegisterForm(UserCreationForm):
email = forms.EmailField(required=True)
class Meta:
model = User
fields = ['username', 'email', 'password1', 'password2'] # paramétre l'affichage des champs (ordre et contenu)
fields = ['username', 'first_name', 'last_name', 'email', 'password1', 'password2'] # paramétre l'affichage des champs (ordre et contenu)
labels = {
'username':"Nom d'utilisateur",
'first_name':"Prénom",
'last_name':"Nom de famille",
'email':"E-mail",
'password1':"Mot de passe",
'password2':"Confirmation du mot de passe"
}
class UserUpdateForm(forms.ModelForm):
email = forms.EmailField()
......
......@@ -70,6 +70,16 @@ def profile(request):
return render(request, 'users/profile.html', {'u_form': u_form, 'p_form': p_form, 'titrePage':'page_perso'})
@login_required
def delete_account(request):
try:
u = User.objects.get(username = request.user.username)
u.delete()
messages.success(request, "Le compte de "+ request.user.username +" a bien été supprimé.")
return render(request, 'clavier.html')
except Exception as e:
return render(request, 'users/profile.html', {'err':e.message})
@login_required
......@@ -265,4 +275,20 @@ def getTracesStats(request):
@allowed_users(allowed_roles=['admin'])
def usersPage(request):
users = User.objects.all()
return render(request, 'users/usersPage.html', {'users':users})
\ No newline at end of file
return render(request, 'users/usersPage.html', {'users':users})
@allowed_users(allowed_roles=['admin'])
def userInfo(request, username):
user = User.objects.filter(username=username).first()
print("Récup info de", user.username)
# Formattage du temps : https://docs.djangoproject.com/en/3.1/ref/templates/builtins/#std:templatefilter-date
traces = Trace.objects.filter(user=user.id)
dataUser = {
'username': user.username,
'traces': traces
}
return render(request, 'users/userInfo.html', {'data': dataUser})
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment