2020-12-09 19:24:41 +01:00
|
|
|
"""
|
|
|
|
@author: p.dolata
|
|
|
|
"""
|
|
|
|
|
2020-12-01 18:01:35 +01:00
|
|
|
from rest_framework import status
|
2020-12-01 22:49:16 +01:00
|
|
|
from rest_framework.generics import RetrieveAPIView, CreateAPIView
|
2020-12-01 18:01:35 +01:00
|
|
|
from rest_framework.permissions import AllowAny
|
|
|
|
from rest_framework.response import Response
|
2020-11-30 22:10:22 +01:00
|
|
|
|
2020-12-01 22:49:16 +01:00
|
|
|
from smartpicasso.app.user.serializers import UserLoginSerializer, UserRegistrationSerializer
|
2020-12-01 18:01:35 +01:00
|
|
|
|
|
|
|
|
|
|
|
class UserLoginView(RetrieveAPIView):
|
|
|
|
"""
|
|
|
|
View for user login
|
|
|
|
"""
|
|
|
|
permission_classes = (AllowAny,)
|
|
|
|
serializer_class = UserLoginSerializer
|
|
|
|
|
|
|
|
def post(self, request):
|
|
|
|
serializer = self.serializer_class(data=request.data)
|
|
|
|
serializer.is_valid(raise_exception=True)
|
|
|
|
response = {
|
|
|
|
'success': 'True',
|
|
|
|
'status_code': status.HTTP_200_OK,
|
|
|
|
'message': 'User logged in successfully',
|
|
|
|
'token': serializer.data['token']
|
|
|
|
}
|
|
|
|
status_code = status.HTTP_200_OK
|
|
|
|
|
|
|
|
return Response(response, status=status_code)
|
2020-12-01 22:49:16 +01:00
|
|
|
|
|
|
|
|
|
|
|
class UserRegistrationView(CreateAPIView):
|
|
|
|
"""
|
|
|
|
View for user registration
|
|
|
|
"""
|
|
|
|
permission_classes = (AllowAny,)
|
|
|
|
serializer_class = UserRegistrationSerializer
|
|
|
|
|
|
|
|
def post(self, request):
|
|
|
|
serializer = self.serializer_class(data=request.data)
|
|
|
|
serializer.is_valid(raise_exception=True)
|
|
|
|
serializer.save()
|
|
|
|
status_code = status.HTTP_201_CREATED
|
|
|
|
response = {
|
|
|
|
'success': 'True',
|
|
|
|
'status_code': status_code,
|
|
|
|
'message': 'User registered successfully'
|
|
|
|
}
|
|
|
|
|
|
|
|
return Response(response, status=status_code)
|