Exemplo n.º 1
0
 def post(self, request, *args, **kwargs):
     user_data = request.data
     user = UserModelSerializer(data=user_data)
     print('注册用户', user, type(user))
     user.is_valid(raise_exception=True)
     user.save()
     return MyResponse(200, '注册用户成功')
Exemplo n.º 2
0
    def post(self, request, *args, **kwargs):
        user_ser = UserModelSerializer(data=request.data)
        user_ser.is_valid(raise_exception=True)

        return APIResponse(data_message="ok",
                           token=user_ser.token,
                           results=UserModelSerializer(user_ser.obj).data)
Exemplo n.º 3
0
def register(request):
    serializer = UserModelSerializer(data=request.data)
    if serializer.is_valid():
        if serializer.is_valid():
            user = serializer.save()
            if user:
                return Response(serializer.data,
                                status=status.HTTP_201_CREATED)
Exemplo n.º 4
0
    def post(self, request, *args, **kwargs):
        request_data = request.data
        print(request_data)
        serializer = UserModelSerializer(data=request_data)
        serializer.is_valid(raise_exception=True)
        user_obj = serializer.save()

        return APIResponse(200,
                           True,
                           results=UserModelSerializer(user_obj).data)
Exemplo n.º 5
0
 def post(self, request, *args, **kwargs):
     request_data = request.data
     ums = UserModelSerializer(
         data=request_data,
         context={"request": request},
     )
     ums.is_valid(raise_exception=True)
     ums_save = ums.save()
     ums_data = UserModelSerializer(ums_save).data
     return APIResponse(200, True, results=ums_data)
Exemplo n.º 6
0
    def post(self, request, *args, **kwargs):
        # 账号使用account  密码使用pwd
        # account = request.data.get("account")
        # pwd = request.data.get("pwd")
        user_ser = UserModelSerializer(data=request.data)
        user_ser.is_valid(raise_exception=True)

        return APIResponse(data_message="ok",
                           token=user_ser.token,
                           results=UserModelSerializer(user_ser.obj).data)
Exemplo n.º 7
0
 def post(self, request, *args, **kwargs):
     # 账号:account(手机号|邮箱|用户名)  密码:passwords
     # 反序列化
     user_ser = UserModelSerializer(data=request.data)
     # 校验信息,错误则返回异常信息
     user_ser.is_valid(raise_exception=True)
     # 返回结果
     return APIResponse(
         data_message="ok",
         token=user_ser.token,
         results=UserModelSerializer(user_ser.obj).data)
Exemplo n.º 8
0
 def post(self, request, *args, **kwargs):
     # 前端用户注册请求的处理
     data = request.data
     if data['password'] != data['passwords']:
         return APIResponse(201, False)
     serializer = UserModelSerializer(data=data)
     serializer.is_valid(raise_exception=True)
     user_obj = serializer.save()
     return APIResponse(200,
                        True,
                        results=UserModelSerializer(user_obj).data)
Exemplo n.º 9
0
    def post(self, request, *args, **kwargs):
        # 账号为user,密码为password(通过前端传递)
        # user = request.data.get("user")
        # password = request.data.get("password")

        user_ser = UserModelSerializer(data=request.data)
        user_ser.is_valid(raise_exception=True)

        return APIResponse(data_message="成功",
                           token=user_ser.token,
                           results=UserModelSerializer(user_ser.obj).data)
Exemplo n.º 10
0
    def user_register(self, request, *args, **kwargs):
        request_data = request.data
        serializer = UserModelSerializer(data=request_data, many=False)
        serializer.is_valid(raise_exception=True)
        user_obj = serializer.save()
        # print("注册成功")

        # if user:
        return Response({
            "status":
            200,
            "message":
            '添加成功',
            "results":
            UserModelSerializer(user_obj, many=False).data,
        })
Exemplo n.º 11
0
 def post(self, request, *args, **kwargs):
     request_data = request.data
     print(request_data)
     print(request_data.get("password"), request_data.get("re_password"))
     pwd = request_data.get("password")
     re_pwd = request_data.get("re_password")
     if pwd == re_pwd:
         serializer = UserModelSerializer(data=request_data)
         serializer.is_valid(raise_exception=True)
         user_obj = serializer.save()
         return APIResponse(200,
                            True,
                            results=UserModelSerializer(user_obj).data)
     return APIResponse(
         400,
         False,
     )
Exemplo n.º 12
0
def register(request):
    serializer = UserModelSerializer(data=request.data)
    if serializer.is_valid():
        User.objects.get(request.data.get('username'),
                         request.data.get('email'),
                         request.data.get('password'))
        return Response(serializer.data, status=status.HTTP_201_CREATED)
    else:
        return Response(serializer.data, status=status.HTTP_400_BAD_REQUEST)
Exemplo n.º 13
0
    def post(self, request, *args, **kwargs):
        """
        前端注册用户请求的处理
        :param request:
        :param args:
        :param kwargs:
        :return:
        """

        request_data = request.data
        serializer = UserModelSerializer(data=request_data)
        serializer.is_valid(raise_exception=True)
        user_obj = serializer.save()
        print(request_data)

        return APIResponse(200,
                           True,
                           results=UserModelSerializer(user_obj).data)
Exemplo n.º 14
0
    def put(self, request, id, format=None):
        if id == request.user.id:
            user = self.get_object(id=id)
        else:
            return Response({'detail': 'ID do usuário inválido'},
                            status=status.HTTP_401_UNAUTHORIZED)

        serializer = UserModelSerializer(user, data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)