Registration #16
@ -23,7 +23,7 @@ urlpatterns = [
|
|||||||
path('login', login),
|
path('login', login),
|
||||||
path('logout', logout),
|
path('logout', logout),
|
||||||
path('register', register),
|
path('register', register),
|
||||||
path('users', include("users.urls")),
|
path('users/', include("users.urls")),
|
||||||
path('questions/', include("questions.urls")),
|
path('questions/', include("questions.urls")),
|
||||||
path('answers/', include("answers.urls")),
|
path('answers/', include("answers.urls")),
|
||||||
path('tests/', include("trials.urls")),
|
path('tests/', include("trials.urls")),
|
||||||
|
@ -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(
|
||||||
|
@ -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()),
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user