我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用django.contrib.auth.views.logout()。
def logout(self, request, extra_context=None): """ Logs out the user for the given HttpRequest. This should *not* assume the user is already logged in. """ from django.contrib.auth.views import logout defaults = { 'extra_context': dict( self.each_context(request), # Since the user isn't logged out at this point, the value of # has_permission must be overridden. has_permission=False, **(extra_context or {}) ), } if self.logout_template is not None: defaults['template_name'] = self.logout_template request.current_app = self.name return logout(request, **defaults)
def logout(self, request, extra_context=None): """ Logs out the user for the given HttpRequest. This should *not* assume the user is already logged in. """ from django.contrib.auth.views import logout defaults = { 'current_app': self.name, 'extra_context': dict( self.each_context(request), # Since the user isn't logged out at this point, the value of # has_permission must be overridden. has_permission=False, **(extra_context or {}) ), } if self.logout_template is not None: defaults['template_name'] = self.logout_template return logout(request, **defaults)
def admin_view(self, view, cacheable=False): """ Decorator to create an admin view attached to this ``AdminSite``. This wraps the view and provides permission checking by calling ``self.has_permission``. You'll want to use this from within ``AdminSite.get_urls()``: class MyAdminSite(AdminSite): def get_urls(self): from django.conf.urls import patterns, url urls = super(MyAdminSite, self).get_urls() urls += patterns('', url(r'^my_view/$', self.admin_view(some_view)) ) return urls By default, admin_views are marked non-cacheable using the ``never_cache`` decorator. If the view can be safely cached, set cacheable=True. """ def inner(request, *args, **kwargs): if LOGIN_FORM_KEY in request.POST and request.user.is_authenticated(): auth_logout(request) if not self.has_permission(request): if request.path == reverse('admin:logout', current_app=self.name): index_path = reverse('admin:index', current_app=self.name) return HttpResponseRedirect(index_path) return self.login(request) return view(request, *args, **kwargs) if not cacheable: inner = never_cache(inner) # We add csrf_protect here so this function can be used as a utility # function for any view, without having to repeat 'csrf_protect'. if not getattr(view, 'csrf_exempt', False): inner = csrf_protect(inner) return update_wrapper(inner, view)
def logout(request): return views.logout(request, next_page="/")
def get(self, request, *args, **kwargs): context = self.get_context() defaults = { 'extra_context': context, 'current_app': self.admin_site.name, 'template_name': self.logout_template or 'xadmin/views/logged_out.html', } if self.logout_template is not None: defaults['template_name'] = self.logout_template self.update_params(defaults) return logout(request, **defaults)
def logout(request): auth_views.logout(request) return render(request, 'registration/logout.html', {'data': ''})
def get(self, request): template_response = views.logout(request) messages.success(request, 'You have been logged out') return redirect(reverse('ploghubapp:login'))
def logout(self, request, extra_context=None): """ Logs out the user for the given HttpRequest. This should *not* assume the user is already logged in. """ from django.contrib.auth.views import logout defaults = { 'current_app': self.name, 'extra_context': dict(self.each_context(request), **(extra_context or {})), } if self.logout_template is not None: defaults['template_name'] = self.logout_template return logout(request, **defaults)
def hybrid_logout(request, next_page=None, template_name='registration/logged_out.html'): if users.get_current_user(): return google_logout(request, next_page) return logout(request, next_page, template_name)
def logout(request, *args, **kwargs): kwargs.setdefault('next_page', '/') user_id = getattr(request, 'original_user', request.user).id response = auth_views.logout(request, *args, **kwargs) if not request.user.is_authenticated(): LoginHistory.objects.create(type='logout', user_id=user_id, ip=request.META['REMOTE_ADDR']) return response
def finish_logout(request, response, next_page=None): if response and response.status_ok(): if next_page is None and hasattr(settings, 'LOGOUT_REDIRECT_URL'): next_page = settings.LOGOUT_REDIRECT_URL logger.debug('Performing django logout with a next_page of %s', next_page) return django_logout(request, next_page=next_page) else: logger.error('Unknown error during the logout') return render(request, "djangosaml2/logout_error.html", {})
def get(self,request): check = self.request.GET.get('check',False) if check in ['true','false',False]:#solve ast malformed string exception check = {'true':True,'false':False}[str(check).lower()] else: check = ast.literal_eval(check) if self.request.user == 'AnonymousUser': user = {'upn': 'ANONYMOUS'} else: user = {'upn': str(self.request.user)} if check and self.request.user.is_authenticated(): response = HttpResponse(u'authenticated') response["Access-Control-Allow-Origin"] = "*" response["Server"] = "GateOne" return response logout_get = self.request.GET.get("logout", None) if logout_get: logout(request) response = HttpResponse('/') response.delete_cookie('gateone_user') self.user_logout(request) return response next_url = self.request.GET.get("next", None) if next_url: return redirect(next_url) return redirect(getsettings('url_prefix','/'))
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) #elif view_func == logout: # return cas_logout(request, *view_args, **view_kwargs) if settings.CAS_ADMIN_PREFIX: if not request.path.startswith(settings.CAS_ADMIN_PREFIX): return None elif not view_func.__module__.startswith('django.contrib.admin.'): return None if request.user.is_authenticated(): if request.user.is_staff: return None else: error = ('<h1>Forbidden</h1><p>You do not have staff ' 'privileges.</p>') return HttpResponseForbidden(error) params = urlencode({REDIRECT_FIELD_NAME: request.get_full_path()}) return HttpResponseRedirect(reverse(cas_login) + '?' + params)
def process_exception(self, request, exception): """When we get a CasTicketException, that is probably caused by the ticket timing out. So logout/login and get the same page again.""" if isinstance(exception, CasTicketException): do_logout(request) # This assumes that request.path requires authentication. return HttpResponseRedirect(request.path) else: return None
def logout_view(request, *args, **kwargs): kwargs['next_page'] = reverse('index') logger = logging.getLogger(__name__) logger.info(request.user.__str__() + ' Logout ') return logout(request, *args, **kwargs)
def logout(self, request, extra_context=None): """ Logs out the user for the given HttpRequest. This should *not* assume the user is already logged in. """ from django.contrib.auth.views import logout defaults = { 'current_app': self.name, 'extra_context': extra_context or {}, } if self.logout_template is not None: defaults['template_name'] = self.logout_template return logout(request, **defaults)
def finish_logout(request, response, next_page=None): if response and response.status_ok(): if next_page is None and hasattr(settings, 'LOGOUT_REDIRECT_URL'): next_page = settings.LOGOUT_REDIRECT_URL logger.info('Performing django_logout with a next_page of %s', next_page) return django_logout(request, next_page=next_page) else: logger.info('Unknown error during the logout') return render(request, "penndjangosaml2/logout_error.html", {})
def logout(request, next_page=None, **kwargs): # Simple Wrapper around django.contrib.auth.views.logout to default # next_page based off the setting LOGOUT_REDIRECT_URLNAME. if next_page is None and hasattr(settings, "LOGOUT_REDIRECT_URLNAME"): next_page = reverse(settings.LOGOUT_REDIRECT_URLNAME) return django_logout(request, next_page, **kwargs)