当前位置: 首页>>代码示例>>Python>>正文


Python auth.logout方法代码示例

本文整理汇总了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")) 
开发者ID:apragacz,项目名称:django-rest-registration,代码行数:23,代码来源:login.py

示例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() 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:19,代码来源:client.py

示例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') 
开发者ID:AcademicsToday,项目名称:academicstoday-django,代码行数:22,代码来源:tests.py

示例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') 
开发者ID:AcademicsToday,项目名称:academicstoday-django,代码行数:19,代码来源:tests.py

示例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 
开发者ID:betagouv,项目名称:mrs,代码行数:24,代码来源:middleware.py

示例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) 
开发者ID:childe,项目名称:esproxy,代码行数:24,代码来源:middleware.py

示例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) 
开发者ID:guohongze,项目名称:adminset,代码行数:24,代码来源:user.py

示例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") 
开发者ID:fpsw,项目名称:Servo,代码行数:10,代码来源:account.py

示例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!!')) 
开发者ID:CiscoDevNet,项目名称:yang-explorer,代码行数:31,代码来源:views.py

示例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')) 
开发者ID:crowdata,项目名称:crowdata,代码行数:5,代码来源:views.py

示例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('/') 
开发者ID:sfu-fas,项目名称:coursys,代码行数:15,代码来源:views.py

示例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) 
开发者ID:impak-finance,项目名称:django-oidc-rp,代码行数:17,代码来源:views.py

示例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}) 
开发者ID:archesproject,项目名称:arches,代码行数:11,代码来源:auth.py

示例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('主页') 
开发者ID:nature1995,项目名称:ran-django-template,代码行数:6,代码来源:views.py

示例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) 
开发者ID:lotus-dgas,项目名称:AnsibleUI,代码行数:6,代码来源:account.py


注:本文中的django.contrib.auth.logout方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。