示例#1
0
 def post(self, request, format=None):
     serializer = UserSerializer(data=request.data)
     if serializer.is_valid(raise_exception=True):
         user = User.objects.get(username=serializer.data['username'])
         token, created = Token.objects.get_or_create(user=user)
         return Response({'Token': token.key}, 200)
     return Response({'error': 'idl'})
示例#2
0
    def post(self, request):
        # serializer = UserSerializer(data = request.data)
        response, is_valid = UserSerializer.validate(self, data=request.data)
        if is_valid:
            response = UserSerializer.create(self, Validated_data=response)

        return Response(response, status=200)
示例#3
0
    def post(self, request, *args, **kwargs):
        user = request.data
        serializer = UserSerializer(data=user)
        if serializer.is_valid(raise_exception=True):
            serializer.save()

        return Response(
            {"success": "User '{}' created successfully".format(user["name"])},
            status=201)
def current_user(request):
    """
    Determine the current user by their token, and return their data
    """

    serializer = UserSerializer(request.user)
    print(serializer.data)
    return Response(serializer.data)
示例#5
0
def setupNewPlayer(request):

    plantae = Unit()
    plantae.name = "Plantae"
    plantae.kingdom = 1
    plantae.save()
    request.user.units.add(plantae)

    cx = Cx()
    # 나중에 유일한 렌덤값을 생성하도록 고치자.
    cx.name = "B" + "%07d" % random.randint(0, 9999999)
    cx.owner = plantae
    cx.save()
    request.user.cxs.add(cx)

    animalia = Unit()
    animalia.name = "Animalia"
    animalia.kingdom = 0
    animalia.save()
    request.user.units.add(animalia)

    return JsonResponse({'data': UserSerializer(request.user).data})
示例#6
0
def setupCx(request):

    request.user.curCx_id = request.POST['curCxDBID']
    request.user.curUnit_id = request.POST['curUnitDBID']

    return JsonResponse({'data': UserSerializer(request.user).data})
示例#7
0
def user(request):
    return JsonResponse(UserSerializer(request.user).data)
示例#8
0
 def get(self, request, *args, **kwargs):
     users = User.objects.all()
     serializer = UserSerializer(users, many=True)
     return Response({"Users": serializer.data}, status=200)
def get(self, request, format=None):
    users = User.objects.all()
    serializer = UserSerializer(users, many=True)
    return Response(serializer.data)