Skip to content

Commit

Permalink
changed authentication token to jwt.
Browse files Browse the repository at this point in the history
  • Loading branch information
msnamiria committed Jan 10, 2022
1 parent 4d195bc commit 273ea56
Show file tree
Hide file tree
Showing 22 changed files with 94 additions and 175 deletions.
Binary file modified back_end/Core/__pycache__/models.cpython-39.pyc
Binary file not shown.
39 changes: 20 additions & 19 deletions back_end/Core/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 3.2.5 on 2022-01-06 12:23
# Generated by Django 3.2.5 on 2022-01-10 16:13

from django.conf import settings
import django.core.validators
Expand All @@ -19,9 +19,10 @@ class Migration(migrations.Migration):
name='Celebrity',
fields=[
('celebID', models.AutoField(primary_key=True, serialize=False)),
('nameOf', models.CharField(max_length=150)),
('nameOf', models.CharField(max_length=255)),
('gender', models.BooleanField()),
('dateOfBirth', models.DateTimeField(null=True)),
('dateOfBirth', models.DateField(null=True)),
('nationality', models.CharField(max_length=255, null=True)),
],
),
migrations.CreateModel(
Expand All @@ -47,7 +48,7 @@ class Migration(migrations.Migration):
name='Genre',
fields=[
('genreID', models.AutoField(primary_key=True, serialize=False)),
('nameOf', models.CharField(max_length=150)),
('nameOf', models.CharField(max_length=100, unique=True)),
('details', models.TextField()),
],
),
Expand All @@ -61,17 +62,6 @@ class Migration(migrations.Migration):
('rating', models.IntegerField(default=0, validators=[django.core.validators.MaxValueValidator(10), django.core.validators.MinValueValidator(0)])),
],
),
migrations.CreateModel(
name='Review',
fields=[
('reviewID', models.AutoField(primary_key=True, serialize=False)),
('filmID', models.PositiveIntegerField()),
('userID', models.PositiveIntegerField()),
('textOf', models.TextField()),
('dateOf', models.DateField(auto_now_add=True)),
('rating', models.IntegerField(default=0, validators=[django.core.validators.MaxValueValidator(10), django.core.validators.MinValueValidator(0)])),
],
),
migrations.CreateModel(
name='Sale',
fields=[
Expand All @@ -95,16 +85,16 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='User',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('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')),
('userID', models.AutoField(primary_key=True, serialize=False)),
('username', models.CharField(max_length=100, unique=True, validators=[django.core.validators.RegexValidator(regex='^(?=[a-z0-9._]{5,20}$)(?!.*[_.]{2})[^_.].*[^_.]$')])),
('email', models.EmailField(max_length=100, unique=True, validators=[django.core.validators.EmailValidator()])),
('username', models.CharField(max_length=100, unique=True, validators=[django.core.validators.RegexValidator(regex='^(?=[a-zA-Z0-9._]{8,20}$)(?!.*[_.]{2})[^_.].*[^_.]$')])),
('name', models.CharField(max_length=100)),
('isSuspended', models.BooleanField(default=False)),
('isAdmin', models.BooleanField(default=False)),
('emailActivation', models.BooleanField(default=False)),
('name', models.CharField(max_length=100)),
('balance', models.IntegerField(default=0)),
('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')),
Expand All @@ -125,7 +115,7 @@ class Migration(migrations.Migration):
('season', models.PositiveIntegerField()),
('encoder', models.CharField(max_length=20)),
('directoryLocation', models.TextField()),
('film', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='Core.film')),
('film', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='Core.film')),
],
),
migrations.CreateModel(
Expand All @@ -138,6 +128,17 @@ class Migration(migrations.Migration):
('user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='Review',
fields=[
('reviewID', models.AutoField(primary_key=True, serialize=False)),
('textOf', models.TextField()),
('dateOf', models.DateField(auto_now_add=True)),
('rating', models.IntegerField(default=0, validators=[django.core.validators.MaxValueValidator(10), django.core.validators.MinValueValidator(0)])),
('film', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='Core.film')),
('user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='Payment',
fields=[
Expand Down
19 changes: 0 additions & 19 deletions back_end/Core/migrations/0002_alter_user_username.py

This file was deleted.

19 changes: 0 additions & 19 deletions back_end/Core/migrations/0003_alter_user_username.py

This file was deleted.

18 changes: 0 additions & 18 deletions back_end/Core/migrations/0004_alter_genre_nameof.py

This file was deleted.

33 changes: 0 additions & 33 deletions back_end/Core/migrations/0005_auto_20220108_2027.py

This file was deleted.

33 changes: 0 additions & 33 deletions back_end/Core/migrations/0006_auto_20220108_2323.py

This file was deleted.

22 changes: 0 additions & 22 deletions back_end/Core/migrations/0007_auto_20220108_2326.py

This file was deleted.

Binary file modified back_end/Core/migrations/__pycache__/0001_initial.cpython-39.pyc
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions back_end/Core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def createSuperUser(self, email, password):


class User(AbstractBaseUser, PermissionsMixin):
userID = models.AutoField(primary_key=True)
username = models.CharField(max_length=100, unique=True, validators=[RegexValidator(regex="^(?=[a-z0-9._]{5,20}$)(?!.*[_.]{2})[^_.].*[^_.]$")])
email= models.EmailField(max_length=100, unique=True, validators=[EmailValidator()])
name = models.CharField(max_length=100)
Expand Down
Binary file modified back_end/Film/__pycache__/serializers.cpython-39.pyc
Binary file not shown.
Binary file modified back_end/Film/__pycache__/urls.cpython-39.pyc
Binary file not shown.
Binary file modified back_end/Film/__pycache__/views.cpython-39.pyc
Binary file not shown.
11 changes: 10 additions & 1 deletion back_end/Film/serializers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from rest_framework import serializers
from Core.models import Celebrity, Genre
from Core.models import Celebrity, Genre, Film


class GenreSerializer(serializers.ModelSerializer):
Expand All @@ -16,6 +16,15 @@ class Meta:
read_only_fields = ('celebID',)


class FilmSerializer(serializers.ModelSerializer):
class Meta:
model = Film
fields = ('filmID', 'title', 'price', 'seasons', 'duration',
'statusOf', 'typeOf', 'numberOfFilminoRatings', 'filminoRating',
'rating', 'releaseDate', 'details', 'salePercentage', 'saleExpiration',)
read_only_fields = ('filmID',)


# class VideoSerilizer(serializers.ModelSerializer):
# class Meta:
# model = Celebrity
Expand Down
2 changes: 1 addition & 1 deletion back_end/Film/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

router.register('genre', views.GenreViewSet)
router.register('celebrity', views.CelebrityViewSet)
router.register('film', views.FilmViewSet)

app_name = 'Film'

urlpatterns = [
path('', include(router.urls)),
path('', include(router.urls))
]
16 changes: 15 additions & 1 deletion back_end/Film/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from rest_framework.decorators import authentication_classes, permission_classes
from rest_framework.permissions import IsAuthenticated
from rest_framework.utils import serializer_helpers
from Core.models import Celebrity, Genre
from Core.models import Celebrity, Genre, Film
from Film import serializers

# Create your views here.
Expand All @@ -30,6 +30,20 @@ class CelebrityViewSet(viewsets.GenericViewSet, mixins.ListModelMixin, mixins.Cr
queryset = Celebrity.objects.all()
serializer_class = serializers.CelebritySerializer

def get_queryset(self):
return self.queryset

def perform_create(self, serializer):
serializer.save()


class FilmViewSet(viewsets.GenericViewSet, mixins.ListModelMixin, mixins.CreateModelMixin):
authentication_classes = (TokenAuthentication,)
""" In case we want to make access to this list available to users only. """
# permission_classes = (IsAuthenticated,)
queryset = Film.objects.all()
serializer_class = serializers.FilmSerializer

def get_queryset(self):
return self.queryset

Expand Down
Binary file modified back_end/User/__pycache__/serializers.cpython-39.pyc
Binary file not shown.
Binary file modified back_end/User/__pycache__/views.cpython-39.pyc
Binary file not shown.
8 changes: 4 additions & 4 deletions back_end/User/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
class UserSerializer(serializers.ModelSerializer):
class Meta:
model = get_user_model()
fields = ('username','email', 'password', 'name', 'balance', 'emailActivation', 'isSuspended')
fields = ('userID', 'username','email', 'password', 'name', 'balance', 'emailActivation', 'isSuspended')
extra_kwargs = {'password': {'write_only': True, 'min_length': 8}}
read_only_fields = ('balance', 'isSuspended', 'emailActivation')
read_only_fields = ('userID', 'balance', 'isSuspended', 'emailActivation')

def create(self, validated_data):
return get_user_model().objects.createUser(**validated_data)
Expand Down Expand Up @@ -45,8 +45,8 @@ def validate(self, attrs):
return attrs


class TokenSerializer(serializers.ModelSerializer):
"""class TokenSerializer(serializers.ModelSerializer):
user = UserSerializer()
class Meta:
model = DefaultTokenModel
fields = ('key', 'user',)
fields = ('key', 'user',)"""
Loading

0 comments on commit 273ea56

Please sign in to comment.