本文整理汇总了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)