Python django.conf.settings.LOGOUT_REDIRECT_URL Examples

The following are 9 code examples for showing how to use django.conf.settings.LOGOUT_REDIRECT_URL(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module django.conf.settings , or try the search function .

Example 1
Project: bioforum   Author: reBiocoder   File: views.py    License: MIT License 6 votes vote down vote up
def get_next_page(self):
        if self.next_page is not None:
            next_page = resolve_url(self.next_page)
        elif settings.LOGOUT_REDIRECT_URL:
            next_page = resolve_url(settings.LOGOUT_REDIRECT_URL)
        else:
            next_page = self.next_page

        if (self.redirect_field_name in self.request.POST or
                self.redirect_field_name in self.request.GET):
            next_page = self.request.POST.get(
                self.redirect_field_name,
                self.request.GET.get(self.redirect_field_name)
            )
            url_is_safe = is_safe_url(
                url=next_page,
                allowed_hosts=self.get_success_url_allowed_hosts(),
                require_https=self.request.is_secure(),
            )
            # Security check -- Ensure the user-originating redirection URL is
            # safe.
            if not url_is_safe:
                next_page = self.request.path
        return next_page 
Example 2
Project: Hands-On-Application-Development-with-PyCharm   Author: PacktPublishing   File: views.py    License: MIT License 6 votes vote down vote up
def get_next_page(self):
        if self.next_page is not None:
            next_page = resolve_url(self.next_page)
        elif settings.LOGOUT_REDIRECT_URL:
            next_page = resolve_url(settings.LOGOUT_REDIRECT_URL)
        else:
            next_page = self.next_page

        if (self.redirect_field_name in self.request.POST or
                self.redirect_field_name in self.request.GET):
            next_page = self.request.POST.get(
                self.redirect_field_name,
                self.request.GET.get(self.redirect_field_name)
            )
            url_is_safe = is_safe_url(
                url=next_page,
                allowed_hosts=self.get_success_url_allowed_hosts(),
                require_https=self.request.is_secure(),
            )
            # Security check -- Ensure the user-originating redirection URL is
            # safe.
            if not url_is_safe:
                next_page = self.request.path
        return next_page 
Example 3
Project: python2017   Author: bpgc-cte   File: views.py    License: MIT License 6 votes vote down vote up
def get_next_page(self):
        if self.next_page is not None:
            next_page = resolve_url(self.next_page)
        elif settings.LOGOUT_REDIRECT_URL:
            next_page = resolve_url(settings.LOGOUT_REDIRECT_URL)
        else:
            next_page = self.next_page

        if (self.redirect_field_name in self.request.POST or
                self.redirect_field_name in self.request.GET):
            next_page = self.request.POST.get(
                self.redirect_field_name,
                self.request.GET.get(self.redirect_field_name)
            )
            url_is_safe = is_safe_url(
                url=next_page,
                allowed_hosts=self.get_success_url_allowed_hosts(),
                require_https=self.request.is_secure(),
            )
            # Security check -- Ensure the user-originating redirection URL is
            # safe.
            if not url_is_safe:
                next_page = self.request.path
        return next_page 
Example 4
Project: django-keycloak   Author: Peter-Slump   File: views.py    License: MIT License 6 votes vote down vote up
def get_redirect_url(self, *args, **kwargs):
        if hasattr(self.request.user, 'oidc_profile'):
            self.request.realm.client.openid_api_client.logout(
                self.request.user.oidc_profile.refresh_token
            )
            self.request.user.oidc_profile.access_token = None
            self.request.user.oidc_profile.expires_before = None
            self.request.user.oidc_profile.refresh_token = None
            self.request.user.oidc_profile.refresh_expires_before = None
            self.request.user.oidc_profile.save(update_fields=[
                'access_token',
                'expires_before',
                'refresh_token',
                'refresh_expires_before'
            ])

        logout(self.request)

        if settings.LOGOUT_REDIRECT_URL:
            return resolve_url(settings.LOGOUT_REDIRECT_URL)

        return reverse('keycloak_login') 
Example 5
Project: django-oidc-rp   Author: impak-finance   File: views.py    License: MIT License 5 votes vote down vote up
def post(self, request):
        """ Processes POST requests. """
        logout_url = settings.LOGOUT_REDIRECT_URL or '/'

        # Log out the current user.
        if request.user.is_authenticated:
            try:
                logout_url = self.provider_end_session_url \
                    if oidc_rp_settings.PROVIDER_END_SESSION_ENDPOINT else logout_url
            except KeyError:  # pragma: no cover
                logout_url = logout_url
            auth.logout(request)

        # Redirects the user to the appropriate URL.
        return HttpResponseRedirect(logout_url) 
Example 6
Project: django-oidc-rp   Author: impak-finance   File: views.py    License: MIT License 5 votes vote down vote up
def provider_end_session_url(self):
        """ Returns the end-session URL. """
        q = QueryDict(mutable=True)
        q[oidc_rp_settings.PROVIDER_END_SESSION_REDIRECT_URI_PARAMETER] = \
            self.request.build_absolute_uri(settings.LOGOUT_REDIRECT_URL or '/')
        q[oidc_rp_settings.PROVIDER_END_SESSION_ID_TOKEN_PARAMETER] = \
            self.request.session['oidc_auth_id_token']
        return '{}?{}'.format(oidc_rp_settings.PROVIDER_END_SESSION_ENDPOINT, q.urlencode()) 
Example 7
Project: pythonic-news   Author: sebst   File: views.py    License: GNU Affero General Public License v3.0 5 votes vote down vote up
def logout(request):
    if request.method=="POST":
        do_logout(request)
        redirect_url = settings.LOGOUT_REDIRECT_URL or '/'
        return HttpResponseRedirect(redirect_url)
    else:
        return render(request, 'accounts/logout.html') 
Example 8
Project: hoover-search   Author: liquidinvestigations   File: views.py    License: MIT License 5 votes vote down vote up
def oauth2_logout(request):
    logout(request)
    return redirect(settings.LOGOUT_REDIRECT_URL) 
Example 9
Project: eoj3   Author: F0RE1GNERS   File: auth_view.py    License: MIT License 5 votes vote down vote up
def logout(request, next_page=None,
           template_name='registration/logged_out.html',
           redirect_field_name=REDIRECT_FIELD_NAME,
           extra_context=None):
  """
  Logs out the user and displays 'You are logged out' message.
  """
  auth_logout(request)

  if next_page is not None:
    next_page = resolve_url(next_page)
  elif settings.LOGOUT_REDIRECT_URL:
    next_page = resolve_url(settings.LOGOUT_REDIRECT_URL)

  if (redirect_field_name in request.POST or
      redirect_field_name in request.GET):
    next_page = request.POST.get(redirect_field_name,
                                 request.GET.get(redirect_field_name))
    # # Security check -- don't allow redirection to a different host.
    # if not is_safe_url(url=next_page, host=request.get_host()):
    #     next_page = request.path

  if next_page:
    # Redirect to this page until the session has been cleared.
    return HttpResponseRedirect(next_page)

  current_site = get_current_site(request)
  context = {
    'site': current_site,
    'site_name': current_site.name,
    'title': _('Logged out')
  }
  if extra_context is not None:
    context.update(extra_context)

  return TemplateResponse(request, template_name, context)