-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #101 from zstenger93/user_management
User management
- Loading branch information
Showing
52 changed files
with
503 additions
and
337 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
cd backend && source venv/bin/activate | ||
python manage.py makemigrations && python manage.py migrate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
from django.contrib import admin | ||
from .models import User | ||
|
||
# Register your models here. | ||
|
||
admin.site.register(User) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
28 changes: 28 additions & 0 deletions
28
backend/authentication/migrations/0002_user_losses_user_total_matches_user_wins.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Generated by Django 5.0 on 2023-12-20 09:36 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('authentication', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='user', | ||
name='losses', | ||
field=models.PositiveIntegerField(default=0), | ||
), | ||
migrations.AddField( | ||
model_name='user', | ||
name='total_matches', | ||
field=models.PositiveIntegerField(default=0), | ||
), | ||
migrations.AddField( | ||
model_name='user', | ||
name='wins', | ||
field=models.PositiveIntegerField(default=0), | ||
), | ||
] |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 5.0 on 2023-12-20 10:19 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('authentication', '0002_user_losses_user_total_matches_user_wins'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='user', | ||
name='picture', | ||
field=models.ImageField(blank=True, default='default_profile_picture.PNG', null=True, upload_to='authentication/images/'), | ||
), | ||
] |
18 changes: 18 additions & 0 deletions
18
backend/authentication/migrations/0004_rename_picture_user_profile_picture.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 5.0 on 2023-12-20 10:22 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('authentication', '0003_user_picture'), | ||
] | ||
|
||
operations = [ | ||
migrations.RenameField( | ||
model_name='user', | ||
old_name='picture', | ||
new_name='profile_picture', | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 5.0 on 2023-12-21 10:00 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('authentication', '0004_rename_picture_user_profile_picture'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='user', | ||
name='title', | ||
field=models.CharField(blank=True, max_length=100, null=True), | ||
), | ||
] |
19 changes: 19 additions & 0 deletions
19
backend/authentication/migrations/0006_alter_user_profile_picture.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Generated by Django 5.0 on 2023-12-21 12:39 | ||
|
||
import authentication.models | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('authentication', '0005_user_title'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='user', | ||
name='profile_picture', | ||
field=models.ImageField(blank=True, default='default_profile_picture.PNG', null=True, upload_to=authentication.models.user_profile_picture_path), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Generated by Django 5.0 on 2023-12-22 13:23 | ||
|
||
import django.db.models.deletion | ||
from django.conf import settings | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('authentication', '0006_alter_user_profile_picture'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='FriendRequest', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('status', models.CharField(choices=[('pending', 'Pending'), ('accepted', 'Accepted'), ('rejected', 'Rejected')], default='pending', max_length=10)), | ||
('timestamp', models.DateTimeField(auto_now_add=True)), | ||
('from_user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='friend_requests_sent', to=settings.AUTH_USER_MODEL)), | ||
('to_user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='friend_requests_received', to=settings.AUTH_USER_MODEL)), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,44 @@ | ||
from django.db import models | ||
|
||
from django.contrib.auth.models import AbstractUser | ||
from .utils import user_profile_picture_path | ||
# Create your models here. | ||
|
||
class User(AbstractUser): | ||
|
||
profile_picture = models.ImageField(upload_to=user_profile_picture_path, null=True, blank=True, default='default_profile_picture.PNG') | ||
total_matches = models.PositiveIntegerField(default=0) | ||
wins = models.PositiveIntegerField(default=0) | ||
losses = models.PositiveIntegerField(default=0) | ||
title = models.CharField(max_length=100, null=True, blank=True) | ||
|
||
def get_friends(self) -> list: | ||
accepted_requests = FriendRequest.objects.filter( | ||
models.Q(from_user=self, status='accepted') | models.Q(to_user=self, status='accepted') | ||
) | ||
friends = [request.to_user if request.from_user == self else request.from_user for request in accepted_requests] | ||
return friends | ||
|
||
def get_received_friend_requests(self) -> list: | ||
received_requests = FriendRequest.objects.filter(to_user=self, status='pending') | ||
users = [request.from_user for request in received_requests] | ||
return users | ||
|
||
|
||
|
||
def __str__(self) -> str: | ||
return "Custom User: " + super().__str__() + ' . Total matches: ' + str(self.total_matches) + ' . Wins: ' + str(self.wins) + ' . Losses: ' + str(self.losses) | ||
|
||
class FriendRequest(models.Model): | ||
STATUS_CHOICES = ( | ||
('pending', 'Pending'), | ||
('accepted', 'Accepted'), | ||
('rejected', 'Rejected'), | ||
) | ||
|
||
from_user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='friend_requests_sent') | ||
to_user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='friend_requests_received') | ||
status = models.CharField(max_length=10, choices=STATUS_CHOICES, default='pending') | ||
timestamp = models.DateTimeField(auto_now_add=True) | ||
|
||
def __str__(self): | ||
return f"{self.from_user} to {self.to_user} ({self.status})" |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,32 +2,45 @@ | |
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Welcome to Ping Pong World</title> | ||
<!-- Include Tailwind CSS CDN or link to your local file --> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/tailwind.min.css"> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Welcome to Ping Pong World</title> | ||
<!-- Include Tailwind CSS CDN or link to your local file --> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/tailwind.min.css"> | ||
</head> | ||
|
||
<body class="bg-gray-100"> | ||
|
||
<div class="container mx-auto mt-20 text-center"> | ||
<h1 class="text-4xl font-bold text-green-600 mb-4">Ping Pong Home Page</h1> | ||
<p class="text-gray-600 mb-8">The Ultimate Ping Pong Experience!</p> | ||
<div class="container mx-auto mt-20 text-center"> | ||
<h1 class="text-4xl font-bold text-green-600 mb-4">Ping Pong Home Page</h1> | ||
<p class="text-gray-600 mb-8">The Ultimate Ping Pong Experience!</p> | ||
|
||
<div class="flex justify-center"> | ||
<a href="#" class="bg-green-500 hover:bg-green-600 text-white font-bold py-2 px-4 rounded-full mr-4">Play | ||
Now</a> | ||
<a href="#" class="bg-gray-500 hover:bg-gray-600 text-white font-bold py-2 px-4 rounded-full">Learn More</a> | ||
<!-- Display username and email from the context with enhanced styles --> | ||
<p class="text-lg font-semibold text-gray-800 mb-4"> | ||
Welcome, <span class="bg-green-200 px-2 py-1 rounded-md">{{ username }}</span>! | ||
</p> | ||
<p class="text-sm text-gray-600 mb-8"> | ||
Email: <span class="bg-blue-200 px-2 py-1 rounded-md">{{ email }}</span> | ||
</p> | ||
|
||
<!-- Add the logout button --> | ||
<a href="{% url 'logout' %}" class="bg-red-500 hover:bg-red-600 text-white font-bold py-2 px-4 rounded-full ml-4">Logout</a> | ||
</div> | ||
</div> | ||
<div class="flex justify-center"> | ||
<a href="#" class="bg-green-500 hover:bg-green-600 text-white font-bold py-2 px-4 rounded-full mr-4">Play | ||
Now</a> | ||
<a href="#" class="bg-gray-500 hover:bg-gray-600 text-white font-bold py-2 px-4 rounded-full">Learn More</a> | ||
|
||
<!-- Include Tailwind CSS and JavaScript CDNs or link to your local files --> | ||
<!-- Replace with the appropriate version numbers based on your project --> | ||
<!-- <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/tailwind.min.js"></script> --> | ||
<!-- Add the logout button --> | ||
<a href="{% url 'logout' %}" | ||
class="bg-red-500 hover:bg-red-600 text-white font-bold py-2 px-4 rounded-full ml-4">Logout</a> | ||
</div> | ||
|
||
|
||
<a href="{% url 'users_list' %}" | ||
class="bg-blue-500 hover:bg-blue-600 text-white font-bold py-2 px-4 rounded-full">Users List</a> | ||
</div> | ||
|
||
<!-- Include Tailwind CSS and JavaScript CDNs or link to your local files --> | ||
<!-- Replace with the appropriate version numbers based on your project --> | ||
<!-- <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/tailwind.min.js"></script> --> | ||
|
||
</body> | ||
|
||
|
Oops, something went wrong.