Merge branch 'master' into feature/tests

This commit is contained in:
Hubert Jankowski 2021-12-12 23:08:15 +01:00
commit 0cb5d80134
3 changed files with 45 additions and 2 deletions

View File

@ -5,6 +5,34 @@ from users import cons
from tools.tools import decode_uid, encode_uid from tools.tools import decode_uid, encode_uid
class RegisterSerializer(serializers.ModelSerializer):
password = serializers.CharField(
write_only=True,
required=False,
min_length=8,
style={"input_type": "password"},
)
email = serializers.CharField(
write_only=True
)
first_name = serializers.CharField(
write_only=True
)
last_name = serializers.CharField(
write_only=True
)
#todo
# avatar = serializers.ImageField(allow_empty_file=True, source="profile.avatar", read_only=True)
class Meta:
model = User
fields = (
"email",
"first_name",
"last_name",
"password"
)
class UserSerializer(serializers.ModelSerializer): class UserSerializer(serializers.ModelSerializer):
password = serializers.CharField( password = serializers.CharField(

View File

@ -4,14 +4,16 @@ from django.urls import path
from users.views import UserModelViewSet from users.views import UserModelViewSet
from rest_framework_simplejwt.views import TokenObtainPairView from rest_framework_simplejwt.views import TokenObtainPairView
from rest_framework_simplejwt.views import TokenRefreshView from rest_framework_simplejwt.views import TokenRefreshView
from .views import PasswordReset, UserPasswordResetConfirmView from .views import PasswordReset, UserPasswordResetConfirmView, RegisterViewSet
router = DefaultRouter(trailing_slash=False) router = DefaultRouter(trailing_slash=False)
router.register("items", UserModelViewSet) router.register("items", UserModelViewSet)
# router.register("register", RegisterViewSet, basename="pyk")
urlpatterns = [ urlpatterns = [
path("", include(router.urls)), path("", include(router.urls)),
path('register', RegisterViewSet.as_view(), name='register'),
path('api/token', TokenObtainPairView.as_view(), name='token_obtain_pair'), path('api/token', TokenObtainPairView.as_view(), name='token_obtain_pair'),
path('api/token/refresh', TokenRefreshView.as_view(), name='token_refresh'), path('api/token/refresh', TokenRefreshView.as_view(), name='token_refresh'),
path("password/reset", PasswordReset.as_view()), path("password/reset", PasswordReset.as_view()),

View File

@ -5,7 +5,8 @@ from users.serializers import UserSerializer
from rest_framework import views, exceptions, status, viewsets, permissions, generics from rest_framework import views, exceptions, status, viewsets, permissions, generics
from tools.tools import PasswordResetShortcut, PasswordResetConfirmShortcut from tools.tools import PasswordResetShortcut, PasswordResetConfirmShortcut
from django.contrib.auth.tokens import default_token_generator from django.contrib.auth.tokens import default_token_generator
from .serializers import UserPasswordResetSerializer, UserPasswordResetConfirmSerializer from .serializers import UserPasswordResetSerializer, UserPasswordResetConfirmSerializer, RegisterSerializer
from rest_framework.response import Response
class UserModelViewSet(viewsets.ModelViewSet): class UserModelViewSet(viewsets.ModelViewSet):
@ -13,6 +14,18 @@ class UserModelViewSet(viewsets.ModelViewSet):
serializer_class = UserSerializer 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): class PasswordReset(PasswordResetShortcut, generics.GenericAPIView):
""" """
```json ```json