From 6056ff459e0319087436d76004de89ba10f16055 Mon Sep 17 00:00:00 2001 From: hu8813 Date: Tue, 23 Apr 2024 11:15:10 +0200 Subject: [PATCH] a --- srcs/backend/myapp/models.py | 12 +++++++++++- srcs/backend/myapp/views.py | 3 ++- srcs/backend/start.sh | 23 ++++++++--------------- srcs/frontend/views/login.html | 2 -- 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/srcs/backend/myapp/models.py b/srcs/backend/myapp/models.py index 4bc9f96..93d1bee 100644 --- a/srcs/backend/myapp/models.py +++ b/srcs/backend/myapp/models.py @@ -102,4 +102,14 @@ class Channel(models.Model): password = models.CharField(max_length=100, blank=True) def __str__(self): - return self.name \ No newline at end of file + return self.name + + +class GameStats(models.Model): + user = models.ForeignKey(User, on_delete=models.CASCADE) + opponent = models.CharField(max_length=100) # Name of the opponent or "CPU" + win = models.BooleanField() # True if the user won, False if lost + date_time_played = models.DateTimeField(auto_now_add=True) + + def __str__(self): + return f'{self.user.username} vs. {self.opponent} - {"Won" if self.win else "Lost"}' \ No newline at end of file diff --git a/srcs/backend/myapp/views.py b/srcs/backend/myapp/views.py index 868a31a..0f9999d 100644 --- a/srcs/backend/myapp/views.py +++ b/srcs/backend/myapp/views.py @@ -15,7 +15,7 @@ import os import json from .forms import UserRegistrationForm -from .models import Tournament, User, Player, WaitingPlayer, Message, UserProfile, Feedback, Achievement, MyAppUserGroups, MyAppUserPermissions, Channel +from .models import Tournament, User, Player, WaitingPlayer, Message, UserProfile, Feedback, Achievement, MyAppUserGroups, MyAppUserPermissions, Channel, GameStats from django.utils import timezone from django.db import IntegrityError from django.utils.html import escape @@ -1133,6 +1133,7 @@ def manage_profile(request): MyAppUserPermissions.objects.filter(user=user).delete() UserProfile.objects.filter(user=user).delete() WaitingPlayer.objects.filter(user=user).delete() + GameStats.objects.filter(user=user).delete() user.delete() return JsonResponse({'message': 'Profile deleted successfully'}) diff --git a/srcs/backend/start.sh b/srcs/backend/start.sh index 405937e..9bde959 100755 --- a/srcs/backend/start.sh +++ b/srcs/backend/start.sh @@ -66,6 +66,14 @@ CREATE TABLE IF NOT EXISTS myapp_waitingplayer ( user_id INTEGER UNIQUE REFERENCES auth_user(id) ); +CREATE TABLE IF NOT EXISTS GameStats ( + id SERIAL PRIMARY KEY, + user_id INTEGER REFERENCES auth_user(id) ON DELETE CASCADE, + opponent VARCHAR(100) NOT NULL, + win BOOLEAN NOT NULL, + date_time_played TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP +); + -- Alter tables ALTER TABLE auth_user ADD COLUMN IF NOT EXISTS two_factor_enabled BOOLEAN DEFAULT FALSE; ALTER TABLE auth_user ADD COLUMN IF NOT EXISTS score INTEGER DEFAULT 0; @@ -82,21 +90,6 @@ ALTER TABLE auth_user_friends ADD COLUMN IF NOT EXISTS to_user_id INTEGER REFERE ALTER TABLE auth_user_blocked_users ADD COLUMN IF NOT EXISTS from_user_id INTEGER REFERENCES auth_user(id); ALTER TABLE auth_user_blocked_users ADD COLUMN IF NOT EXISTS to_user_id INTEGER REFERENCES auth_user(id); -INSERT INTO auth_user (username, email, password, first_name, last_name, is_superuser, is_staff, is_active, date_joined, score, nickname, image_link) -VALUES - ('user1', 'user1@example.com', 'password1', 'John', 'Doe', FALSE, FALSE, TRUE, NOW(), 0, 'Johny', 'https://pong42.vercel.app/src/logo.png'), - ('user2', 'user2@example.com', 'password2', 'Jane', 'Smith', FALSE, FALSE, TRUE, NOW(), 0, 'Janey', 'https://pong42.vercel.app/src/logo.png'), - ('user3', 'user3@example.com', 'password3', 'Bob', 'Johnson', FALSE, FALSE, TRUE, NOW(), 0, 'Bobby', 'https://pong42.vercel.app/src/logo.png'), - ('user4', 'user4@example.com', 'password4', 'Alice', 'Johnson', FALSE, FALSE, TRUE, NOW(), 0, 'Alicia', 'https://pong42.vercel.app/src/logo.png'), - ('user5', 'user5@example.com', 'password5', 'Eva', 'Brown', FALSE, FALSE, TRUE, NOW(), 0, 'Evie', 'https://pong42.vercel.app/src/logo.png'), - ('user6', 'user6@example.com', 'password6', 'Michael', 'Lee', FALSE, FALSE, TRUE, NOW(), 0, 'Mike', 'https://pong42.vercel.app/src/logo.png'), - ('user7', 'user7@example.com', 'password7', 'Emily', 'Garcia', FALSE, FALSE, TRUE, NOW(), 0, 'Emi', 'https://pong42.vercel.app/src/logo.png'), - ('user8', 'user8@example.com', 'password8', 'Daniel', 'Martinez', FALSE, FALSE, TRUE, NOW(), 0, 'Danny', 'https://pong42.vercel.app/src/logo.png'), - ('user9', 'user9@example.com', 'password9', 'Sophia', 'Hernandez', FALSE, FALSE, TRUE, NOW(), 0, 'Sophie', 'https://pong42.vercel.app/src/logo.png'), - ('user10', 'user10@example.com', 'password10', 'Alexander', 'Lopez', FALSE, FALSE, TRUE, NOW(), 0, 'Alex', 'https://pong42.vercel.app/src/logo.png'), - ('user11', 'user11@example.com', 'password11', 'Emma', 'Adams', FALSE, FALSE, TRUE, NOW(), 0, 'Emmie', 'https://pong42.vercel.app/src/logo.png'), - ('user12', 'user12@example.com', 'password12', 'Oliver', 'Wright', FALSE, FALSE, TRUE, NOW(), 0, 'Ollie', 'https://pong42.vercel.app/src/logo.png'), - ('user15', 'user15@example.com', 'password15', 'Ava', 'Young', FALSE, FALSE, TRUE, NOW(), 0, 'Avie', 'https://pong42.vercel.app/src/logo.png'); " | psql -h $POSTGRES_HOST -U $POSTGRES_USER -d $POSTGRES_DB -p $POSTGRES_PORT > /dev/null 2>&1 diff --git a/srcs/frontend/views/login.html b/srcs/frontend/views/login.html index c33e801..41ae428 100644 --- a/srcs/frontend/views/login.html +++ b/srcs/frontend/views/login.html @@ -20,7 +20,6 @@ name="username" id="userName" placeholder="Username" - value="user42" style="width: 80%; max-width: 200px;" /> @@ -31,7 +30,6 @@ name="password" id="pwd" placeholder="Password" - value="Pass@42" style="width: 80%; max-width: 200px;" />