Exemplo n.º 1
0
    def authenticate(self, username=None, password=None, **kwargs):
        request = kwargs.pop('request', None)

        if not request:
            raise Exception('Django\'s request is required to authenticate')

        try:
            # Invoke que web service that logs in
            url = generate_service_url('/login')
            data = dict(email=username, password=password)
            data.update(kwargs)

            status, response = invoke_backend_service('POST',
                                                      url,
                                                      json_data=data,
                                                      public=True,
                                                      request=request)
            if status == 200:
                # Create the logged user and set its attributes
                user = self._create_user(request.user.pk, response)
                cache.set(request.user.pk, user.to_dict())
                return user
            elif status == 204:
                raise Exception('Web service did not return a valid user')
            elif status == 400 or status == 500:
                raise Exception(response[proxy_server.ERROR][
                    proxy_server.MESSAGE].encode('utf8'))
            else:
                raise Exception('Authentication error')

        except Exception as e:
            raise Exception(str(e))
Exemplo n.º 2
0
    def test_invoke_backend_service(self):
        service_url = generate_service_url('/login')
        response = invoke_backend_service('POST', service_url, json_data={ 'email': '*****@*****.**', 'password': '******' })
        print('Invoke backend response 200: ', response)

        try:
            invoke_backend_service('POST', service_url, json_data={ 'email': '*****@*****.**' })
        except Exception as e:
            print('Invoke backend response 500: ', str(e))
Exemplo n.º 3
0
def test(request):
    service_url = generate_service_url('/login')
    return invoke_backend_service_as_proxy(request,
                                           'POST',
                                           service_url,
                                           json_data={
                                               'email': '*****@*****.**',
                                               'password': '******'
                                           })
Exemplo n.º 4
0
    def test_invoke_backend_service(self):
        service_url = generate_service_url('/login')
        response = invoke_backend_service('POST', service_url, json_data={ 'email':'*****@*****.**', 'password':'******' })
        print 'Invoke backend response 200: ', response

        try:
            invoke_backend_service('POST', service_url, json_data={ 'email':'*****@*****.**' })
        except Exception as e:
            print 'Invoke backend response 500: ', str(e)
Exemplo n.º 5
0
def test_token_validation(request):
    service_url = generate_service_url('/login')
    response = invoke_backend_service_as_proxy(request,
                                               'POST',
                                               service_url,
                                               json_data={
                                                   'email': '*****@*****.**',
                                                   'password': '******'
                                               })
    print('Views:', response)
def renew_session(request):
    response = invoke_backend_service_as_proxy(request, 'POST', generate_service_url('/renew_session'), response_token=True)
    return response