コード例 #1
0
def registration(request):
    if request.method == 'POST':
        user_data = request.data
        serializer = RegisterSerializer(data=user_data)
        serializer.is_valid(raise_exception=True)
        serializer.save()
        return Response(serializer.data, status=HTTP_201_CREATED)
コード例 #2
0
 def post(self, request):
     serializer = RegisterSerializer(data=request.data)
     serializer.is_valid(raise_exception=True)
     serializer.save()
     return response.Response(
         status=status.HTTP_201_CREATED,
         data=serializer.data,
     )
コード例 #3
0
def register(request):
    if request.method == 'POST':
        data = JSONParser().parse(request)
        username = data['email'].split('@')[0]
        data['username'] = username

        serializer = RegisterSerializer(data=data)
        if serializer.is_valid():
            serializer.save()
            Response = {
                "id": serializer.data['id'],
                "token": serializer.data['token']
            }
            return JsonResponse(Response)
        return HttpResponse(status=404)
コード例 #4
0
ファイル: views.py プロジェクト: YliaMyk/manager
def register(request):
    serializer = RegisterSerializer(data=request.data)
    serializer.is_valid(raise_exception=True)
    user = serializer.save()
    return Response({
        "message":
        "User Created Successfully.  Now perform Login to get your token",
    })
コード例 #5
0
ファイル: views.py プロジェクト: viocuong/ktgt
 def post(self, request):
     serializer = RegisterSerializer(data=request.data)
     data = {}
     if serializer.is_valid():
         person = serializer.save()
         data['response'] = ['success']
     else:
         data = serializer.errors
     return Response(data)
コード例 #6
0
ファイル: register_view.py プロジェクト: MikaSoftware/mikaid
    def post(self, request):
        # Save our code and return the serialized data.
        serializer = RegisterSerializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        data = serializer.save()

        # Get the newly created user from the registration.
        authenticated_user = data['user']

        # Get our web application authorization.
        application = Application.objects.filter(
            name=settings.MIKAID_RESOURCE_SERVER_NAME).first()

        # Generate our access token which does not have a time limit.
        aware_dt = timezone.now()
        expires_dt = aware_dt.replace(aware_dt.year + 1776)
        access_token, created = AccessToken.objects.update_or_create(
            application=application,
            user=authenticated_user,
            defaults={
                'user': authenticated_user,
                'application': application,
                'expires': expires_dt,
                'token': generate_token(),
                'scope': 'read,write,introspection'
            },
            scope='read,write,introspection')

        # Return our new token.
        return Response(
            data={
                # --- REQUIRED --- #
                'token': str(access_token),
                'scope': access_token.scope,

                # --- OPTIONAL --- #
                "client_id": access_token.user.id,
                "email": access_token.user.email,
                # "exp": int(format(access_token.expires, 'U'))
                "exp": access_token.expires,
            },
            status=status.HTTP_201_CREATED)
コード例 #7
0
 def post(self, request, format=None):
     serializer = RegisterSerializer(data=request.data)
     if serializer.is_valid():
         token = serializer.save()
         return Response({'token': token}, status=status.HTTP_201_CREATED)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)