Example #1
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)
        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
Example #2
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)
     login(request, user)
     return JsonResponse(UserSerializer(user).data)
Example #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')
     })