Esempio n. 1
0
 def post(request: Request):
     if not request.user.is_authenticated:
         return NotAuthenticatedResponse()
     serial = CollectionGeneralInfo(data=request.data)
     if serial.is_valid():
         serial.save()
         return OKResponse(serial.data)
     else:
         return BadRequestResponse(serial.errors)
Esempio n. 2
0
 def delete(request, collection_id):
     if not request.user.is_authenticated:
         return NotAuthenticatedResponse()
     if not (collection := find_collection(collection_id)):
         return NotFoundResponse("collection", collection_id.__str__())
Esempio n. 3
0
 def get(request, collection_id):
     if not request.user.is_authenticated:
         return NotAuthenticatedResponse()
     if not (collection := find_collection(collection_id)):
         return NotFoundResponse('collection', collection_id)
Esempio n. 4
0
 def get(request):
     if request.user.is_authenticated:
         serial = CollectionGeneralInfo(Collection.objects.all(), many=True)
         return OKResponse(serial.data)
     else:
         return NotAuthenticatedResponse()
Esempio n. 5
0
from note.responses import NotAuthenticatedResponse, OKResponse, BadRequestResponse


class __RequestToken(APIView):
    @staticmethod
    def get(request: Request):
        if (r_user := request.user).is_authenticated:
            try:
                inv_token = InvitationToken.objects.get(user=r_user)
            except:
                t = uuid.uuid4().__str__().lower()
                inv_token = InvitationToken.objects.create(token=t,
                                                           user=r_user)
            return OKResponse(data={"token": inv_token.token})
        else:
            return NotAuthenticatedResponse()


class __RegisterAPIView(APIView):
    @staticmethod
    def post(request: Request):
        try:
            inv_token: str = request.data.get('inv_code')
            errors = []
            if not inv_token:
                errors.append("invitation token not valid")

            username: str = request.data.get('username')
            if not username:
                errors.append("username not valid")