diff --git a/AppGCC/AppGCC/__pycache__/settings.cpython-310.pyc b/AppGCC/AppGCC/__pycache__/settings.cpython-310.pyc index 0e63aad2ed05514e5f78f638fd8ce1f229ae5eb9..53de68a277d9ded5ac10fbac7b9a5cd98b593716 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 ce487c2eb9b96e109658b38e8cfecb067acdc7e9..3535e525e077195a71aea23cc923c54ae627cb18 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 new file mode 100644 index 0000000000000000000000000000000000000000..e0fe575d0915ac9c901103ea9040ec9571c4463b Binary files /dev/null and b/AppGCC/AppGCC/__pycache__/views.cpython-310.pyc differ diff --git a/AppGCC/AppGCC/settings.py b/AppGCC/AppGCC/settings.py index 66efde7e92d25fe81c691c8593ce53bb0a6ae5f4..5153ae5c9bcbb0b6b3b3f589c9e0c656ffe93b9b 100644 --- a/AppGCC/AppGCC/settings.py +++ b/AppGCC/AppGCC/settings.py @@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/3.2/ref/settings/ """ from pathlib import Path +import os # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent @@ -56,7 +57,7 @@ ROOT_URLCONF = 'AppGCC.urls' TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [], + 'DIRS': [os.path.join(BASE_DIR, 'AppGCC/templates')], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ diff --git a/AppGCC/AppGCC/templates/challenges.html b/AppGCC/AppGCC/templates/challenges.html new file mode 100644 index 0000000000000000000000000000000000000000..544e2c6b7f9ce3da4ae597f6aa8bff840877441f --- /dev/null +++ b/AppGCC/AppGCC/templates/challenges.html @@ -0,0 +1,27 @@ +<!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> + <script> + function completeChallenge(challenge) { + fetch("/complete_challenge/", { + method: "POST", + headers: { + "X-CSRFToken": "{{ csrf_token }}", + "Content-Type": "application/x-www-form-urlencoded" + }, + body: "challenge=" + challenge + }).then(() => location.reload()); + } + </script> +</body> +</html> diff --git a/AppGCC/AppGCC/templates/login.html b/AppGCC/AppGCC/templates/login.html new file mode 100644 index 0000000000000000000000000000000000000000..8723a21d539deb0def5296c763d4b2ae4bc52e99 --- /dev/null +++ b/AppGCC/AppGCC/templates/login.html @@ -0,0 +1,13 @@ +<!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> +</body> +</html> diff --git a/AppGCC/AppGCC/templates/ranking.html b/AppGCC/AppGCC/templates/ranking.html new file mode 100644 index 0000000000000000000000000000000000000000..bc1308b3cb431ab5ef463b4feab7eeb11162ea46 --- /dev/null +++ b/AppGCC/AppGCC/templates/ranking.html @@ -0,0 +1,12 @@ +<!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> +</body> +</html> diff --git a/AppGCC/AppGCC/urls.py b/AppGCC/AppGCC/urls.py index c0cc764774dd9f6febdffd8037294a6fba723c8c..af2e996df3b209f41b31e8eaa8b345ca50ade9a6 100644 --- a/AppGCC/AppGCC/urls.py +++ b/AppGCC/AppGCC/urls.py @@ -1,21 +1,11 @@ -"""AppGCC URL Configuration - -The `urlpatterns` list routes URLs to views. For more information please see: - https://docs.djangoproject.com/en/3.2/topics/http/urls/ -Examples: -Function views - 1. Add an import: from my_app import views - 2. Add a URL to urlpatterns: path('', views.home, name='home') -Class-based views - 1. Add an import: from other_app.views import Home - 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') -Including another URLconf - 1. Import the include() function: from django.urls import include, path - 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) -""" from django.contrib import admin from django.urls import path +from .views import login_view, challenges_view, complete_challenge, ranking_view urlpatterns = [ - path('admin/', admin.site.urls), + 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 ] diff --git a/AppGCC/AppGCC/views.py b/AppGCC/AppGCC/views.py new file mode 100644 index 0000000000000000000000000000000000000000..6dee095f69deeba8af7b12b9daa5fe67c341465b --- /dev/null +++ b/AppGCC/AppGCC/views.py @@ -0,0 +1,67 @@ +from django.shortcuts import render, redirect +from django.contrib.auth import login +from django.contrib.auth.models import User +from django.http import JsonResponse +import csv +import os + +# Fichier CSV pour stocker les scores +CSV_FILE = "scores.csv" + +def init_csv(): + if not os.path.exists(CSV_FILE): + with open(CSV_FILE, 'w', newline='') as file: + writer = csv.writer(file) + writer.writerow(["username", "score"]) + +def read_scores(): + scores = {} + try: + with open(CSV_FILE, 'r') as file: + reader = csv.reader(file) + next(reader) # Ignorer l'en-tête + for row in reader: + scores[row[0]] = int(row[1]) + except FileNotFoundError: + init_csv() + return scores + +def update_score(username, points): + scores = read_scores() + scores[username] = scores.get(username, 0) + points + with open(CSV_FILE, 'w', newline='') as file: + writer = csv.writer(file) + writer.writerow(["username", "score"]) + for user, score in scores.items(): + writer.writerow([user, score]) + +def login_view(request): + if request.method == "POST": + username = request.POST["username"] + user, created = User.objects.get_or_create(username=username) + login(request, user) + return redirect("challenges") + return render(request, "login.html") + +def challenges_view(request): + if not request.user.is_authenticated: + return redirect("login") + challenges = ["Monter les escaliers", "1h de bureau debout", "Faire 5000 pas"] + return render(request, "challenges.html", {"challenges": challenges}) + +def complete_challenge(request): + if request.method == "POST": + challenge_points = { + "Monter les escaliers": 100, + "1h de bureau debout": 50, + "Faire 5000 pas": 200 + } + challenge = request.POST.get("challenge") + if challenge in challenge_points: + update_score(request.user.username, challenge_points[challenge]) + return JsonResponse({"success": True}) + +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}) diff --git a/AppGCC/db.sqlite3 b/AppGCC/db.sqlite3 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..49132dc115de005085e7326bd4a957a275993fec 100644 Binary files a/AppGCC/db.sqlite3 and b/AppGCC/db.sqlite3 differ diff --git a/postgresData/base/13468/pg_internal.init b/postgresData/base/13468/pg_internal.init index dc1aacba1dee528bbbd9e6a0b0afee8c37db99b2..cb35c73e5bd12ea6491abe0363908d84a981168d 100644 Binary files a/postgresData/base/13468/pg_internal.init and b/postgresData/base/13468/pg_internal.init differ diff --git a/postgresData/global/pg_control b/postgresData/global/pg_control index 39d680a5d6a488d1d38bd7cac66ee06887d475bc..39e770e976ddf56ddf16fde48c3324a8de685d70 100644 Binary files a/postgresData/global/pg_control and b/postgresData/global/pg_control differ diff --git a/postgresData/global/pg_internal.init b/postgresData/global/pg_internal.init index 431d4472b69bb1ef81b496c8ae8f32a9e2c18082..2b078469a136682a00f210c6f3023efe5ce756e0 100644 Binary files a/postgresData/global/pg_internal.init and b/postgresData/global/pg_internal.init differ diff --git a/postgresData/pg_stat_tmp/db_0.stat b/postgresData/pg_stat_tmp/db_0.stat index bdc47a6014e6a460f8e3d879827e57968f07bbd4..7c775239c34ab35d37841ed709ab502d7dd69c13 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 d65d19019222fb7cb6a6d884e70ada914567de2b..4944551708aa6e1aa1fe93a65067c50fb11ffeeb 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 f88d8377462968b11a4de5aebcb91ccfe537a138..3a1c48da8e484d7639758b807739b9f20cd89bfb 100644 Binary files a/postgresData/pg_stat_tmp/global.stat and b/postgresData/pg_stat_tmp/global.stat differ diff --git a/postgresData/pg_wal/000000010000000000000001 b/postgresData/pg_wal/000000010000000000000001 index c1900074925bcfbf8f2bd321fcf16929044663cd..e9abe198d2cead17ebe8ba6ad9b4ce7c80b8ac7e 100644 Binary files a/postgresData/pg_wal/000000010000000000000001 and b/postgresData/pg_wal/000000010000000000000001 differ diff --git a/postgresData/postmaster.pid b/postgresData/postmaster.pid index 0271fa40ffdbd31b3543f3fec63801e4555ef9ca..8c25c0eb578c8a8476b5f241b57054c49d531815 100644 --- a/postgresData/postmaster.pid +++ b/postgresData/postmaster.pid @@ -1,6 +1,6 @@ 1 /var/lib/postgresql/data -1741772457 +1741781339 5432 /var/run/postgresql * diff --git a/scores.csv b/scores.csv new file mode 100644 index 0000000000000000000000000000000000000000..0defcb415d94457a5e72617a1a1dfe78d26a6c25 --- /dev/null +++ b/scores.csv @@ -0,0 +1,3 @@ +username,score +Elvan,550 +Thibaud,150