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


Python views.LoginView类代码示例

本文整理汇总了Python中django.contrib.auth.views.LoginView的典型用法代码示例。如果您正苦于以下问题:Python LoginView类的具体用法?Python LoginView怎么用?Python LoginView使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了LoginView类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_login_csrf_rotate

    def test_login_csrf_rotate(self):
        """
        Makes sure that a login rotates the currently-used CSRF token.
        """
        # Do a GET to establish a CSRF token
        # TestClient isn't used here as we're testing middleware, essentially.
        req = HttpRequest()
        CsrfViewMiddleware().process_view(req, LoginView.as_view(), (), {})
        # get_token() triggers CSRF token inclusion in the response
        get_token(req)
        resp = LoginView.as_view()(req)
        resp2 = CsrfViewMiddleware().process_response(req, resp)
        csrf_cookie = resp2.cookies.get(settings.CSRF_COOKIE_NAME, None)
        token1 = csrf_cookie.coded_value

        # Prepare the POST request
        req = HttpRequest()
        req.COOKIES[settings.CSRF_COOKIE_NAME] = token1
        req.method = "POST"
        req.POST = {'username': 'testclient', 'password': 'password', 'csrfmiddlewaretoken': token1}

        # Use POST request to log in
        SessionMiddleware().process_request(req)
        CsrfViewMiddleware().process_view(req, LoginView.as_view(), (), {})
        req.META["SERVER_NAME"] = "testserver"  # Required to have redirect work in login view
        req.META["SERVER_PORT"] = 80
        resp = LoginView.as_view()(req)
        resp2 = CsrfViewMiddleware().process_response(req, resp)
        csrf_cookie = resp2.cookies.get(settings.CSRF_COOKIE_NAME, None)
        token2 = csrf_cookie.coded_value

        # Check the CSRF token switched
        self.assertNotEqual(token1, token2)
开发者ID:mattseymour,项目名称:django,代码行数:33,代码来源:test_views.py

示例2: login

 def login(self):
     """
     Return the login view.
     """
     return LoginView.as_view(
         template_name='zinnia/login.html'
     )(self.request)
开发者ID:Fantomas42,项目名称:django-blog-zinnia,代码行数:7,代码来源:entry_protection.py

示例3: login

    def login(self, request, extra_context=None):
        """
        Displays the login form for the given HttpRequest.
        """
        if request.method == 'GET' and self.has_permission(request):
            # Already logged-in, redirect to admin index
            index_path = reverse('admin:index', current_app=self.name)
            return HttpResponseRedirect(index_path)

        from django.contrib.auth.views import LoginView
        # Since this module gets imported in the application's root package,
        # it cannot import models from other applications at the module level,
        # and django.contrib.admin.forms eventually imports User.
        from django.contrib.admin.forms import AdminAuthenticationForm
        context = dict(
            self.each_context(request),
            title=_('Log in'),
            app_path=request.get_full_path(),
            username=request.user.get_username(),
        )
        if (REDIRECT_FIELD_NAME not in request.GET and
                REDIRECT_FIELD_NAME not in request.POST):
            context[REDIRECT_FIELD_NAME] = reverse('admin:index', current_app=self.name)
        context.update(extra_context or {})

        defaults = {
            'extra_context': context,
            'authentication_form': self.login_form or AdminAuthenticationForm,
            'template_name': self.login_template or 'admin/login.html',
        }
        request.current_app = self.name
        return LoginView.as_view(**defaults)(request)
开发者ID:AleksejManaev,项目名称:django,代码行数:32,代码来源:sites.py

示例4: login

def login(request):
    """return the django.contrib.auth or the django-allauth login view"""
    if settings.USE_ALL_AUTH:
        # noinspection PyPackageRequirements
        from allauth.account.views import login

        return login(request)
    return LoginView.as_view()(request)
开发者ID:d9pouces,项目名称:django-floor,代码行数:8,代码来源:auth.py

示例5: smart_login

def smart_login(request):
    pref_cas = request.COOKIES.get('prefer_cas', None)
    use_cas = request.GET.get("force_cas", None)

    next_url = request.GET.get("next", reverse('home'))
    if request.user.is_authenticated:
        return HttpResponseRedirect(next_url)
    if pref_cas == "true" or use_cas == "true" or "ticket" in request.GET:
        return cas_login(request, next_url)
    else:
        return LoginView.as_view(template_name='registration/login.html', authentication_form=forms.LoginForm)(request)
开发者ID:WPI-LNL,项目名称:lnldb,代码行数:11,代码来源:views.py

示例6: dispatch

    def dispatch(self, request, *args, **kwargs):
        if not request.user.is_authenticated:
            login_defaults = {
                'template_name': 'login.html',
                'redirect_field_name': REDIRECT_FIELD_NAME,
                'form_class': LoginForm,
                'extra_context': {
                    'next_value': request.get_full_path(),
                },
                'redirect_authenticated_user': False,
            }
            return LoginView.as_view(**login_defaults)(request)

        self.ensure_required_permission()

        return super().dispatch(request, *args, **kwargs)
开发者ID:deluge,项目名称:terrarium,代码行数:16,代码来源:mixins.py

示例7: login

def login(request, extra_context=None):
    """
    Display the login form.
    """
    if request.method == 'GET' and request.user.is_active:
        index_path = reverse(
            'index', current_app=request.resolver_match.app_name)
        return HttpResponseRedirect(index_path)
    context = {
        'title': _('Log in'),
        'has_permission': request.user.is_active,
    }
    if REDIRECT_FIELD_NAME not in request.GET and REDIRECT_FIELD_NAME not in request.POST:
        context[REDIRECT_FIELD_NAME] = reverse(
            'index', current_app=request.resolver_match.app_name)
    context.update(extra_context or {})
    defaults = view_defaults(context, authentication_form=AuthenticationForm)
    return LoginView.as_view(**defaults)(request)
开发者ID:imdario,项目名称:shipanaro,代码行数:18,代码来源:views.py

示例8: path

Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
# from django.contrib.auth import views as auth_views
from django.contrib.auth.views import LoginView
from django.conf import settings
from django.conf.urls.static import static
from django.urls import include, path
from . import views

urlpatterns = [
    path('notes/', include('notes.urls', namespace='notes')),
    # path('login/', auth_views.login, name='login'),
    path('login', LoginView.as_view()),
    path('logout', views.logout_view),
    path('', views.IndexView.as_view()),
    path('api/', include('rest_framework.urls')),
    path('admin/', admin.site.urls),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

handler404 = 'views.note_not_found'
开发者ID:asommer70,项目名称:strangway,代码行数:30,代码来源:urls.py

示例9: path

from django.urls import path
from django.contrib.auth.views import LoginView, LogoutView
from django.views.generic import TemplateView

urlpatterns = [
    path(r"", TemplateView.as_view(template_name="home.html"), name="home"),
    path(r"login/", LoginView.as_view(), name="auth_login"),
    path(r"logout/", LogoutView.as_view(template_name="logout.html"), name="auth_logout"),
]
开发者ID:spapas,项目名称:cookiecutter-django-starter,代码行数:9,代码来源:urls.py

示例10: reverse

from __future__ import unicode_literals, print_function, absolute_import
from django.conf import settings
from django.contrib.auth.views import LoginView, LogoutView
from django.urls import path, reverse
from django.views.generic import RedirectView
from .views import local_admin_login

app_name = "kirppuauth"

_urls = []


if not settings.KIRPPU_USE_SSO:
    _urls.append(path('login/', LoginView.as_view(
        template_name="kirppuauth/login.html",
        extra_context={
            "ask_pass": True,
            "submit": lambda: reverse('kirppuauth:local_login'),
        },
    ), name='local_login'))

_urls.append(path('profile/', RedirectView.as_view(pattern_name="home", permanent=False)))
_urls.append(path('logout/', LogoutView.as_view(next_page="home"), name='local_logout'))

if settings.KIRPPU_SU_AS_USER:
    _urls.append(path('set_user', local_admin_login, name='local_admin_login'))


urlpatterns = _urls
开发者ID:jlaunonen,项目名称:kirppu,代码行数:29,代码来源:urls.py

示例11: path

"""
Definition of urls for $safeprojectname$.
"""

from datetime import datetime
from django.urls import path
from django.contrib import admin
from django.contrib.auth.views import LoginView, LogoutView
from app import forms, views


urlpatterns = [
    path('', views.home, name='home'),
    path('contact/', views.contact, name='contact'),
    path('about/', views.about, name='about'),
    path('login/',
         LoginView.as_view
         (
             template_name='app/login.html',
             authentication_form=forms.BootstrapAuthenticationForm,
             extra_context=
             {
                 'title': 'Log in',
                 'year' : datetime.now().year,
             }
         ),
         name='login'),
    path('logout/', LogoutView.as_view(next_page='/'), name='logout'),
    path('admin/', admin.site.urls),
]
开发者ID:DamirAinullin,项目名称:PTVS,代码行数:30,代码来源:project-urls.py

示例12: url

       name='details',
    ),

    url(regex=r'^(?P<pk>\d+)/settings/avatar',
       view=AvatarView.as_view(),
       name='avatar',
    ),

    url(regex=r'^(?P<pk>\d+)/settings/password',
       view=PasswordView.as_view(),
       name='password',
    ),

    url(
       regex=r'^login/$',
       view=LoginView.as_view(redirect_authenticated_user=True, template_name='login.html'),
       name='login'
    ),

    url(
       regex=r'^logout/$',
       view=logout_then_login,
       kwargs={'login_url': '/accounts/login'},
       name='logout'
    ),

    path('', include('django.contrib.auth.urls')),

    path(
        'reset/<uidb64>/<token>',
        PasswordResetConfirmView.as_view(),
开发者ID:bgroff,项目名称:kala-app,代码行数:31,代码来源:urls.py

示例13: get_context_data

 def get_context_data(self, **kwargs):
     self.context = LoginView.get_context_data(self, **kwargs)
     self.context['form_signup'] = SignUpForm()
     return self.context
开发者ID:solvo,项目名称:organilab,代码行数:4,代码来源:views.py

示例14: url

# -*- coding: utf-8 -*-
from django.conf.urls import url
from django.contrib.auth.views import LoginView, LogoutView, \
    PasswordResetView, PasswordResetDoneView, PasswordResetConfirmView, PasswordResetCompleteView

urlpatterns = (
    # login and logout url
    url(r'^login/$', LoginView.as_view(template_name='login.html'), name='login'),
    # or use logout with template 'logout.html'
    url(r'^logout/$', LogoutView.as_view(), name='logout'),

    # password reset urls
    url(r'^password_reset/$',
        PasswordResetView.as_view(template_name='password_reset.html'),
        name='password_reset'),
    url(r'^password_reset_done/$',
        PasswordResetDoneView.as_view(template_name='password_reset_done.html'),
        name='password_reset_done'),
    url(r'^password_reset_confirm/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>.+)/$',
        PasswordResetConfirmView.as_view(template_name='password_reset_confirm.html'),
        name='password_reset_confirm'),
    url(r'^password_reset_complete/$',
        PasswordResetCompleteView.as_view(template_name='password_reset_complete.html'),
        name='password_reset_complete'),
)
开发者ID:nsupdate-info,项目名称:nsupdate.info,代码行数:25,代码来源:urls.py

示例15: url

urlpatterns = [
    url(r'^blog/(?P<slug>[\w\-]+)/$', blog_detail, name='blog'),
    url(r'^category/(?P<category>[\w\-]+)/(?P<slug>[\w\-]+)/$', instagram_detail, name='instagram'),
    url(r'^category/(?P<category>[\w\-]+)/$', instagram_list, name='instagram-list'),
    url(r'^category/', TemplateView.as_view(template_name='blog/categories.html'), name='instagram-categories'),
    url(r'^article/(?P<slug>[\w\-]+)/$', article, name='article'),
    url(r'^article/$', article_list, name='article-list'),
    url(r'^blog/$', blog_list, name='blog-list'),
    url(r'^$', blog_list, name='home'),
    url(r'^grappelli/', include('grappelli.urls')),
    url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
    url(r'^admin/', include(admin.site.urls)),
    url(r'^comments/', include('django_comments_xtd.urls')),
    url(r'^vote/(?P<app>[\w\-\_]+)/(?P<model>[\w\_]+)/(?P<pk>\d+)/(?P<vote>([01]))/$', vote, name='vote'),
    url(r'^accounts/login/$', LoginView.as_view(), name='login'),
    url(r'^accounts/logout/$', logout, name='logout'),
    url(r'^accounts/profile/$', profile, name='profile'),
    url(r'^accounts/registration/$', registration, name='registration'),
    url(r'^accounts/registration_thanks/$', registration_thanks,
                                            name='registration-thanks'),
    url(r'^tag/(?P<tag>.+)/$', tags, name='tags'),
    url(r'^tag_autocomplite/$', tags_autocomplite, name='tags_autocomplite'),
    url(r'^tag/$', tags, name='tags'),
    url(r'^sitemap\.xml$', sitemap, {'sitemaps': sitemaps},
                        name='django.contrib.sitemaps.views.sitemap'),
    #url(r'^captcha/(?P<code>[\da-f]{32})/$', draw),
    url(r'^captcha/', include('captcha.urls')),
    #url(r'^media/(?P<path>.*)$', 'django.views.static.serve',
    #{'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
    url(r'^laminat/$', laminat, name='laminat'),
开发者ID:Marx86,项目名称:anny_blog,代码行数:30,代码来源:urls.py


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