docker setup
This commit is contained in:
		
							
								
								
									
										25
									
								
								srcs/accounts/views/change_password.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								srcs/accounts/views/change_password.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,25 @@
 | 
			
		||||
from rest_framework.views import APIView
 | 
			
		||||
from rest_framework.response import Response
 | 
			
		||||
from rest_framework import permissions, status
 | 
			
		||||
from django.http import HttpRequest
 | 
			
		||||
from django.contrib.auth import login
 | 
			
		||||
from rest_framework.authentication import SessionAuthentication
 | 
			
		||||
from django.contrib.auth.models import User
 | 
			
		||||
 | 
			
		||||
from ..serializers.change_password import ChangePasswordSerializer
 | 
			
		||||
 | 
			
		||||
class ChangePasswordView(APIView):
 | 
			
		||||
 | 
			
		||||
    permission_classes = (permissions.IsAuthenticated,)
 | 
			
		||||
    authentication_classes = (SessionAuthentication,)
 | 
			
		||||
 | 
			
		||||
    def post(self, request: HttpRequest):
 | 
			
		||||
        data = request.data
 | 
			
		||||
 | 
			
		||||
        serializer = ChangePasswordSerializer(data=data)
 | 
			
		||||
        if serializer.is_valid(raise_exception=True):
 | 
			
		||||
            user: User = request.user
 | 
			
		||||
            if (user.check_password(data['current_password']) == 0):
 | 
			
		||||
                return Response({'current_password': "The password is not right."}, status=status.HTTP_200_OK)
 | 
			
		||||
            user.set_password(data["new_password"])
 | 
			
		||||
            return Response('password changed', status=status.HTTP_200_OK)
 | 
			
		||||
							
								
								
									
										12
									
								
								srcs/accounts/views/delete.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								srcs/accounts/views/delete.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,12 @@
 | 
			
		||||
from rest_framework.views import APIView
 | 
			
		||||
from rest_framework import permissions, status
 | 
			
		||||
from rest_framework.response import Response
 | 
			
		||||
from django.http import HttpRequest
 | 
			
		||||
from rest_framework.authentication import SessionAuthentication
 | 
			
		||||
 | 
			
		||||
class DeleteView(APIView):
 | 
			
		||||
	permission_classes = (permissions.IsAuthenticated,)
 | 
			
		||||
	authentication_classes = (SessionAuthentication,)
 | 
			
		||||
	def post(self, request: HttpRequest):
 | 
			
		||||
		request.user.delete()
 | 
			
		||||
		return Response("user deleted", status=status.HTTP_200_OK)
 | 
			
		||||
							
								
								
									
										23
									
								
								srcs/accounts/views/login.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								srcs/accounts/views/login.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,23 @@
 | 
			
		||||
from rest_framework.views import APIView
 | 
			
		||||
from rest_framework.response import Response
 | 
			
		||||
from rest_framework import permissions, status
 | 
			
		||||
from django.http import HttpRequest
 | 
			
		||||
from django.contrib.auth import login
 | 
			
		||||
from rest_framework.authentication import SessionAuthentication
 | 
			
		||||
 | 
			
		||||
from ..serializers.login import LoginSerializer
 | 
			
		||||
 | 
			
		||||
class LoginView(APIView):
 | 
			
		||||
    
 | 
			
		||||
	permission_classes = (permissions.AllowAny,)
 | 
			
		||||
	authentication_classes = (SessionAuthentication,)
 | 
			
		||||
 | 
			
		||||
	def post(self, request: HttpRequest):
 | 
			
		||||
		data = request.data
 | 
			
		||||
		serializer = LoginSerializer(data=data)
 | 
			
		||||
		serializer.is_valid(raise_exception=True)
 | 
			
		||||
		user = serializer.get_user(data)
 | 
			
		||||
		if user is None:
 | 
			
		||||
			return Response({'user': ['Username or password wrong.']}, status.HTTP_200_OK)
 | 
			
		||||
		login(request, user)
 | 
			
		||||
		return Response('user connected', status=status.HTTP_200_OK)
 | 
			
		||||
							
								
								
									
										13
									
								
								srcs/accounts/views/logout.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								srcs/accounts/views/logout.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,13 @@
 | 
			
		||||
from rest_framework.views import APIView
 | 
			
		||||
from django.contrib.auth import logout
 | 
			
		||||
from rest_framework import permissions, status
 | 
			
		||||
from rest_framework.response import Response
 | 
			
		||||
from django.http import HttpRequest
 | 
			
		||||
from rest_framework.authentication import SessionAuthentication
 | 
			
		||||
 | 
			
		||||
class LogoutView(APIView):
 | 
			
		||||
	permission_classes = (permissions.IsAuthenticated,)
 | 
			
		||||
	authentication_classes = (SessionAuthentication,)
 | 
			
		||||
	def post(self, request: HttpRequest):
 | 
			
		||||
		logout(request)
 | 
			
		||||
		return Response("user unlogged", status=status.HTTP_200_OK)
 | 
			
		||||
							
								
								
									
										16
									
								
								srcs/accounts/views/register.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								srcs/accounts/views/register.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,16 @@
 | 
			
		||||
from rest_framework import permissions, status
 | 
			
		||||
from ..serializers.register import RegisterSerialiser
 | 
			
		||||
from rest_framework.views import APIView
 | 
			
		||||
from rest_framework.response import Response
 | 
			
		||||
from django.http import HttpRequest
 | 
			
		||||
 | 
			
		||||
class RegisterView(APIView):
 | 
			
		||||
	permission_classes = (permissions.AllowAny,)
 | 
			
		||||
	def post(self, request: HttpRequest):
 | 
			
		||||
		data = request.data
 | 
			
		||||
		serializer = RegisterSerialiser(data=data)
 | 
			
		||||
		if serializer.is_valid(raise_exception=True):
 | 
			
		||||
			user = serializer.create(data)
 | 
			
		||||
			if user:
 | 
			
		||||
				return Response("user created", status=status.HTTP_201_CREATED)
 | 
			
		||||
		return Response(status=status.HTTP_400_BAD_REQUEST)
 | 
			
		||||
		Reference in New Issue
	
	Block a user