Exemple #1
0
    def post(self, request, *args, **kwargs):

        user_serializer = RegisterSerializer(data=request.data)
        profile_serializer = SellerProfileSerializer(data=request.data)

        user_serializer.is_valid(raise_exception=True)
        profile_serializer.is_valid(raise_exception=True)

        user = user_serializer.save()

        profile = profile_serializer.save(user=user)

        res = {
            "status":
            'success',
            "code":
            status.HTTP_200_OK,
            "message":
            'User registerd successfully',
            "user":
            UserSerializer(user, context=self.get_serializer_context()).data,
            "user_profile":
            SellerProfileSerializer(
                profile, context=self.get_serializer_context()).data,
            "token":
            AuthToken.objects.create(user)[1]
        }

        return Response(res, status=status.HTTP_200_OK)
Exemple #2
0
 def post(self, request):
     data = request.data
     serializer = RegisterSerializer(data=data)
     if serializer.is_valid(raise_exception=True):
         user = serializer.save()
         send_activation_email(user)
         return Response('Account usp soz.', status=status.HTTP_201_CREATED)
 def create(self, request):
     serializer = RegisterSerializer(data=request.data)
     serializer.is_valid(raise_exception=True)
     user, token = serializer.save()
     data = {
         'user': CustomUserSerializer(user).data,
         'access_token': token,
     }
     return Response(data, status=201)
Exemple #4
0
 def register_validated_user(self, *agrs, **kwargs):
     user = RegisterSerializer(data=self.request.data)
     if user.is_valid():
         instance = user.create()
         board_member = self.complete_validation(instance)
         board = Board.active_objects.filter(pk=board_member.board.id)
         serializer = CompletedValidationSerializer(
             board, many=True, context={"user": instance})
         return Response(serializer.data, status=201)
     return Response(serializer.errors, status=400)
Exemple #5
0
 def new_user(self, request, pk=None):
     serializer = RegisterSerializer(data=request.data)
     serializer.is_valid()
     user = User.objects.create_user(
         username=serializer.data.get('username'),
         email=serializer.data.get('email'),
         password=serializer.data.get('password'),
         is_superuser=serializer.data.get('is_superuser'),
         is_staff=serializer.data.get('is_staff'),
         is_active=serializer.data.get('is_active'),
     )
     return Response(self.serializer_class(user, many=False).data)
Exemple #6
0
    def post(self, request, *args, **kwargs):
        serializer = RegisterSerializer(data=request.data)
        if not serializer.is_valid(raise_exception=True):
            return Response({
                "message": "Request Body Error"
                }, status=status.HTTP_409_CONFLICT)

        user = serializer.save()
        
        profile = Profile(user=user, nickname=user.username, introduce="소개를 작성해주세요.")
        profile.save()
        
        response = Response(status=status.HTTP_200_OK)
        response = jwt_login(response=response, user=user)
        return response
Exemple #7
0
    def register(self, request):
        serializer = RegisterSerializer(data=request.data)
        if serializer.is_valid():
            try:
                User.objects.create_user(
                    username=serializer.data.get('username'),
                    password=serializer.data.get('password'),
                    email=serializer.data.get('email'),
                    is_active=True,
                )
            except IntegrityError:
                return Response({'username': ['username sudah terdaftar!']}, status=status.HTTP_400_BAD_REQUEST)

            return Response(serializer.data)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
class ProfileSerializer(serializers.ModelSerializer):
    user = RegisterSerializer(required=True)
    experience = ExperienceSerializer(many=True)
    interests = InterestsSerializer(many=True)

    class Meta:
        model = Profile
        fields = [
            'id', 'experience', 'interests', 'user', 'user_id', 'bio',
            'photo_url', 'location', 'phone_number'
        ]

    def save(self):
        profile = Profile(
            user=self.validated_data('user'),
            bio=self.validated_data('bio'),
            photo_url=self.validated_data('photo_url'),
            location=self.validated_data('location'),
            phone_number=self.validated_data('phone_number'),
        )
        profile.save()
Exemple #9
0
 def post(self, request):
     # """注册用户信息保存"""
     # # ① 获取参数并进行校验
     # req_data = json.loads(request.body.decode())
     # username = req_data.get('username')
     # password = req_data.get('password')
     # password2 = req_data.get('password2')
     # mobile = req_data.get('mobile')
     # allow = req_data.get('allow')
     # sms_code = req_data.get('sms_code')
     #
     # if not all([username, password, password2, mobile, allow, sms_code]):
     #     return JsonResponse({'code': 400,
     #                          'message': '缺少必传参数'})
     serializer = RegisterSerializer(data=request.data)
     serializer.is_valid(raise_exception=True)
     # ② 保存新增用户数据到数据库
     serializer.save()
     return Response(serializer.data, status=201)