55 lines
1.7 KiB
Python
55 lines
1.7 KiB
Python
from rest_framework import viewsets
|
|
|
|
from users.models import User
|
|
from users.serializers import UserSerializer
|
|
from rest_framework import views, exceptions, status, viewsets, permissions, generics
|
|
from tools.tools import PasswordResetShortcut, PasswordResetConfirmShortcut
|
|
from django.contrib.auth.tokens import default_token_generator
|
|
from .serializers import UserPasswordResetSerializer, UserPasswordResetConfirmSerializer, RegisterSerializer
|
|
from rest_framework.response import Response
|
|
|
|
|
|
class UserModelViewSet(viewsets.ModelViewSet):
|
|
queryset = User.objects.all()
|
|
serializer_class = UserSerializer
|
|
|
|
|
|
class RegisterViewSet(generics.GenericAPIView):
|
|
serializer_class = RegisterSerializer
|
|
permission_classes = (permissions.AllowAny, )
|
|
|
|
def post(self, request):
|
|
serializer = self.get_serializer(data=request.data)
|
|
if serializer.is_valid():
|
|
return Response({"detail": "Done"}, status=status.HTTP_200_OK)
|
|
else:
|
|
return Response(data=serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
|
|
|
|
|
class PasswordReset(PasswordResetShortcut, generics.GenericAPIView):
|
|
"""
|
|
```json
|
|
{
|
|
"email": "testowymail@gmail.com"
|
|
}
|
|
```
|
|
"""
|
|
serializer_class = UserPasswordResetSerializer
|
|
permission_classes = (permissions.AllowAny, )
|
|
|
|
|
|
class UserPasswordResetConfirmView(PasswordResetConfirmShortcut, generics.GenericAPIView):
|
|
"""
|
|
```json
|
|
{
|
|
"uid": "NYz",
|
|
"token": "asdasdasd",
|
|
"code": 123456,
|
|
"newPassword": "testowe",
|
|
"repeatNewPassword": "testowe"
|
|
}
|
|
```
|
|
"""
|
|
serializer_class = UserPasswordResetConfirmSerializer
|
|
permission_classes = (permissions.AllowAny, )
|
|
token_generator = default_token_generator |