Ejemplo n.º 1
0
def login_user(request):

    success = False
    auth_backend = RequestParamsClientBackend()
    client = auth_backend.authenticate(request)

    if client:
        if request.method == "POST":

            user = authenticate(email=request.POST['email'], password=request.POST['password'])
            if user is not None:
                if user.is_active:
                    # Redirect to a success page.
                    token = AccessToken.objects.create(
                        user=user,
                        client=client,
                        scope=provider.scope.to_int(request.POST['scope'])
                    )

                    success = True

                    token_view = AccessTokenView()

                    return token_view.access_token_response(token)
                else:
                    # Return a 'disabled account' error message
                    success = 'False - Account disabled'
            else:
                # Return an 'invalid login' error message.
                success = 'False - Invalid login'

    return render_to_response('success.json', {
        'success': success,
    }, context_instance=RequestContext(request))
Ejemplo n.º 2
0
def register_user(request):

    success = False
    auth_backend = RequestParamsClientBackend()
    client = auth_backend.authenticate(request)

    if client:
        if request.method == "POST":

            if QualiaUser.objects.filter(email=request.POST['email']).count():
                success = 'False - Email exists'

            else:
                user = QualiaUser.objects.create_user(request.POST['email'], request.POST['password'])
                token = AccessToken.objects.create(
                    user=user,
                    client=client,
                    scope=provider.scope.to_int(request.POST['scope'])
                )
                success = True

                token_view = AccessTokenView()

                return token_view.access_token_response(token)

    return render_to_response('success.json', {
        'success': success,
    }, context_instance=RequestContext(request))
Ejemplo n.º 3
0
def login_user(request):

    success = False
    auth_backend = RequestParamsClientBackend()
    client = auth_backend.authenticate(request)

    if client:
        if request.method == "POST":

            user = authenticate(email=request.POST['email'],
                                password=request.POST['password'])
            if user is not None:
                if user.is_active:
                    # Redirect to a success page.
                    token = AccessToken.objects.create(
                        user=user,
                        client=client,
                        scope=provider.scope.to_int(request.POST['scope']))

                    success = True

                    token_view = AccessTokenView()

                    return token_view.access_token_response(token)
                else:
                    # Return a 'disabled account' error message
                    success = 'False - Account disabled'
            else:
                # Return an 'invalid login' error message.
                success = 'False - Invalid login'

    return render_to_response('success.json', {
        'success': success,
    },
                              context_instance=RequestContext(request))
Ejemplo n.º 4
0
def register_user(request):

    success = False
    auth_backend = RequestParamsClientBackend()
    client = auth_backend.authenticate(request)

    if client:
        if request.method == "POST":

            if QualiaUser.objects.filter(email=request.POST['email']).count():
                success = 'False - Email exists'

            else:
                user = QualiaUser.objects.create_user(request.POST['email'],
                                                      request.POST['password'])
                token = AccessToken.objects.create(user=user,
                                                   client=client,
                                                   scope=provider.scope.to_int(
                                                       request.POST['scope']))
                success = True

                token_view = AccessTokenView()

                return token_view.access_token_response(token)

    return render_to_response('success.json', {
        'success': success,
    },
                              context_instance=RequestContext(request))
Ejemplo n.º 5
0
    def test_backends_disallow_get(self):
        self.assertIsNone(RequestParamsClientBackend().authenticate(None))

        auth = {
            'client_id': self.get_client().client_id,
            'client_secret': self.get_client().client_secret
        }
        factory = RequestFactory()
        request = factory.get('', auth)

        self.assertIsNone(RequestParamsClientBackend().authenticate(request))
        self.assertIsNone(PublicPasswordBackend().authenticate(request))
Ejemplo n.º 6
0
    def test_request_params_client_backend(self):
        request = type('Request', (object, ), {'REQUEST': {}})()

        request.REQUEST['client_id'] = self.get_client().client_id
        request.REQUEST['client_secret'] = self.get_client().client_secret

        self.assertEqual(RequestParamsClientBackend().authenticate(request).id,
                         2, "Didn't return the right client.'")
Ejemplo n.º 7
0
    def test_request_params_client_backend(self):
        factory = RequestFactory()
        auth = {
            'client_id': self.get_client().client_id,
            'client_secret': self.get_client().client_secret
        }
        request = factory.post('', auth)

        self.assertEqual(RequestParamsClientBackend().authenticate(request).id,
                         2, "Didn't return the right client.'")