コード例 #1
0
ファイル: views.py プロジェクト: gitfunded/middleware
    def post(self, request):
        public_address = request.data.get('public_address', '')
        signature = request.data.get('signature', '')
        user = authenticate(public_address=public_address, signature=signature)
        if not user:
            return HttpResponse('Unauthorized', status=401)
        jwt_token = loginJWT(request, user)
        expires = datetime.datetime.utcnow() + datetime.timedelta(seconds=max_age)
        cookie_value = 'Bearer {}'.format(
            jwt_token.decode('utf-8'))

        response = JsonResponse({
            'user': UserSerializer(user).data,
            'token': cookie_value
        })

        response.set_cookie(
            'Authorization',
            domain=settings.SESSION_COOKIE_DOMAIN,
            value=cookie_value,
            secure=False, httponly=False, expires=expires
        )

        login(request, user)
        return response
コード例 #2
0
ファイル: views.py プロジェクト: iamonuwa/BountiesAPI
 def post(self, request):
     public_address = request.data.get('public_address', '')
     signature = request.data.get('signature', '')
     user = authenticate(public_address=public_address, signature=signature)
     if not user:
         return HttpResponse('Unauthorized', status=401)
     login(request, user)
     return JsonResponse(UserSerializer(user).data)
コード例 #3
0
 def post(self, request):
     public_address = request.data.get('public_address', '')
     signature = request.data.get('signature', '')
     user = authenticate(public_address=public_address, signature=signature)
     if not user:
         return HttpResponse('Unauthorized', status=401)
     jwt_token = loginJWT(request, user)
     return JsonResponse({
         'user': UserSerializer(user).data,
         'token': jwt_token.decode('utf-8')
     })