diff --git a/AppGCC/AppGCC/__pycache__/settings.cpython-310.pyc b/AppGCC/AppGCC/__pycache__/settings.cpython-310.pyc index 53de68a277d9ded5ac10fbac7b9a5cd98b593716..b0787d6b4cbcf21500c7d47d83e05cdf2e1cb78c 100644 Binary files a/AppGCC/AppGCC/__pycache__/settings.cpython-310.pyc and b/AppGCC/AppGCC/__pycache__/settings.cpython-310.pyc differ diff --git a/AppGCC/AppGCC/__pycache__/urls.cpython-310.pyc b/AppGCC/AppGCC/__pycache__/urls.cpython-310.pyc index 3535e525e077195a71aea23cc923c54ae627cb18..b8eb334a169d8563ee0f6497d3c2c9125b63777d 100644 Binary files a/AppGCC/AppGCC/__pycache__/urls.cpython-310.pyc and b/AppGCC/AppGCC/__pycache__/urls.cpython-310.pyc differ diff --git a/AppGCC/AppGCC/__pycache__/views.cpython-310.pyc b/AppGCC/AppGCC/__pycache__/views.cpython-310.pyc index e0fe575d0915ac9c901103ea9040ec9571c4463b..72c9bc106856317ceadcdba22292abbef13ca646 100644 Binary files a/AppGCC/AppGCC/__pycache__/views.cpython-310.pyc and b/AppGCC/AppGCC/__pycache__/views.cpython-310.pyc differ diff --git a/AppGCC/AppGCC/settings.py b/AppGCC/AppGCC/settings.py index 5153ae5c9bcbb0b6b3b3f589c9e0c656ffe93b9b..fc8b5ae4e5f12dab7d3e665bf77b9799f1e21ef0 100644 --- a/AppGCC/AppGCC/settings.py +++ b/AppGCC/AppGCC/settings.py @@ -27,7 +27,8 @@ SECRET_KEY = 'django-insecure-x&6%7n^!c0zx_%@5n(pidp1(eo4)esi+2-2c9_7^9ub_1gu6fl DEBUG = True ALLOWED_HOSTS = [ - "navlexx.fr" + "navlexx.fr", + "localhost" ] @@ -122,7 +123,13 @@ USE_TZ = True STATIC_URL = '/static/' +STATICFILES_DIRS = [ + BASE_DIR / "static", # This points to the 'static' directory at the root of your project +] + # Default primary key field type # https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' + +LOGOUT_REDIRECT_URL = '/login/' \ No newline at end of file diff --git a/AppGCC/AppGCC/templates/challenges.html b/AppGCC/AppGCC/templates/challenges.html index 544e2c6b7f9ce3da4ae597f6aa8bff840877441f..b8530b7ac3866fc2f21a7ee8b8e5e7114fec31d8 100644 --- a/AppGCC/AppGCC/templates/challenges.html +++ b/AppGCC/AppGCC/templates/challenges.html @@ -1,17 +1,72 @@ +{% load static %} <!DOCTYPE html> -<html> -<head><title>Défis</title></head> -<body> - <h2>Mes challenges du jour</h2> - <ul> - {% for challenge in challenges %} - <li> - {{ challenge }} - <button onclick="completeChallenge('{{ challenge }}')">Valider</button> - </li> - {% endfor %} - </ul> +<html lang="fr"> +<head> + <meta charset="UTF-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <title>Mes Défis</title> + <script src="https://cdn.tailwindcss.com"></script> +</head> +<body class="bg-[#dfdbec] flex flex-col items-center justify-between min-h-screen p-6"> + + <!-- Main Container --> + <div class="bg-white p-8 rounded-2xl shadow-2xl w-full max-w-3xl"> + + <!-- User Profile Section --> + <div class="flex items-center justify-between mb-6"> + <div class="flex items-center"> + <img src="{% static 'img/default-avatar.png' %}" alt="Avatar" class="h-16 w-16 rounded-full shadow-lg border-2 border-[#102564] cursor-pointer" onclick="toggleProfilePopup()"> + <div class="ml-4"> + <p class="text-2xl font-semibold text-[#102564]">{{ user.username }}</p> + <p class="text-sm text-gray-500">Bienvenue, {{ user.first_name }}</p> + </div> + </div> + <div class="flex space-x-4"> + <a href="{% url 'ranking' %}" class="bg-[#102564] text-white py-2 px-4 rounded-lg shadow-md hover:bg-[#000000] transition duration-300">Classement</a> + <a href="{% url 'logout' %}" class="bg-[#102564] text-white py-2 px-4 rounded-lg shadow-md hover:bg-[#000000] transition duration-300">Se déconnecter</a> + </div> + </div> + + <!-- Title --> + <h2 class="text-3xl font-bold text-[#102564] text-center mb-6">Mes Challenges du Jour</h2> + + <!-- Challenge List --> + <ul class="space-y-4"> + {% for challenge in challenges %} + <li class="flex items-center justify-between p-4 bg-gray-100 rounded-lg shadow-lg hover:shadow-xl transition duration-300"> + <span class="text-lg font-medium text-[#102564]">{{ challenge }}</span> + <button onclick="completeChallenge('{{ challenge }}')" class="py-2 px-4 bg-[#102564] text-white font-semibold rounded-lg shadow-md hover:bg-[#000000] transition duration-300">Valider</button> + </li> + {% endfor %} + </ul> + </div> + + <!-- Navigation Bar --> + <div class="fixed bottom-0 w-full bg-[#102564] text-white flex justify-around py-3 shadow-md"> + <a href="{% url 'challenges' %}" class="text-lg font-semibold hover:text-gray-300">Accueil</a> + <a href="{% url 'ranking' %}" class="text-lg font-semibold hover:text-gray-300">Classement</a> + </div> + + <!-- Profile Popup --> + <div id="profilePopup" class="hidden fixed inset-0 bg-black bg-opacity-50 flex justify-center items-center"> + <div class="bg-white p-6 rounded-lg shadow-lg w-96"> + <h2 class="text-xl font-bold text-[#102564] mb-4">Modifier le Profil</h2> + <label class="block text-sm text-gray-700">Niveau de difficulté</label> + <select id="difficulty" class="w-full p-2 border rounded-lg mb-4"> + <option value="facile">Facile</option> + <option value="moyen">Moyen</option> + <option value="difficile">Difficile</option> + </select> + <button onclick="saveProfileSettings()" class="w-full bg-[#102564] text-white py-2 rounded-lg hover:bg-[#000000] transition duration-300">Enregistrer</button> + <button onclick="toggleProfilePopup()" class="w-full mt-2 bg-gray-300 py-2 rounded-lg hover:bg-gray-400 transition duration-300">Annuler</button> + </div> + </div> + <script> + function toggleProfilePopup() { + document.getElementById("profilePopup").classList.toggle("hidden"); + } + function completeChallenge(challenge) { fetch("/complete_challenge/", { method: "POST", @@ -22,6 +77,18 @@ body: "challenge=" + challenge }).then(() => location.reload()); } + + function saveProfileSettings() { + let difficulty = document.getElementById("difficulty").value; + fetch("/update_difficulty/", { + method: "POST", + headers: { + "X-CSRFToken": "{{ csrf_token }}", + "Content-Type": "application/x-www-form-urlencoded" + }, + body: "difficulty=" + difficulty + }).then(() => toggleProfilePopup()); + } </script> </body> -</html> +</html> \ No newline at end of file diff --git a/AppGCC/AppGCC/templates/login.html b/AppGCC/AppGCC/templates/login.html index 8723a21d539deb0def5296c763d4b2ae4bc52e99..af596fe6da9a7445bd1cb00ed46f903ca6f1a053 100644 --- a/AppGCC/AppGCC/templates/login.html +++ b/AppGCC/AppGCC/templates/login.html @@ -1,13 +1,40 @@ <!DOCTYPE html> -<html> -<head><title>Connexion</title></head> -<body> - <h2>Connexion</h2> - <form method="post"> - {% csrf_token %} - <label>Nom d'utilisateur:</label> - <input type="text" name="username" required> - <button type="submit">Se connecter</button> - </form> +<html lang="fr"> +<head> + <meta charset="UTF-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <title>Connexion</title> + <script src="https://cdn.tailwindcss.com"></script> <!-- Tailwind CDN --> + {% load static %} +</head> +<body class="bg-[#dfdbec] flex items-center justify-center min-h-screen"> + <div class="bg-white p-8 rounded-lg shadow-lg w-full max-w-md"> + <!-- Logo Section --> + <div class="flex justify-center mb-6"> + <img src="{% static 'img/chadfit1024.png' %}" alt="Logo" class="h-16 w-auto shadow-lg rounded-lg"> + </div> + + <!-- Title --> + <h2 class="text-2xl font-semibold text-[#000000] text-center mb-6">Connexion</h2> + + <!-- Form Section --> + <form method="post"> + {% csrf_token %} + + <!-- Username Input --> + <div class="mb-4"> + <label for="username" class="block text-sm font-medium text-[#000000]">Nom d'utilisateur:</label> + <input type="text" name="username" id="username" required + class="w-full p-3 mt-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-2 focus:ring-[#102564] focus:border-[#102564]"> + </div> + + <!-- Submit Button --> + <div class="flex items-center justify-between mt-6"> + <button type="submit" class="w-full py-3 bg-[#102564] text-white font-semibold rounded-lg shadow-md hover:bg-[#000000] focus:outline-none focus:ring-2 focus:ring-[#102564] focus:ring-opacity-50"> + Se connecter + </button> + </div> + </form> + </div> </body> </html> diff --git a/AppGCC/AppGCC/templates/ranking.html b/AppGCC/AppGCC/templates/ranking.html index bc1308b3cb431ab5ef463b4feab7eeb11162ea46..cdad18674dd6c42131f386b78d21692d563053aa 100644 --- a/AppGCC/AppGCC/templates/ranking.html +++ b/AppGCC/AppGCC/templates/ranking.html @@ -1,12 +1,20 @@ <!DOCTYPE html> <html> -<head><title>Classement</title></head> -<body> - <h2>Classement</h2> - <ul> - {% for user, score in scores %} - <li>{{ user }}: {{ score }} points</li> - {% endfor %} - </ul> +<head> + <title>Classement</title> + <script src="https://cdn.tailwindcss.com"></script> +</head> +<body class="bg-[#dfdbec] flex items-center justify-center min-h-screen p-6"> + <div class="bg-white p-8 rounded-2xl shadow-2xl w-full max-w-3xl"> + <h2 class="text-3xl font-bold text-[#102564] text-center mb-6">Classement</h2> + <ul class="space-y-4"> + {% for user, score in scores %} + <li class="flex justify-between p-4 bg-gray-100 rounded-lg shadow-md"> + <span class="text-lg text-[#102564] font-medium">{{ user }}</span> + <span class="text-lg font-semibold text-[#102564]">{{ score }} points</span> + </li> + {% endfor %} + </ul> + </div> </body> -</html> +</html> \ No newline at end of file diff --git a/AppGCC/AppGCC/urls.py b/AppGCC/AppGCC/urls.py index af2e996df3b209f41b31e8eaa8b345ca50ade9a6..89b3d56b4d9019744754a87658f18b1c5232ce1d 100644 --- a/AppGCC/AppGCC/urls.py +++ b/AppGCC/AppGCC/urls.py @@ -1,11 +1,13 @@ from django.contrib import admin from django.urls import path -from .views import login_view, challenges_view, complete_challenge, ranking_view +from . import views urlpatterns = [ path('admin/', admin.site.urls), # Accès à l'administration Django - path('', login_view, name='login'), # Page de connexion par défaut - path('challenges/', challenges_view, name='challenges'), # Page des défis - path('complete_challenge/', complete_challenge, name='complete_challenge'), # API de validation des défis - path('ranking/', ranking_view, name='ranking'), # Page du classement -] + path('', views.login_view, name='login'), # Page de connexion par défaut + path('challenges/', views.challenges_view, name='challenges'), # Page des défis + path('complete_challenge/', views.complete_challenge, name='complete_challenge'), # API de validation des défis + path('ranking/', views.ranking_view, name='ranking'), # Page du classement + path('logout/', views.logout_view, name='logout'), + path("update_difficulty/", views.update_difficulty, name="update_difficulty"), +] \ No newline at end of file diff --git a/AppGCC/AppGCC/views.py b/AppGCC/AppGCC/views.py index 6dee095f69deeba8af7b12b9daa5fe67c341465b..0e2ac0b7e054b11e7089e61561b583c3781c14d8 100644 --- a/AppGCC/AppGCC/views.py +++ b/AppGCC/AppGCC/views.py @@ -1,12 +1,16 @@ from django.shortcuts import render, redirect from django.contrib.auth import login from django.contrib.auth.models import User +from django.contrib.auth import logout +from django.views.decorators.csrf import csrf_exempt from django.http import JsonResponse import csv import os # Fichier CSV pour stocker les scores CSV_FILE = "scores.csv" +DIFFICULTY_FILE = "difficulties.csv" + def init_csv(): if not os.path.exists(CSV_FILE): @@ -65,3 +69,39 @@ def ranking_view(request): scores = read_scores() sorted_scores = sorted(scores.items(), key=lambda x: x[1], reverse=True) return render(request, "ranking.html", {"scores": sorted_scores}) + +def logout_view(request): + logout(request) # This logs out the user + return redirect('login') + +@csrf_exempt +def update_difficulty(request): + if request.method == "POST": + difficulty = request.POST.get("difficulty", "moyen") # Valeur par défaut + user = request.user.username if request.user.is_authenticated else "guest" # Utilisateur authentifié ou invité + + scores = [] + user_found = False + + if os.path.exists(DIFFICULTY_FILE): + with open(DIFFICULTY_FILE, "r", newline="", encoding="utf-8") as file: + reader = csv.reader(file) + for row in reader: + if len(row) < 2: + continue # Ignorer les lignes mal formées, on s'attend à [username, difficulty] + + if row[0] == user: + row[1] = difficulty # Modifier uniquement la difficulté (plus de score) + user_found = True + scores.append(row) + + if not user_found: + scores.append([user, difficulty]) # Ajouter utilisateur avec difficulté choisie (sans score) + + with open(DIFFICULTY_FILE, "w", newline="", encoding="utf-8") as file: + writer = csv.writer(file) + writer.writerows(scores) + + return JsonResponse({"status": "success", "difficulty": difficulty}) + + return JsonResponse({"status": "error", "message": "Invalid request"}, status=400) \ No newline at end of file diff --git a/AppGCC/db.sqlite3 b/AppGCC/db.sqlite3 index 49132dc115de005085e7326bd4a957a275993fec..0e97db3e44749fa0ee86389a4029f8986b229b83 100644 Binary files a/AppGCC/db.sqlite3 and b/AppGCC/db.sqlite3 differ diff --git a/AppGCC/static/img/chadfit1024.png b/AppGCC/static/img/chadfit1024.png new file mode 100644 index 0000000000000000000000000000000000000000..dd9a39da9d2492be5f31ae8894731027ceee7240 Binary files /dev/null and b/AppGCC/static/img/chadfit1024.png differ diff --git a/difficulties.csv b/difficulties.csv new file mode 100644 index 0000000000000000000000000000000000000000..0e91f7e31f3e0c7717025b9b532ff295a7adc87d --- /dev/null +++ b/difficulties.csv @@ -0,0 +1 @@ +Elvan,moyen diff --git a/postgresData/pg_stat_tmp/db_0.stat b/postgresData/pg_stat_tmp/db_0.stat index 7c775239c34ab35d37841ed709ab502d7dd69c13..a0e90ba7222db70e2d7b34dcdea9444c1184d284 100644 Binary files a/postgresData/pg_stat_tmp/db_0.stat and b/postgresData/pg_stat_tmp/db_0.stat differ diff --git a/postgresData/pg_stat_tmp/db_13468.stat b/postgresData/pg_stat_tmp/db_13468.stat index 4944551708aa6e1aa1fe93a65067c50fb11ffeeb..5b27920b0cc82334557bb9eee1beed2e459652dc 100644 Binary files a/postgresData/pg_stat_tmp/db_13468.stat and b/postgresData/pg_stat_tmp/db_13468.stat differ diff --git a/postgresData/pg_stat_tmp/global.stat b/postgresData/pg_stat_tmp/global.stat index 3a1c48da8e484d7639758b807739b9f20cd89bfb..a8c047e80464cec6e238180599c3d699e7b7dbaa 100644 Binary files a/postgresData/pg_stat_tmp/global.stat and b/postgresData/pg_stat_tmp/global.stat differ diff --git a/scores.csv b/scores.csv index 0defcb415d94457a5e72617a1a1dfe78d26a6c25..dd8571450afcb6b0749ba698eefdb733187c813e 100644 --- a/scores.csv +++ b/scores.csv @@ -1,3 +1,4 @@ username,score -Elvan,550 -Thibaud,150 +Thibaud,100 +Elvan,800 +buval,100