Skip to content

Commit

Permalink
a
Browse files Browse the repository at this point in the history
  • Loading branch information
hu8813 committed Apr 23, 2024
1 parent 8c5f432 commit 6056ff4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 19 deletions.
12 changes: 11 additions & 1 deletion srcs/backend/myapp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,14 @@ class Channel(models.Model):
password = models.CharField(max_length=100, blank=True)

def __str__(self):
return self.name
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"}'
3 changes: 2 additions & 1 deletion srcs/backend/myapp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'})
Expand Down
23 changes: 8 additions & 15 deletions srcs/backend/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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', '[email protected]', 'password1', 'John', 'Doe', FALSE, FALSE, TRUE, NOW(), 0, 'Johny', 'https://pong42.vercel.app/src/logo.png'),
('user2', '[email protected]', 'password2', 'Jane', 'Smith', FALSE, FALSE, TRUE, NOW(), 0, 'Janey', 'https://pong42.vercel.app/src/logo.png'),
('user3', '[email protected]', 'password3', 'Bob', 'Johnson', FALSE, FALSE, TRUE, NOW(), 0, 'Bobby', 'https://pong42.vercel.app/src/logo.png'),
('user4', '[email protected]', 'password4', 'Alice', 'Johnson', FALSE, FALSE, TRUE, NOW(), 0, 'Alicia', 'https://pong42.vercel.app/src/logo.png'),
('user5', '[email protected]', 'password5', 'Eva', 'Brown', FALSE, FALSE, TRUE, NOW(), 0, 'Evie', 'https://pong42.vercel.app/src/logo.png'),
('user6', '[email protected]', 'password6', 'Michael', 'Lee', FALSE, FALSE, TRUE, NOW(), 0, 'Mike', 'https://pong42.vercel.app/src/logo.png'),
('user7', '[email protected]', 'password7', 'Emily', 'Garcia', FALSE, FALSE, TRUE, NOW(), 0, 'Emi', 'https://pong42.vercel.app/src/logo.png'),
('user8', '[email protected]', 'password8', 'Daniel', 'Martinez', FALSE, FALSE, TRUE, NOW(), 0, 'Danny', 'https://pong42.vercel.app/src/logo.png'),
('user9', '[email protected]', 'password9', 'Sophia', 'Hernandez', FALSE, FALSE, TRUE, NOW(), 0, 'Sophie', 'https://pong42.vercel.app/src/logo.png'),
('user10', '[email protected]', 'password10', 'Alexander', 'Lopez', FALSE, FALSE, TRUE, NOW(), 0, 'Alex', 'https://pong42.vercel.app/src/logo.png'),
('user11', '[email protected]', 'password11', 'Emma', 'Adams', FALSE, FALSE, TRUE, NOW(), 0, 'Emmie', 'https://pong42.vercel.app/src/logo.png'),
('user12', '[email protected]', 'password12', 'Oliver', 'Wright', FALSE, FALSE, TRUE, NOW(), 0, 'Ollie', 'https://pong42.vercel.app/src/logo.png'),
('user15', '[email protected]', '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

Expand Down
2 changes: 0 additions & 2 deletions srcs/frontend/views/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
name="username"
id="userName"
placeholder="Username"
value="user42"
style="width: 80%; max-width: 200px;"
/>
</div>
Expand All @@ -31,7 +30,6 @@
name="password"
id="pwd"
placeholder="Password"
value="Pass@42"
style="width: 80%; max-width: 200px;"
/>
</div>
Expand Down

0 comments on commit 6056ff4

Please sign in to comment.