本文整理匯總了Python中django.contrib.auth.logout方法的典型用法代碼示例。如果您正苦於以下問題:Python auth.logout方法的具體用法?Python auth.logout怎麽用?Python auth.logout使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.contrib.auth
的用法示例。
在下文中一共展示了auth.logout方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: logout
# 需要導入模塊: from django.contrib import auth [as 別名]
# 或者: from django.contrib.auth import logout [as 別名]
def logout(request):
'''
Logs out the user. returns an error if the user is not
authenticated.
'''
user = request.user
serializer = LogoutSerializer(
data=request.data,
context={'request': request},
)
serializer.is_valid(raise_exception=True)
data = serializer.validated_data
if should_authenticate_session():
auth.logout(request)
if should_retrieve_token() and data['revoke_token']:
auth_token_manager_cls = registration_settings.AUTH_TOKEN_MANAGER_CLASS
auth_token_manager = auth_token_manager_cls() # noqa: E501 type: rest_registration.auth_token_managers.AbstractAuthTokenManager
auth_token_manager.revoke_token(user)
return get_ok_response(_("Logout successful"))
示例2: logout
# 需要導入模塊: from django.contrib import auth [as 別名]
# 或者: from django.contrib.auth import logout [as 別名]
def logout(self):
"""
Removes the authenticated user's cookies and session object.
Causes the authenticated user to be logged out.
"""
from django.contrib.auth import get_user, logout
request = HttpRequest()
engine = import_module(settings.SESSION_ENGINE)
if self.session:
request.session = self.session
request.user = get_user(request)
else:
request.session = engine.SessionStore()
logout(request)
self.cookies = SimpleCookie()
示例3: test_logout_authentication_with_success
# 需要導入模塊: from django.contrib import auth [as 別名]
# 或者: from django.contrib.auth import logout [as 別名]
def test_logout_authentication_with_success(self):
# Extra parameters to make this a Ajax style request.
kwargs = {'HTTP_X_REQUESTED_WITH':'XMLHttpRequest'}
# Test
client = Client()
client.login(
username=TEST_USER_USERNAME,
password=TEST_USER_PASSWORD
)
response = client.post('/logout', {}, **kwargs )
# Verify: Check that the response is 200 OK.
self.assertEqual(response.status_code, 200)
# Verify: Successful response.
json_string = response.content.decode(encoding='UTF-8')
array = json.loads(json_string)
self.assertEqual(array['status'], 'success')
self.assertEqual(array['message'], 'you are logged off')
示例4: test_logout_authentication_with_non_ajax_call
# 需要導入模塊: from django.contrib import auth [as 別名]
# 或者: from django.contrib.auth import logout [as 別名]
def test_logout_authentication_with_non_ajax_call(self):
# Test
client = Client()
client.login(
username=TEST_USER_USERNAME,
password=TEST_USER_PASSWORD
)
response = client.post('/logout')
# Verify: Check that the response is 200 OK.
self.assertEqual(response.status_code, 200)
# Verify: Successful response.
json_string = response.content.decode(encoding='UTF-8')
array = json.loads(json_string)
self.assertEqual(array['status'], 'success')
self.assertEqual(array['message'], 'you are logged off')
示例5: authorize
# 需要導入模塊: from django.contrib import auth [as 別名]
# 或者: from django.contrib.auth import logout [as 別名]
def authorize(self, request):
if not settings.MAINTENANCE_ENABLE:
# Not to use this env
return True
current_url = resolve(request.path_info).url_name
if current_url in [
'home', 'login', 'logout', 'maintenance', 'list',
'detail', 'bill_download', 'pmt_download'
]:
if request.user.is_authenticated:
if request.user.is_superuser:
return True
else:
# Logout all non superusers (local admins)
logout(request)
return True
else:
return True
else:
return False
示例6: process_view
# 需要導入模塊: from django.contrib import auth [as 別名]
# 或者: from django.contrib.auth import logout [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)
示例7: login
# 需要導入模塊: from django.contrib import auth [as 別名]
# 或者: from django.contrib.auth import logout [as 別名]
def login(request):
if request.user.is_authenticated():
return HttpResponseRedirect('/')
if request.method == 'GET' and request.GET.has_key('next'):
next_page = request.GET['next']
else:
next_page = '/'
if next_page == "/accounts/logout/":
next_page = '/'
if request.method == "POST":
form = LoginUserForm(request, data=request.POST)
if form.is_valid():
auth.login(request, form.get_user())
return HttpResponseRedirect(request.POST['next'])
else:
form = LoginUserForm(request)
kwargs = {
'request': request,
'form': form,
'next': next_page,
}
return render(request, 'accounts/login.html', kwargs)
示例8: logout
# 需要導入模塊: from django.contrib import auth [as 別名]
# 或者: from django.contrib.auth import logout [as 別名]
def logout(request):
if request.method == 'POST':
auth.logout(request)
messages.info(request, _("You have logged out"))
return redirect(login)
return render(request, "accounts/logout.html")
示例9: login_handler
# 需要導入模塊: from django.contrib import auth [as 別名]
# 或者: from django.contrib.auth import logout [as 別名]
def login_handler(request):
""" HTTP Request handler function for user login / logout requests """
if request.POST:
action = request.POST['action']
if action == 'login':
username = request.POST['username']
password = request.POST['password']
user = authenticate(username=username, password=password)
if user is not None and user.is_active:
# Correct password, and the user is marked "active"
login(request, user)
else:
return HttpResponse(Response.error('login', 'Authentication Failed'))
else:
username = ''
try:
if request.session.session_key is not None and request.session.session_key != '':
session_dir = ServerSettings.session_path(request.session.session_key)
if os.path.exists(session_dir):
logger.debug('Cleaning ' + session_dir)
shutil.rmtree(session_dir)
logout(request)
except:
logger.exception("Failed")
else:
logger.debug('Logout success!!')
session = get_session_config(username)
return HttpResponse(Response.success(action, 'ok', session))
return HttpResponse(Response.error('unknown', 'Invalid request!!'))
示例10: logout
# 需要導入模塊: from django.contrib import auth [as 別名]
# 或者: from django.contrib.auth import logout [as 別名]
def logout(request):
auth.logout(request)
return HttpResponseRedirect(reverse('document_set_index'))
示例11: fake_logout
# 需要導入模塊: from django.contrib import auth [as 別名]
# 或者: from django.contrib.auth import logout [as 別名]
def fake_logout(request):
"""
Fake logout view for devel without access to the fake CAS server
"""
import socket
hostname = socket.gethostname()
if settings.DEPLOY_MODE == 'production' or hostname.startswith('courses'):
# make sure we're not in production
raise NotImplementedError
from django.contrib.auth import logout
logout(request)
return HttpResponseRedirect('/')
示例12: post
# 需要導入模塊: from django.contrib import auth [as 別名]
# 或者: from django.contrib.auth import logout [as 別名]
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)
示例13: get
# 需要導入模塊: from django.contrib import auth [as 別名]
# 或者: from django.contrib.auth import logout [as 別名]
def get(self, request):
next = request.GET.get("next", reverse("home"))
if request.GET.get("logout", None) is not None:
logout(request)
# need to redirect to 'auth' so that the user is set to anonymous via the middleware
return redirect("auth")
else:
return render(request, "login.htm", {"auth_failed": False, "next": next})
示例14: logout
# 需要導入模塊: from django.contrib import auth [as 別名]
# 或者: from django.contrib.auth import logout [as 別名]
def logout(request):
if request.method == 'POST':
auth.logout(request)
return redirect('主頁')
示例15: myLogout
# 需要導入模塊: from django.contrib import auth [as 別名]
# 或者: from django.contrib.auth import logout [as 別名]
def myLogout(request):
next = request.GET.get('next','/')
auth.logout(request)
return redirect('%s' % next)