Skip to content

Commit

Permalink
Merge pull request #101 from zstenger93/user_management
Browse files Browse the repository at this point in the history
User management
  • Loading branch information
zstenger93 authored Dec 25, 2023
2 parents 77c67b0 + 487dfd4 commit 1700f65
Show file tree
Hide file tree
Showing 52 changed files with 503 additions and 337 deletions.
13 changes: 11 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


# dependencies
*/node_modules
node_modules
*/.pnp
*.pnp.js

Expand All @@ -44,4 +44,13 @@
*yarn-debug.log*
*yarn-error.log*

node_modules
# Jamshidbek
to-do.txt
jsonuser.json

# backend/authentication
backend/authentication/images/*

# media
media
node_modules
2 changes: 2 additions & 0 deletions backend.sh
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
3 changes: 3 additions & 0 deletions backend/authentication/admin.py
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)
30 changes: 25 additions & 5 deletions backend/authentication/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Generated by Django 5.0 on 2023-12-10 07:48
# Generated by Django 5.0 on 2023-12-19 09:26

import django.contrib.auth.models
import django.contrib.auth.validators
import django.utils.timezone
from django.db import migrations, models


Expand All @@ -8,17 +11,34 @@ class Migration(migrations.Migration):
initial = True

dependencies = [
('auth', '0001_initial'),
]

operations = [
migrations.CreateModel(
name='User',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('username', models.CharField(max_length=255)),
('display_name', models.CharField(max_length=255)),
('email', models.EmailField(max_length=254)),
('picture', models.URLField()),
('password', models.CharField(max_length=128, verbose_name='password')),
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')),
('first_name', models.CharField(blank=True, max_length=150, verbose_name='first name')),
('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')),
('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')),
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.group', verbose_name='groups')),
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.permission', verbose_name='user permissions')),
],
options={
'verbose_name': 'user',
'verbose_name_plural': 'users',
'abstract': False,
},
managers=[
('objects', django.contrib.auth.models.UserManager()),
],
),
]
18 changes: 0 additions & 18 deletions backend/authentication/migrations/0002_alter_user_id.py

This file was deleted.

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),
),
]
17 changes: 0 additions & 17 deletions backend/authentication/migrations/0003_delete_user.py

This file was deleted.

18 changes: 18 additions & 0 deletions backend/authentication/migrations/0003_user_picture.py
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/'),
),
]
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',
),
]
18 changes: 18 additions & 0 deletions backend/authentication/migrations/0005_user_title.py
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),
),
]
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),
),
]
25 changes: 25 additions & 0 deletions backend/authentication/migrations/0007_friendrequest.py
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)),
],
),
]
43 changes: 42 additions & 1 deletion backend/authentication/models.py
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.
51 changes: 32 additions & 19 deletions backend/authentication/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
Loading

0 comments on commit 1700f65

Please sign in to comment.