Skip to content

Commit

Permalink
Merge pull request #42 from subodh30/authentication
Browse files Browse the repository at this point in the history
JWT Authentication
  • Loading branch information
subodh30 committed Oct 9, 2022
2 parents a8b79ba + 63035a9 commit 2f1a170
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.1.1 on 2022-10-07 13:51

from django.db import migrations, models


class Migration(migrations.Migration):

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

operations = [
migrations.AlterField(
model_name='owner',
name='contact_email',
field=models.EmailField(max_length=30, unique=True),
),
migrations.AlterField(
model_name='user',
name='contact_email',
field=models.EmailField(max_length=30, unique=True),
),
]
14 changes: 14 additions & 0 deletions housing/migrations/0004_merge_20221009_1347.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Generated by Django 4.1.1 on 2022-10-09 13:47

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('housing', '0002_alter_owner_contact_email_alter_user_contact_email'),
('housing', '0003_alter_interested_flat_id'),
]

operations = [
]
3 changes: 3 additions & 0 deletions housing/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ class User(models.Model):
pref_drinking = models.CharField(default="N", max_length=2)
pref_veg = models.CharField(default="N", max_length=2)

def __str__(self):
return self.contact_email

class Interested(models.Model):
apartment_id = models.ForeignKey(to=Apartment, on_delete=models.DO_NOTHING)
flat_id = models.ForeignKey(to=Flat, on_delete=models.CASCADE)
Expand Down
7 changes: 7 additions & 0 deletions housing/serializers.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
from rest_framework import serializers
from housing import models
from rest_framework.authtoken.models import Token
from rest_framework.validators import ValidationError
from django.contrib.auth.hashers import make_password

class UserSerializer(serializers.ModelSerializer):
class Meta:
model = models.User
fields = '__all__'

def create(self, validated_data):
validated_data['password'] = make_password(validated_data['password'])
return super(UserSerializer, self).create(validated_data)

class FlatSerializer(serializers.ModelSerializer):
class Meta:
Expand Down
4 changes: 1 addition & 3 deletions housing/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,4 @@
path('apartments/<str:pk>', views.ApartmentViewSet.as_view()),
path('users', views.UserViewSet.as_view()),
path('users/<str:pk>', views.UserViewSet.as_view()),


]
]
9 changes: 5 additions & 4 deletions housing/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
from rest_framework import filters, viewsets, generics
from housing import serializers
from housing import models

from rest_framework.authentication import SessionAuthentication, BasicAuthentication
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework.views import APIView

# Create your views here.
class UserViewSet(generics.ListCreateAPIView, generics.RetrieveUpdateDestroyAPIView):
Expand Down Expand Up @@ -46,6 +49,4 @@ class ApartmentViewSet(generics.ListCreateAPIView, generics.RetrieveUpdateDestro
search_fields = ['address', 'facilities', 'owner_id']
filter_backends = (filters.SearchFilter,)
queryset = models.Apartment.objects.all()
serializer_class = serializers.ApartmentSerializer


serializer_class = serializers.ApartmentSerializer
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ asgiref==3.5.2
backports.zoneinfo==0.2.1
Django==4.1.1
djangorestframework==3.14.0
djangorestframework-simplejwt==5.2.1
PyJWT==2.5.0
pytz==2022.2.1
PyYAML==6.0
sqlparse==0.4.3
tzdata==2022.2
uritemplate==4.1.1
coverage==6.5.0
coverage==6.5.0
11 changes: 8 additions & 3 deletions wolf_lease/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []
ALLOWED_HOSTS = ['localhost']


# Application definition
Expand All @@ -41,6 +41,7 @@
'housing',
]


MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
Expand Down Expand Up @@ -71,7 +72,12 @@

WSGI_APPLICATION = 'wolf_lease.wsgi.application'


REST_FRAMEWORK = {
# 'DEFAULT_PERMISSION_CLASSES': ('rest_framework.permissions.IsAuthenticated',),
# 'DEFAULT_AUTHENTICATION_CLASSES': [
# 'rest_framework_simplejwt.authentication.JWTAuthentication',
# ],
}
# Database
# https://docs.djangoproject.com/en/4.1/ref/settings/#databases

Expand Down Expand Up @@ -101,7 +107,6 @@
},
]


# Internationalization
# https://docs.djangoproject.com/en/4.1/topics/i18n/

Expand Down

0 comments on commit 2f1a170

Please sign in to comment.