當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。