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


Python auth.REDIRECT_FIELD_NAME属性代码示例

本文整理汇总了Python中django.contrib.auth.REDIRECT_FIELD_NAME属性的典型用法代码示例。如果您正苦于以下问题:Python auth.REDIRECT_FIELD_NAME属性的具体用法?Python auth.REDIRECT_FIELD_NAME怎么用?Python auth.REDIRECT_FIELD_NAME使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在django.contrib.auth的用法示例。


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

示例1: user_passes_test

# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import REDIRECT_FIELD_NAME [as 别名]
def user_passes_test(test_func: Callable[[HttpResponse], bool], login_url: Optional[str]=None,
                     redirect_field_name: str=REDIRECT_FIELD_NAME) -> Callable[[ViewFuncT], ViewFuncT]:
    """
    Decorator for views that checks that the user passes the given test,
    redirecting to the log-in page if necessary. The test should be a callable
    that takes the user object and returns True if the user passes.
    """
    def decorator(view_func: ViewFuncT) -> ViewFuncT:
        @wraps(view_func, assigned=available_attrs(view_func))
        def _wrapped_view(request: HttpRequest, *args: object, **kwargs: object) -> HttpResponse:
            if test_func(request):
                return view_func(request, *args, **kwargs)
            path = request.build_absolute_uri()
            resolved_login_url = resolve_url(login_url or settings.LOGIN_URL)
            # If the login url is the same scheme and net location then just
            # use the path as the "next" url.
            login_scheme, login_netloc = urllib.parse.urlparse(resolved_login_url)[:2]
            current_scheme, current_netloc = urllib.parse.urlparse(path)[:2]
            if ((not login_scheme or login_scheme == current_scheme) and
                    (not login_netloc or login_netloc == current_netloc)):
                path = request.get_full_path()
            return redirect_to_login(
                path, resolved_login_url, redirect_field_name)
        return cast(ViewFuncT, _wrapped_view)  # https://github.com/python/mypy/issues/1927
    return decorator 
开发者ID:zulip,项目名称:zulip,代码行数:27,代码来源:decorator.py

示例2: zulip_login_required

# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import REDIRECT_FIELD_NAME [as 别名]
def zulip_login_required(
        function: Optional[ViewFuncT]=None,
        redirect_field_name: str=REDIRECT_FIELD_NAME,
        login_url: str=settings.HOME_NOT_LOGGED_IN,
) -> Union[Callable[[ViewFuncT], ViewFuncT], ViewFuncT]:
    actual_decorator = lambda function: user_passes_test(
        logged_in_and_active,
        login_url=login_url,
        redirect_field_name=redirect_field_name,
    )(
        zulip_otp_required(
            redirect_field_name=redirect_field_name, login_url=login_url,
        )(add_logging_data(function))
    )

    if function:
        return actual_decorator(function)
    return actual_decorator  # nocoverage # We don't use this without a function 
开发者ID:zulip,项目名称:zulip,代码行数:20,代码来源:decorator.py

示例3: is_owner

# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import REDIRECT_FIELD_NAME [as 别名]
def is_owner(view_func):
    @wraps(view_func, assigned=available_attrs(view_func))
    def _wrapped_view(request, *args, **kwargs):
        # assume username is first arg
        if request.user.is_authenticated():
            if request.user.username == kwargs['username']:
                return view_func(request, *args, **kwargs)
            protocol = "https" if request.is_secure() else "http"
            return HttpResponseRedirect("%s://%s" % (protocol,
                                                     request.get_host()))
        path = request.build_absolute_uri()
        login_url = request.build_absolute_uri(settings.LOGIN_URL)
        # If the login url is the same scheme and net location then just
        # use the path as the "next" url.
        login_scheme, login_netloc = urlparse.urlparse(login_url)[:2]
        current_scheme, current_netloc = urlparse.urlparse(path)[:2]
        if ((not login_scheme or login_scheme == current_scheme) and
                (not login_netloc or login_netloc == current_netloc)):
            path = request.get_full_path()
        from django.contrib.auth.views import redirect_to_login
        return redirect_to_login(path, None, REDIRECT_FIELD_NAME)
    return _wrapped_view 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:24,代码来源:decorators.py

示例4: site_is_configured

# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import REDIRECT_FIELD_NAME [as 别名]
def site_is_configured(function=None, redirect_field_name=REDIRECT_FIELD_NAME, login_url=None):
    """
    Decorator for views that checks that the user is logged in, redirecting
    to the log-in page if necessary.
    """
    def check_constance_is_configured():
        return config.USER_HAS_COMPLETED_CONFIGURATION

    actual_decorator = constance_check(
        check_constance_is_configured,
        next_url=login_url,
        redirect_field_name=redirect_field_name
    )
    if function:
        return actual_decorator(function)
    return actual_decorator 
开发者ID:thorrak,项目名称:fermentrack,代码行数:18,代码来源:decorators.py

示例5: login_if_required_for_dashboard

# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import REDIRECT_FIELD_NAME [as 别名]
def login_if_required_for_dashboard(function=None, redirect_field_name=REDIRECT_FIELD_NAME, login_url=None):
    """
    Decorator for views that checks that the user is logged in, redirecting to the log-in page if necessary -
    but only if REQUIRE_LOGIN_FOR_DASHBOARD is set True in Constance.
    """

    def authenticated_test(u):
        if config.REQUIRE_LOGIN_FOR_DASHBOARD:
            return u.is_authenticated
        else:
            return True

    actual_decorator = user_passes_test(
        authenticated_test,
        login_url=login_url,
        redirect_field_name=redirect_field_name
    )
    if function:
        return actual_decorator(function)
    return actual_decorator 
开发者ID:thorrak,项目名称:fermentrack,代码行数:22,代码来源:decorators.py

示例6: gravity_support_enabled

# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import REDIRECT_FIELD_NAME [as 别名]
def gravity_support_enabled(function=None, redirect_field_name=REDIRECT_FIELD_NAME, login_url=None):
    """
    Decorator for views that checks that the user is logged in, redirecting
    to the log-in page if necessary.
    """
    def check_gravity_support_enabled():
        return config.GRAVITY_SUPPORT_ENABLED

    actual_decorator = constance_check(
        check_gravity_support_enabled,
        next_url=login_url,
        redirect_field_name=redirect_field_name
    )
    if function:
        return actual_decorator(function)
    return actual_decorator 
开发者ID:thorrak,项目名称:fermentrack,代码行数:18,代码来源:decorators.py

示例7: redirect_to_login

# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import REDIRECT_FIELD_NAME [as 别名]
def redirect_to_login(next: str, login_url: Optional[str]=None,
                      redirect_field_name: str=REDIRECT_FIELD_NAME) -> HttpResponseRedirect:
    """
    Redirects the user to the login page, passing the given 'next' page
    """
    resolved_url = resolve_url(login_url or settings.LOGIN_URL)

    login_url_parts = list(urllib.parse.urlparse(resolved_url))
    if redirect_field_name:
        querystring = QueryDict(login_url_parts[4], mutable=True)
        querystring[redirect_field_name] = next
        # Don't add ?next=/, to keep our URLs clean
        if next != '/':
            login_url_parts[4] = querystring.urlencode(safe='/')

    return HttpResponseRedirect(urllib.parse.urlunparse(login_url_parts))

# From Django 1.8 
开发者ID:zulip,项目名称:zulip,代码行数:20,代码来源:decorator.py

示例8: form_valid

# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import REDIRECT_FIELD_NAME [as 别名]
def form_valid(self, form):
        request = self.request

        # If the test cookie worked, go ahead and delete it since its no longer needed
        if request.session.test_cookie_worked():
            request.session.delete_test_cookie()

        # The default Django's "remember me" lifetime is 2 weeks and can be changed by modifying
        # the SESSION_COOKIE_AGE settings' option.
        if settings.USE_REMEMBER_ME:
            if not form.cleaned_data['remember_me']:
                request.session.set_expiry(0)

        login(request, form.user_cache)

        redirect_to = request.POST.get(REDIRECT_FIELD_NAME, request.GET.get(REDIRECT_FIELD_NAME))
        url_is_safe = is_safe_url(redirect_to, allowed_hosts=request.get_host(), require_https=request.is_secure())

        if url_is_safe:
            return redirect(redirect_to)

        return redirect(settings.LOGIN_REDIRECT_URL) 
开发者ID:egorsmkv,项目名称:simple-django-login-and-register,代码行数:24,代码来源:views.py

示例9: view

# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import REDIRECT_FIELD_NAME [as 别名]
def view(request):
    if not request.user.is_authenticated:
        ctx = {
            "next": request.GET.get(REDIRECT_FIELD_NAME, ""),
        }
        return render(request, "welcome.html", ctx)

    lang = request.COOKIES.get(COOKIE_NAME, None)

    if lang is None:
        supported = Language.live.cached_dict(show_all=request.user.is_superuser)
        lang = get_lang_from_http_header(request, supported)

    if lang is not None and lang not in ("projects", ""):
        url = reverse("pootle-language-browse", args=[lang])
    else:
        url = reverse("pootle-projects-browse")

    # Preserve query strings
    args = request.GET.urlencode()
    qs = "?%s" % args if args else ""
    redirect_url = "%s%s" % (url, qs)

    return redirect(redirect_url) 
开发者ID:evernote,项目名称:zing,代码行数:26,代码来源:index.py

示例10: user_login

# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import REDIRECT_FIELD_NAME [as 别名]
def user_login(request):
    """
        View for logging users in.
    """

    redirect_to = request.POST.get(REDIRECT_FIELD_NAME, request.GET.get(REDIRECT_FIELD_NAME, ''))
    login_form = AuthenticationForm(request, data=request.POST)
    if login_form.is_valid():
        # Ensure the user-originating redirection url is safe.
        if not is_safe_url(url=REDIRECT_FIELD_NAME, host=request.get_host()):
            redirect_to = settings.LOGIN_REDIRECT_URL
        # Okay, security check complete. Log the user in.
        auth_login(request, login_form.get_user())
        return redirect(settings.LOGIN_REDIRECT_URL if redirect_to == '' else redirect_to)
    else:
        return render(request, 'index.html', {'login_form': login_form, 'display': 'block', 'active': 'login'}) 
开发者ID:Djacket,项目名称:djacket,代码行数:18,代码来源:views.py

示例11: setup_wanted

# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import REDIRECT_FIELD_NAME [as 别名]
def setup_wanted(view_func, setup_url=None, redirect_field_name=REDIRECT_FIELD_NAME):
    """
    Decorator for views that checks that the user has completed the setup
    process, redirecting to settings.SETUP_URL if required
    """

    @wraps(view_func)
    def wrap(request, *args, **kwargs):
        if (
            not request.user.is_authenticated
            or request.user.account.has_completed_setup
        ):
            return view_func(request, *args, **kwargs)
        else:
            resolved_setup_url = resolve_url(setup_url or settings.SETUP_URL)
            path = request.get_full_path()
            return redirect_to_login(path, resolved_setup_url, redirect_field_name)

    return wrap 
开发者ID:GetTogetherComm,项目名称:GetTogether,代码行数:21,代码来源:decorators.py

示例12: process_view

# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import REDIRECT_FIELD_NAME [as 别名]
def process_view(self, request, view_func, view_args, view_kwargs):
        """ Forwards unauthenticated requests to the admin page to the CAS
            login URL, as well as calls to django.contrib.auth.views.login and
            logout.
        """
        if view_func == login:
            return cas_login(request, *view_args, **view_kwargs)
        if view_func == logout:
            return cas_logout(request, *view_args, **view_kwargs)
        
        # The rest of this method amends the Django admin authorization wich
        # will post a username/password dialog to authenticate to django admin.
        if not view_func.__module__.startswith('django.contrib.admin.'):
            return None

        if request.user.is_authenticated():
            if request.user.is_staff:
                return None
            else:
                raise PermissionDenied("No staff priviliges")
        params = urlencode({auth.REDIRECT_FIELD_NAME: request.get_full_path()})        
        return HttpResponseRedirect(settings.LOGIN_URL + '?' + params) 
开发者ID:childe,项目名称:esproxy,代码行数:24,代码来源:middleware.py

示例13: _service_url

# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import REDIRECT_FIELD_NAME [as 别名]
def _service_url(request, redirect_to):
    """ Returns application service URL for CAS. """

    service = _service(request) + request.path

    params = {}
    if settings.CAS_GATEWAY:
        params.update({settings.CAS_GATEWAY_PARAM: '1'})
    if redirect_to:
        params.update({auth.REDIRECT_FIELD_NAME: redirect_to})

    if not params:
        return service
    else:
        return ''.join([service,
                        '?' if not '?' in service else '&',
                        urlencode(params)]) 
开发者ID:childe,项目名称:esproxy,代码行数:19,代码来源:views.py

示例14: form_valid

# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import REDIRECT_FIELD_NAME [as 别名]
def form_valid(self, form):
        user = form.get_user()
        if not self.requires_two_factor(user):
            # no keys registered, use single-factor auth
            return super(U2FLoginView, self).form_valid(form)
        else:
            self.request.session['u2f_pre_verify_user_pk'] = user.pk
            self.request.session['u2f_pre_verify_user_backend'] = user.backend

            verify_url = reverse('u2f:verify-second-factor')
            redirect_to = self.request.POST.get(auth.REDIRECT_FIELD_NAME,
                                                self.request.GET.get(auth.REDIRECT_FIELD_NAME, ''))
            params = {}
            if is_safe_url(url=redirect_to, allowed_hosts=self.request.get_host()):
                params[auth.REDIRECT_FIELD_NAME] = redirect_to
            if self.is_admin:
                params['admin'] = 1
            if params:
                verify_url += '?' + urlencode(params)

            return HttpResponseRedirect(verify_url) 
开发者ID:gavinwahl,项目名称:django-u2f,代码行数:23,代码来源:views.py

示例15: form_valid

# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import REDIRECT_FIELD_NAME [as 别名]
def form_valid(self, form, forms):
        if not form.validate_second_factor():
            return self.form_invalid(forms)

        del self.request.session['u2f_pre_verify_user_pk']
        del self.request.session['u2f_pre_verify_user_backend']
        self.request.session['verfied_otp'] = True
        self.request.session['verfied_u2f'] = True

        auth.login(self.request, self.user)

        redirect_to = self.request.POST.get(auth.REDIRECT_FIELD_NAME,
                                            self.request.GET.get(auth.REDIRECT_FIELD_NAME, ''))
        if not is_safe_url(url=redirect_to, allowed_hosts=self.request.get_host()):
            redirect_to = resolve_url(settings.LOGIN_REDIRECT_URL)
        return HttpResponseRedirect(redirect_to) 
开发者ID:MicroPyramid,项目名称:django-mfa,代码行数:18,代码来源:views.py


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