当前位置: 首页>>代码示例>>Python>>正文


Python authentication.AUTH_PROVIDERS类代码示例

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


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

示例1: auth_settings

def auth_settings(request, id):
    user_ = get_object_or_404(User, id=id)

    if not (request.user.is_superuser or request.user == user_):
        return HttpResponseUnauthorized(request)
    if not settings.USERS_CAN_CHANGE_AUTH_SETTINGS:
        return HttpResponseUnauthorized(request)

    auth_keys = user_.auth_keys.all()

    if request.user.is_superuser or (not user_.has_usable_password()):
        FormClass = SetPasswordForm
    else:
        FormClass = ChangePasswordForm

    if request.POST:
        form = FormClass(request.POST, user=user_)
        if form.is_valid():
            is_new_pass = not user_.has_usable_password()
            user_.set_password(form.cleaned_data["password1"])
            user_.save()

            if is_new_pass:
                request.user.message_set.create(message=_("New password set"))
                if not request.user.is_superuser:
                    form = ChangePasswordForm(user=user_)
            else:
                request.user.message_set.create(message=_("Your password was changed"))

            return HttpResponseRedirect(reverse("user_authsettings", kwargs={"id": user_.id}))
    else:
        form = FormClass(user=user_)

    auth_keys_list = []

    for k in auth_keys:
        provider = AUTH_PROVIDERS.get(k.provider, None)

        if provider is not None:
            name = "%s: %s" % (provider.context.human_name, provider.context.readable_key(k))
        else:
            from forum.authentication.base import ConsumerTemplateContext

            "unknown: %s" % ConsumerTemplateContext.readable_key(k)

        auth_keys_list.append({"name": name, "id": k.id})

    return render_response(
        "auth/auth_settings.html",
        {
            "view_user": user_,
            "can_view_private": (user_ == request.user) or request.user.is_superuser,
            "form": form,
            "has_password": user_.has_usable_password(),
            "auth_keys": auth_keys_list,
            "allow_local_auth": AUTH_PROVIDERS.get("local", None),
        },
        request,
    )
开发者ID:sanketsaurav,项目名称:OSQA,代码行数:59,代码来源:auth.py

示例2: auth_settings

def auth_settings(request, id):
    user_ = get_object_or_404(User, id=id)

    if not (request.user.is_superuser or request.user == user_):
        return HttpResponseUnauthorized(request)
    if not settings.USERS_CAN_CHANGE_AUTH_SETTINGS:
        return HttpResponseUnauthorized(request)

    auth_keys = user_.auth_keys.all()

    if request.user.is_superuser or (not user_.has_usable_password()):
        FormClass = SetPasswordForm
    else:
        FormClass = ChangePasswordForm

    if request.POST:
        form = FormClass(request.POST, user=user_)
        if form.is_valid():
            is_new_pass = not user_.has_usable_password()
            user_.set_password(form.cleaned_data['password1'])
            user_.save()

            if is_new_pass:
                messages.info(request, _("New password set"))
                if not request.user.is_superuser:
                    form = ChangePasswordForm(user=user_)
            else:
                messages.info(request, _("Your password was changed"))

            return HttpResponseRedirect(reverse('user_authsettings', kwargs={'id': user_.id}))
    else:
        form = FormClass(user=user_)

    auth_keys_list = []

    for k in auth_keys:
        provider = AUTH_PROVIDERS.get(k.provider, None)

        if provider is not None:
            name =  "%s: %s" % (provider.context.human_name, provider.context.readable_key(k))
        else:
            from forum.authentication.base import ConsumerTemplateContext
            "unknown: %s" % ConsumerTemplateContext.readable_key(k)

        auth_keys_list.append({
        'name': name,
        'id': k.id
        })

    return render_to_response('auth/auth_settings.html', {
    'view_user': user_,
    "can_view_private": (user_ == request.user) or request.user.is_superuser,
    'form': form,
    'has_password': user_.has_usable_password(),
    'auth_keys': auth_keys_list,
    'allow_local_auth': AUTH_PROVIDERS.get('local', None),
    }, context_instance=RequestContext(request))
开发者ID:softbalajibi,项目名称:osqa,代码行数:57,代码来源:auth.py

示例3: _get_bigicon_providers

def _get_bigicon_providers(request):
    all_providers = [provider.context for provider in AUTH_PROVIDERS.values() if provider.context]

    sort = lambda c1, c2: c1.weight - c2.weight
    can_show = lambda c: not request.user.is_authenticated() or c.show_to_logged_in_user

    return sorted([context for context in all_providers if context.mode == "BIGICON" and can_show(context)], sort)
开发者ID:konrado0,项目名称:vosqa,代码行数:7,代码来源:views.py

示例4: signin_page

def signin_page(request):
    subdomain = get_subdomain()
    on_hub_server = not any(map(lambda x: subdomain.endswith(x), ['-a', '-b']))
    if not on_hub_server and not request.session.has_key('auth_error'):
        # Go log in to main site instead, which will redirect back here
        return HttpResponseRedirect('http://' + subdomain.replace('-a','').replace('-b', '') + '.moocforums.org' + reverse('auth_signin'))

    referer = request.META.get('HTTP_REFERER', '/')

    # If the referer is equal to the sign up page, e. g. if the previous login attempt was not successful we do not
    # change the sign in URL. The user should go to the same page.
    if not referer.replace(settings.APP_URL, '') == reverse('auth_signin'):
        request.session[ON_SIGNIN_SESSION_ATTR] = referer

    all_providers = [provider.context for provider in AUTH_PROVIDERS.values() if provider.context]

    sort = lambda c1, c2: c1.weight - c2.weight
    can_show = lambda c: not request.user.is_authenticated() or c.show_to_logged_in_user

    if on_hub_server:
        bigicon_providers = sorted([
        context for context in all_providers if context.mode == 'BIGICON' and can_show(context)
        ], sort)
    else:
        bigicon_providers = []

    smallicon_providers = sorted([
    context for context in all_providers if context.mode == 'SMALLICON' and can_show(context)
    ], sort)

    top_stackitem_providers = sorted([
    context for context in all_providers if context.mode == 'TOP_STACK_ITEM' and can_show(context)
    ], sort)

    stackitem_providers = sorted([
    context for context in all_providers if context.mode == 'STACK_ITEM' and can_show(context)
    ], sort)

    try:
        msg = request.session['auth_error']
        del request.session['auth_error']
    except:
        msg = None

    return render_to_response(
            'auth/signin.html',
            {
            'msg': msg,
            'all_providers': all_providers,
            'bigicon_providers': bigicon_providers,
            'top_stackitem_providers': top_stackitem_providers,
            'stackitem_providers': stackitem_providers,
            'smallicon_providers': smallicon_providers,
            },
            RequestContext(request))
开发者ID:dcoetzee,项目名称:osqa_forum_experiment,代码行数:55,代码来源:auth.py

示例5: signin_page

def signin_page(request):
    referer = request.META.get('HTTP_REFERER', '/')

    # If the referer is equal to the sign up page, e. g. if the previous login attempt was not successful we do not
    # change the sign in URL. The user should go to the same page.
    if not referer.replace(settings.APP_URL, '') == reverse('auth_signin'):
        request.session[ON_SIGNIN_SESSION_ATTR] = referer

    all_providers = [provider.context for provider in AUTH_PROVIDERS.values() if provider.context]

    sort = lambda c1, c2: c1.weight - c2.weight
    can_show = lambda c: not request.user.is_authenticated() or c.show_to_logged_in_user

    bigicon_providers = sorted([
    context for context in all_providers if context.mode == 'BIGICON' and can_show(context)
    ], sort)

    smallicon_providers = sorted([
    context for context in all_providers if context.mode == 'SMALLICON' and can_show(context)
    ], sort)

    top_stackitem_providers = sorted([
    context for context in all_providers if context.mode == 'TOP_STACK_ITEM' and can_show(context)
    ], sort)

    stackitem_providers = sorted([
    context for context in all_providers if context.mode == 'STACK_ITEM' and can_show(context)
    ], sort)

    allow_auto_redirect = "true"
    if request.user.is_authenticated():
        allow_auto_redirect = "false"

    try:
        msg = request.session['auth_error']
        del request.session['auth_error']
        allow_auto_redirect = "false"
    except:
        msg = None

    return render_to_response(
            'auth/signin.html',
            {
            'msg': msg,
            'bz_url': djsettings.BZ_SITE_BASE,
            'allow_auto_redirect': allow_auto_redirect,
            'all_providers': all_providers,
            'bigicon_providers': bigicon_providers,
            'top_stackitem_providers': top_stackitem_providers,
            'stackitem_providers': stackitem_providers,
            'smallicon_providers': smallicon_providers,
            },
            RequestContext(request))
开发者ID:sadleb,项目名称:osqa,代码行数:53,代码来源:auth.py

示例6: signin_page

def signin_page(request):
    referer = request.META.get('HTTP_REFERER', reverse('index'))
    referer_parsed = urlparse(referer)

    # If the referer is equal to the sign up page, e. g. if the previous login attempt was not successful we do not
    # change the sign in URL. The user should go to the same page.
    ### F. CRESPEL EDIT 2013-01-26: reworked condition to work with HTTP/HTTPS and prevent redirecting to off-site URL
    if not referer_parsed.path == reverse('auth_signin') and urlparse(settings.APP_URL).path in referer_parsed.path:
        request.session[ON_SIGNIN_SESSION_ATTR] = referer

    all_providers = [provider.context for provider in AUTH_PROVIDERS.values() if provider.context]

    sort = lambda c1, c2: c1.weight - c2.weight
    can_show = lambda c: not request.user.is_authenticated() or c.show_to_logged_in_user

    bigicon_providers = sorted([
    context for context in all_providers if context.mode == 'BIGICON' and can_show(context)
    ], sort)

    smallicon_providers = sorted([
    context for context in all_providers if context.mode == 'SMALLICON' and can_show(context)
    ], sort)

    top_stackitem_providers = sorted([
    context for context in all_providers if context.mode == 'TOP_STACK_ITEM' and can_show(context)
    ], sort)

    stackitem_providers = sorted([
    context for context in all_providers if context.mode == 'STACK_ITEM' and can_show(context)
    ], sort)

    try:
        msg = request.session['auth_error']
        del request.session['auth_error']
    except:
        msg = None

    # F. CRESPEL EDIT 2013-01-28: added setting to redirect to a default authentication provider
    if settings.DEFAULT_AUTH_PROVIDER and not msg:
        return HttpResponseRedirect(reverse('auth_provider_signin', kwargs={'provider': str(settings.DEFAULT_AUTH_PROVIDER)}))

    return render_to_response(
            'auth/signin.html',
            {
            'msg': msg,
            'all_providers': all_providers,
            'bigicon_providers': bigicon_providers,
            'top_stackitem_providers': top_stackitem_providers,
            'stackitem_providers': stackitem_providers,
            'smallicon_providers': smallicon_providers,
            },
            RequestContext(request))
开发者ID:it-toolbox,项目名称:project-factory-packages,代码行数:52,代码来源:auth.py

示例7: auth_settings

def auth_settings(request):
    """
    change password view.

    url : /changepw/
    template: authopenid/changepw.html
    """
    user_ = request.user
    auth_keys = user_.auth_keys.all()

    if user_.has_usable_password():
        FormClass = ChangePasswordForm
    else:
        FormClass = SetPasswordForm

    if request.POST:
        form = FormClass(request.POST, user=user_)
        if form.is_valid():
            if user_.has_usable_password():
                request.user.message_set.create(message=_("Your password was changed"))
            else:
                request.user.message_set.create(message=_("New password set"))
                FormClass = ChangePasswordForm
                
            user_.set_password(form.cleaned_data['password1'])
            user_.save()
            return HttpResponseRedirect(reverse('user_authsettings'))
    
    form = FormClass(user=user_)

    auth_keys_list = []

    for k in auth_keys:
        provider = AUTH_PROVIDERS.get(k.provider, None)

        if provider is not None:
            name =  "%s: %s" % (provider.context.human_name, provider.context.readable_key(k))
        else:
            from forum.authentication.base import ConsumerTemplateContext
            "unknown: %s" % ConsumerTemplateContext.readable_key(k)

        auth_keys_list.append({
            'name': name,
            'id': k.id
        })

    return render_to_response('auth/auth_settings.html', {
        'form': form,
        'has_password': user_.has_usable_password(),
        'auth_keys': auth_keys_list,
    }, context_instance=RequestContext(request))
开发者ID:gvasilev,项目名称:osqa,代码行数:51,代码来源:auth.py

示例8: signin_page

def signin_page(request):
    referer = request.META.get("HTTP_REFERER", "/")

    # If the referer is equal to the sign up page, e. g. if the previous login attempt was not successful we do not
    # change the sign in URL. The user should go to the same page.
    if not referer.replace(settings.APP_URL, "") == reverse("auth_signin"):
        request.session[ON_SIGNIN_SESSION_ATTR] = referer

    all_providers = [provider.context for provider in AUTH_PROVIDERS.values() if provider.context]

    sort = lambda c1, c2: c1.weight - c2.weight
    can_show = lambda c: not request.user.is_authenticated() or c.show_to_logged_in_user

    bigicon_providers = sorted(
        [context for context in all_providers if context.mode == "BIGICON" and can_show(context)], sort
    )

    smallicon_providers = sorted(
        [context for context in all_providers if context.mode == "SMALLICON" and can_show(context)], sort
    )

    top_stackitem_providers = sorted(
        [context for context in all_providers if context.mode == "TOP_STACK_ITEM" and can_show(context)], sort
    )

    stackitem_providers = sorted(
        [context for context in all_providers if context.mode == "STACK_ITEM" and can_show(context)], sort
    )

    try:
        msg = request.session["auth_error"]
        del request.session["auth_error"]
    except:
        msg = None

    return render_to_response(
        "auth/signin.html",
        {
            "msg": msg,
            "all_providers": all_providers,
            "bigicon_providers": bigicon_providers,
            "top_stackitem_providers": top_stackitem_providers,
            "stackitem_providers": stackitem_providers,
            "smallicon_providers": smallicon_providers,
        },
        RequestContext(request),
    )
开发者ID:pombredanne,项目名称:osqa-ng,代码行数:47,代码来源:auth.py

示例9: signin_page

def signin_page(request, action=None):
    if action is None:
        request.session['on_signin_url'] = request.META.get('HTTP_REFERER', '/')
    else:
        request.session['on_signin_action'] = action
        request.session['on_signin_url'] = reverse('auth_action_signin', kwargs={'action': action})

    all_providers = [provider.context for provider in AUTH_PROVIDERS.values()]

    sort = lambda c1, c2: c1.weight - c2.weight
    can_show = lambda c: not request.user.is_authenticated() or c.show_to_logged_in_user

    bigicon_providers = sorted([
        context for context in all_providers if context.mode == 'BIGICON' and can_show(context)
    ], sort)

    smallicon_providers = sorted([
        context for context in all_providers if context.mode == 'SMALLICON' and can_show(context)
    ], sort)

    top_stackitem_providers = sorted([
        context for context in all_providers if context.mode == 'TOP_STACK_ITEM' and can_show(context)
    ], sort)

    stackitem_providers = sorted([
        context for context in all_providers if context.mode == 'STACK_ITEM' and can_show(context)
    ], sort)

    try:
        msg = request.session['auth_error']
        del request.session['auth_error']
    except:
        msg = None

    return render_to_response(
            'auth/signin.html',
            {
                'msg': msg,
                'all_providers': all_providers,
                'bigicon_providers': bigicon_providers,
                'top_stackitem_providers': top_stackitem_providers,
                'stackitem_providers': stackitem_providers,
                'smallicon_providers': smallicon_providers,
            },
            RequestContext(request))
开发者ID:gvasilev,项目名称:osqa,代码行数:45,代码来源:auth.py


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