Skip to content

added session authentication #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified db.sqlite3
Binary file not shown.
2 changes: 1 addition & 1 deletion project/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 = ['localhost', 'testserver']
ALLOWED_HOSTS = ['localhost', 'testserver',"*"]


REST_FRAMEWORK = {
Expand Down
22 changes: 11 additions & 11 deletions rest_api/views.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
from rest_framework import generics, permissions
from rest_framework import generics
from .permissions import IsOwner
from .serializers import BucketlistSerializer, UserSerializer
from .models import Bucketlist
from django.contrib.auth.models import User


from rest_framework.permissions import IsAuthenticated
from rest_framework.authentication import SessionAuthentication
class CreateView(generics.ListCreateAPIView):
"""This class handles the GET and POSt requests of our rest api."""
queryset = Bucketlist.objects.all()
serializer_class = BucketlistSerializer
permission_classes = (
permissions.IsAuthenticated,
IsOwner)
permission_classes = [IsAuthenticated]
authentication_classes = [SessionAuthentication]

def perform_create(self, serializer):
"""Save the post data when creating a new bucketlist."""
Expand All @@ -23,18 +22,19 @@ class DetailsView(generics.RetrieveUpdateDestroyAPIView):

queryset = Bucketlist.objects.all()
serializer_class = BucketlistSerializer
permission_classes = (
permissions.IsAuthenticated,
IsOwner)

permission_classes = [IsAuthenticated]
authentication_classes = [SessionAuthentication]

class UserView(generics.ListAPIView):
"""View to list the user queryset."""
queryset = User.objects.all()
serializer_class = UserSerializer

permission_classes = [IsAuthenticated]
authentication_classes = [SessionAuthentication]

class UserDetailsView(generics.RetrieveAPIView):
"""View to retrieve a user instance."""
queryset = User.objects.all()
serializer_class = UserSerializer
permission_classes = [IsAuthenticated]
authentication_classes = [SessionAuthentication]