當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。