Exemplo n.º 1
0
    def pipeline(self, pipeline, *args, **kwargs):
        """Pipeline"""
        out = kwargs.copy()

        if 'pipeline_index' in kwargs:
            base_index = int(kwargs['pipeline_index'])
        else:
            base_index = 0

        for idx, name in enumerate(pipeline):
            out['pipeline_index'] = base_index + idx
            mod_name, func_name = name.rsplit('.', 1)
            try:
                mod = import_module(mod_name)
            except ImportError:
                log('exception', 'Error importing pipeline %s', name)
            else:
                func = getattr(mod, func_name, None)

                if callable(func):
                    try:
                        result = func(*args, **out) or {}
                    except StopPipeline:
                        # Clean partial pipeline on stop
                        if 'request' in kwargs:
                            clean_partial_pipeline(kwargs['request'])
                        break

                    if isinstance(result, dict):
                        out.update(result)
                    else:
                        return result
        return out
Exemplo n.º 2
0
    def pipeline(self, pipeline, *args, **kwargs):
        """Pipeline"""
        out = kwargs.copy()

        if 'pipeline_index' in kwargs:
            base_index = int(kwargs['pipeline_index'])
        else:
            base_index = 0

        for idx, name in enumerate(pipeline):
            out['pipeline_index'] = base_index + idx
            mod_name, func_name = name.rsplit('.', 1)
            try:
                mod = import_module(mod_name)
            except ImportError:
                log('exception', 'Error importing pipeline %s', name)
            else:
                func = getattr(mod, func_name, None)

                if callable(func):
                    try:
                        result = func(*args, **out) or {}
                    except StopPipeline:
                        # Clean partial pipeline on stop
                        if 'request' in kwargs:
                            clean_partial_pipeline(kwargs['request'])
                        break

                    if isinstance(result, dict):
                        out.update(result)
                    else:
                        return result
        return out
Exemplo n.º 3
0
def auth_process(request, backend):
    """Authenticate using social backend"""
    # Save any defined next value into session
    data = request.POST if request.method == 'POST' else request.GET
    if REDIRECT_FIELD_NAME in data:
        # Check and sanitize a user-defined GET/POST next field value
        redirect = data[REDIRECT_FIELD_NAME]
        if setting('SOCIAL_AUTH_SANITIZE_REDIRECTS', True):
            redirect = sanitize_redirect(request.get_host(), redirect)
        request.session[REDIRECT_FIELD_NAME] = redirect or DEFAULT_REDIRECT

    # Clean any partial pipeline info before starting the process
    clean_partial_pipeline(request)

    if backend.uses_redirect:
        return HttpResponseRedirect(backend.auth_url())
    else:
        return HttpResponse(backend.auth_html(),
                            content_type='text/html;charset=UTF-8')