Skip to content
Snippets Groups Projects
Commit da7db4e7 authored by DUVAL Elvan's avatar DUVAL Elvan
Browse files

V1

parent 2c6db504
Branches
No related tags found
No related merge requests found
Showing
with 194 additions and 41 deletions
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -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
{% 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
<!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>
<!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
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
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
No preview for this file type
AppGCC/static/img/chadfit1024.png

64.1 KiB

Elvan,moyen
No preview for this file type
No preview for this file type
No preview for this file type
username,score
Elvan,550
Thibaud,150
Thibaud,100
Elvan,800
buval,100
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment