• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python utils.sanitize_redirect函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中social_auth.utils.sanitize_redirect函数的典型用法代码示例。如果您正苦于以下问题:Python sanitize_redirect函数的具体用法?Python sanitize_redirect怎么用?Python sanitize_redirect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了sanitize_redirect函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: auth_process

def auth_process(request, backend):
    """Authenticate using social backend"""
    print(backend)
    data = request.POST if request.method == 'POST' else request.GET

    # Save extra data into session.
    for field_name in setting('SOCIAL_AUTH_FIELDS_STORED_IN_SESSION', []):
        if field_name in data:
            request.session[field_name] = data[field_name]

    # Save any defined next value into session
    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')
开发者ID:jbau,项目名称:django-social-auth,代码行数:25,代码来源:views.py


示例2: auth_process

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).dict()
    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:
        query = urlencode(data)
        auth_url = backend.auth_url(data.get('extra_scope', ''))

        if query:
            auth_url += "&" + query

        return HttpResponseRedirect(auth_url)
    else:
        return HttpResponse(backend.auth_html(),
                            content_type='text/html;charset=UTF-8')
开发者ID:Bunch,项目名称:django-social-auth,代码行数:25,代码来源:views.py


示例3: auth_process

def auth_process(request, backend):
    """Authenticate using social backend"""
    # Added by Mike:
    # Save any query parameters into session.
    data = request.POST if request.method == 'POST' else request.GET
    for key, value in data.items():
        request.session[key] = value 

    # 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')
开发者ID:idonethis,项目名称:django-social-auth,代码行数:25,代码来源:views.py


示例4: auth_process

def auth_process(request, backend, complete_url_name):
    """Authenticate using social backend"""
    redirect = reverse(complete_url_name, args=(backend,))
    backend = get_backend(backend, request, redirect)
    if not backend:
        return HttpResponseServerError('Incorrect authentication service')
    # Check and sanitize a user-defined GET/POST redirect_to field value.
    redirect = sanitize_redirect(request.get_host(),
                                 request.REQUEST.get(REDIRECT_FIELD_NAME))
    error_redirect = sanitize_redirect(request.get_host(),
                                 request.REQUEST.get(ERROR_REDIRECT_FIELD_NAME))
    request.session[REDIRECT_FIELD_NAME] = redirect or DEFAULT_REDIRECT
    request.session[ERROR_REDIRECT_FIELD_NAME] = error_redirect or ERROR_DEFAULT_REDIRECT
    
    if backend.uses_redirect:
        return HttpResponseRedirect(backend.auth_url())
    else:
        return HttpResponse(backend.auth_html(),
                            content_type='text/html;charset=UTF-8')
开发者ID:certator,项目名称:django-social-auth,代码行数:19,代码来源:views.py


示例5: auth_process

def auth_process(request, backend):
    """Authenticate using social backend"""
    # Save any defined redirect_to value into session
    if REDIRECT_FIELD_NAME in request.REQUEST:
        data = request.POST if request.method == "POST" else request.GET
        if REDIRECT_FIELD_NAME in data:
            # Check and sanitize a user-defined GET/POST redirect_to field value.
            redirect = sanitize_redirect(request.get_host(), data[REDIRECT_FIELD_NAME])
            request.session[REDIRECT_FIELD_NAME] = redirect or DEFAULT_REDIRECT

    if backend.uses_redirect:
        return HttpResponseRedirect(backend.auth_url())
    else:
        return HttpResponse(backend.auth_html(), content_type="text/html;charset=UTF-8")
开发者ID:szaboat,项目名称:django-social-auth,代码行数:14,代码来源:views.py


示例6: complete_process

def complete_process(request, backend, *args, **kwargs):
    """Authentication complete process"""
    user = auth_complete(request, backend, *args, **kwargs)
    
    redirect_value = request.session.pop(REDIRECT_FIELD_NAME, '')

    # this is added for FB client-side auth which POSTs to this view directly with an access_token
    if REDIRECT_FIELD_NAME in request.REQUEST:
        data = request.POST if request.method == 'POST' else request.GET
        if REDIRECT_FIELD_NAME in data:
            redirect = data[REDIRECT_FIELD_NAME]
            if SANITIZE_REDIRECTS:
                redirect = sanitize_redirect(request.get_host(), redirect)
            if redirect:
                redirect_value = redirect

    if isinstance(user, HttpResponse):
        return user

    if user:
        if getattr(user, 'is_active', True):
            login(request, user)
            messages.success(request, 'Awesome, you are now logged in!')
            # user.social_user is the used UserSocialAuth instance defined
            # in authenticate process
            social_user = user.social_user

            if SESSION_EXPIRATION :
                # Set session expiration date if present and not disabled by
                # setting. Use last social-auth instance for current provider,
                # users can associate several accounts with a same provider.
                if social_user.expiration_delta():
                    request.session.set_expiry(social_user.expiration_delta())

            # store last login backend name in session
            request.session[SOCIAL_AUTH_LAST_LOGIN] = social_user.provider

            # Remove possible redirect URL from session, if this is a new
            # account, send him to the new-users-page if defined.
            url = NEW_USER_REDIRECT if NEW_USER_REDIRECT and \
                                       getattr(user, 'is_new', False) else \
                  redirect_value or \
                  DEFAULT_REDIRECT
        else:
            url = INACTIVE_USER_URL or LOGIN_ERROR_URL
    else:
        if ERROR_MESSAGE:
            messages.error(request, ERROR_MESSAGE)
        url = LOGIN_ERROR_URL
    return HttpResponseRedirect(url)
开发者ID:dolbeau,项目名称:django-social-auth,代码行数:50,代码来源:views.py


示例7: auth_process

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

    if backend.uses_redirect:
        return HttpResponseRedirect(backend.auth_url())
    else:
        return HttpResponse(backend.auth_html(),
                            content_type='text/html;charset=UTF-8')
开发者ID:FrankBie,项目名称:django-social-auth,代码行数:16,代码来源:views.py


示例8: auth_process

def auth_process(request, backend, complete_url_name):
    """Authenticate using social backend"""
    redirect = reverse(complete_url_name, args=(backend,))
    backend = get_backend(backend, request, redirect)
    if not backend:
        return HttpResponseServerError('Incorrect authentication service')

    # Save any defined redirect_to value into session
    if REDIRECT_FIELD_NAME in request.REQUEST:
        data = request.POST if request.method == 'POST' else request.GET
        if REDIRECT_FIELD_NAME in data:
            # Check and sanitize a user-defined GET/POST redirect_to field value.
            redirect = sanitize_redirect(request.get_host(),
                                         data[REDIRECT_FIELD_NAME])
            request.session[REDIRECT_FIELD_NAME] = redirect or DEFAULT_REDIRECT

    if backend.uses_redirect:
        return HttpResponseRedirect(backend.auth_url())
    else:
        return HttpResponse(backend.auth_html(),
                            content_type='text/html;charset=UTF-8')
开发者ID:cid2105,项目名称:greek_gavel,代码行数:21,代码来源:views.py


示例9: auth_process

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
    for field in data:
        if field == REDIRECT_FIELD_NAME:
            # 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
        else:
            request.session[field] = data[field]

    # 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")
开发者ID:arnaudbreton,项目名称:django-social-auth,代码行数:21,代码来源:views.py


示例10: auth_process

def auth_process(request, backend, complete_url_name):
    """Authenticate using social backend"""
    redirect = reverse(complete_url_name, args=(backend,))
    backend = get_backend(backend, request, redirect)
    if not backend:
        return HttpResponseServerError('Incorrect authentication service')
    data = request.REQUEST
    # Check and sanitize a user-defined GET/POST redirect_to field value.
    redirect = sanitize_redirect(request.get_host(), data.get(REDIRECT_FIELD_NAME))
    try:
        request.session[REDIRECT_FIELD_NAME] = redirect or DEFAULT_REDIRECT
        if backend.uses_redirect:
            return HttpResponseRedirect(backend.auth_url())
        else:
            return HttpResponse(backend.auth_html(),
                            content_type='text/html;charset=UTF-8')
    except ValueError, e:
        error_key = getattr(settings, 'SOCIAL_AUTH_ERROR_KEY', None)
        if error_key:  # store error in session
            request.session[error_key] = str(e)
        url = getattr(settings, 'LOGIN_ERROR_URL', settings.LOGIN_URL)
        return HttpResponseRedirect(url)
开发者ID:nwalker,项目名称:django-social-auth,代码行数:22,代码来源:views.py


示例11: auth_process

def auth_process(request, backend, complete_url_name):
    """Authenticate using social backend"""
    redirect = reverse(complete_url_name, args=(backend,))
    backend = get_backend(backend, request, redirect)
    if not backend:
        return HttpResponseServerError('Incorrect authentication service')

    # Check and sanitize a user-defined GET/POST redirect_to field value.
    redirect = sanitize_redirect(request.get_host(),
                                 request.REQUEST.get(REDIRECT_FIELD_NAME))

    request.session[REDIRECT_FIELD_NAME] = redirect

    # Store query parameters (if any). These will be tacked on to the end of
    # the login redirect url in complete_process().
    all_params = dict(parse_qsl(request.META['QUERY_STRING']))
    params = [(k, v) for k, v in all_params.items() if not k == REDIRECT_FIELD_NAME]
    request.session[REDIRECT_QUERY_STRING] = urlencode(params)

    if backend.uses_redirect:
        return HttpResponseRedirect(backend.auth_url())
    else:
        return HttpResponse(backend.auth_html(),
                            content_type='text/html;charset=UTF-8')
开发者ID:scouredimage,项目名称:django-social-auth,代码行数:24,代码来源:views.py



注:本文中的social_auth.utils.sanitize_redirect函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.setting函数代码示例发布时间:2022-05-27
下一篇:
Python utils.sanitize_log_data函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap