• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python forms.AuthenticationForm类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: login

def login(request):
    if request.method == 'GET':
        return {'logged_in': request.user.is_authenticated()}

    from users.forms import AuthenticationForm
    form = AuthenticationForm(data=request.POST)
    if form.is_valid():
        auth_login(request, form.get_user())
        return {'ok': True}
    else:
        return {'form_errors': form.errors}
开发者ID:mozilla,项目名称:pto,代码行数:11,代码来源:views.py


示例2: test_only_active

    def test_only_active(self):
        # Verify with active user
        form = AuthenticationForm(data={'username': self.active_user.username,
                                        'password': 'testpass'})
        assert form.is_valid()

        # Verify with inactive user
        form = AuthenticationForm(data={
                'username': self.inactive_user.username,
                'password': 'testpass'})
        assert not form.is_valid()
开发者ID:DWDRAEGER,项目名称:kitsune,代码行数:11,代码来源:test_forms.py


示例3: handle_signin

def handle_signin(request):
    """Helper function that signs a user in."""
    auth.logout(request)
    if request.method == 'POST':
        form = AuthenticationForm(data=request.POST)
        if form.is_valid():
            auth.login(request, form.get_user())
            if request.session.test_cookie_worked():
                request.session.delete_test_cookie()
        return form
    request.session.set_test_cookie()
    return AuthenticationForm()
开发者ID:rossbruniges,项目名称:betafarm,代码行数:12,代码来源:utils.py


示例4: handle_login

def handle_login(request, only_active=True):
    if request.method == 'POST':
        form = AuthenticationForm(data=request.POST, only_active=only_active)
        if form.is_valid():
            auth.login(request, form.get_user())

            if request.session.test_cookie_worked():
                request.session.delete_test_cookie()

        return form

    request.session.set_test_cookie()
    return AuthenticationForm()
开发者ID:LucianU,项目名称:kuma,代码行数:13,代码来源:utils.py


示例5: login_view

def login_view(request):
    if request.method != 'POST':
        form = AuthenticationForm()
    else:
        form = AuthenticationForm(data=request.POST)

        if form.login(request):
            return redirect('home')

    # Render
    context = regular_context(request.user)
    context['form'] = form
    return render(request, 'login.html', context)
开发者ID:dozmus,项目名称:notes,代码行数:13,代码来源:views.py


示例6: test_recaptcha_errors_only

    def test_recaptcha_errors_only(self):
        """Only recaptcha errors should be returned if validation fails.

        We don't want any information on the username/password returned if the
        captcha is incorrect.

        """
        form = AuthenticationForm(
            data={"username": "foo", "password": "barpassword", "recaptcha": ""}, use_recaptcha=True
        )
        form.is_valid()

        assert len(form.errors) == 1
        assert "recaptcha" in form.errors
开发者ID:aniketkudale,项目名称:olympia,代码行数:14,代码来源:test_forms.py


示例7: login

def login(request):
    form = AuthenticationForm()
    if request.method == "POST":
        form = AuthenticationForm(data=request.POST)
        if form.is_valid():
            user = authenticate(username=request.POST["username"], password=request.POST["password"])
            if user is not None:
                if user.is_active:
                    django_login(request, user)
                    if user.is_teacher:
                        return redirect("/courses/")
                    else:
                        return redirect("/courses/s")
    return render(request, "login.html", {"form": form})
开发者ID:ngavrish,项目名称:django-lms,代码行数:14,代码来源:views.py


示例8: test_recaptcha_errors_only

    def test_recaptcha_errors_only(self):
        """Only recaptcha errors should be returned if validation fails.

        We don't want any information on the username/password returned if the
        captcha is incorrect.

        """
        form = AuthenticationForm(data={'username': 'foo',
                                        'password': 'barpassword',
                                        'recaptcha': ''},
                                  use_recaptcha=True)
        form.is_valid()

        assert len(form.errors) == 1
        assert 'recaptcha' in form.errors
开发者ID:ddurst,项目名称:olympia,代码行数:15,代码来源:test_forms.py


示例9: test_only_active

    def test_only_active(self):
        # Verify with active user
        u = User.objects.get(username='rrosario')
        assert u.is_active
        form = AuthenticationForm(data={'username': 'rrosario',
                                        'password': 'testpass'})
        assert form.is_valid()

        # Verify with inactive user
        u.is_active = False
        u.save()
        u = User.objects.get(username='rrosario')
        assert not u.is_active
        form = AuthenticationForm(data={'username': 'rrosario',
                                        'password': 'testpass'})
        assert not form.is_valid()
开发者ID:readevalprint,项目名称:kitsune,代码行数:16,代码来源:test_forms.py


示例10: test_allow_inactive

    def test_allow_inactive(self):
        # Verify with active user
        user = User.objects.get(username='testuser')
        assert user.is_active
        form = AuthenticationForm(only_active=False,
                                  data={'username': 'testuser',
                                        'password': 'testpass'})
        assert form.is_valid()

        # Verify with inactive user
        user.is_active = False
        user.save()
        user = User.objects.get(username='testuser')
        assert not user.is_active
        form = AuthenticationForm(only_active=False,
                                  data={'username': 'testuser',
                                        'password': 'testpass'})
        assert form.is_valid()
开发者ID:pmclanahan,项目名称:kuma,代码行数:18,代码来源:test_forms.py


示例11: home

def home(request):
    if not request.user.is_authenticated():
        form = AuthenticationForm()
        if request.method == 'POST':
            form = AuthenticationForm(data=request.POST)
            if form.is_valid():
                user = authenticate(username=request.POST['username'],
                    password=request.POST['password'])
                if user is not None:
                    if user.is_active:
                        django_login(request, user)
                        if user.is_teacher:
                            return redirect('/courses/')
                        else:
                            return redirect('/courses/s')
        return render(request, 'home.html', {'form': form})
    if request.user.is_teacher:
        return redirect('/courses/')
    return redirect('/courses/s')
开发者ID:IvoSlavchev,项目名称:django-lms,代码行数:19,代码来源:views.py


示例12: login

def login(request):
    """Try to log the user in."""
    next_url = _clean_next_url(request) or settings.LOGIN_REDIRECT_URL
    if request.user.is_authenticated():
        return HttpResponseRedirect(next_url)

    if request.method == 'POST':
        form = AuthenticationForm(data=request.POST)
        if form.is_valid():
            auth.login(request, form.get_user())

            if request.session.test_cookie_worked():
                request.session.delete_test_cookie()

            return HttpResponseRedirect(next_url)
    else:
        form = AuthenticationForm(request)

    request.session.set_test_cookie()

    return jingo.render(request, 'users/login.html',
                        {'form': form, 'next_url': next_url})
开发者ID:pcraciunoiu,项目名称:fastask,代码行数:22,代码来源:views.py


示例13: browserid_register

def browserid_register(request):
    """Handle user creation when assertion is valid, but no existing user"""
    redirect_to = request.session.get(SESSION_REDIRECT_TO,
        getattr(settings, 'LOGIN_REDIRECT_URL', reverse('home')))
    email = request.session.get(SESSION_VERIFIED_EMAIL, None)

    if not email:
        # This is pointless without a verified email.
        return HttpResponseRedirect(redirect_to)

    # Set up the initial forms
    register_form = BrowserIDRegisterForm()
    login_form = AuthenticationForm()

    if request.method == 'POST':

        # If the profile creation form was submitted...
        if 'register' == request.POST.get('action', None):
            register_form = BrowserIDRegisterForm(request.POST)
            if register_form.is_valid():
                try:
                    # If the registration form is valid, then create a new
                    # Django user, a new MindTouch user, and link the two
                    # together.
                    # TODO: This all belongs in model classes
                    username = register_form.cleaned_data['username']

                    user = User.objects.create(username=username, email=email)
                    user.set_unusable_password()
                    user.save()

                    profile = UserProfile.objects.create(user=user)
                    deki_user = DekiUserBackend.post_mindtouch_user(user)
                    profile.deki_user_id = deki_user.id
                    profile.save()

                    user.backend = 'django_browserid.auth.BrowserIDBackend'
                    auth.login(request, user)

                    # Bounce to the newly created profile page, since the user
                    # might want to review & edit.
                    redirect_to = request.session.get(SESSION_REDIRECT_TO,
                                                    profile.get_absolute_url())
                    return set_browserid_explained(
                        _redirect_with_mindtouch_login(redirect_to,
                                                       user.username))
                except MindTouchAPIError:
                    if user:
                        user.delete()
                    return jingo.render(request, '500.html',
                                        {'error_message': "We couldn't "
                                        "register a new account at this time. "
                                        "Please try again later."})

        else:
            # If login was valid, then set to the verified email
            login_form = handle_login(request)
            if login_form.is_valid():
                if request.user.is_authenticated():
                    # Change email to new verified email, for next time
                    user = request.user
                    user.email = email
                    user.save()
                    return _redirect_with_mindtouch_login(redirect_to,
                        login_form.cleaned_data.get('username'),
                        login_form.cleaned_data.get('password'))

    # HACK: Pretend the session was modified. Otherwise, the data disappears
    # for the next request.
    request.session.modified = True

    return jingo.render(request, 'users/browserid_register.html',
                        {'login_form': login_form,
                         'register_form': register_form})
开发者ID:kaiquewdev,项目名称:kuma,代码行数:74,代码来源:views.py


示例14: test_if_not_valid_on_empty_field_except_is_teacher

 def test_if_not_valid_on_empty_field_except_is_teacher(self):
     form_data = {'username': 'example', 'password': ''}
     form = AuthenticationForm(data=form_data)
     self.assertFalse(form.is_valid())
开发者ID:ngavrish,项目名称:django-lms,代码行数:4,代码来源:test_forms.py


示例15: test_if_valid_on_empty_is_teacher

 def test_if_valid_on_empty_is_teacher(self):
     form_data = {'username': 'example', 'is_teacher': '',
         'password': 'example'}
     form = AuthenticationForm(data=form_data)
     self.assertTrue(form.is_valid())
开发者ID:ngavrish,项目名称:django-lms,代码行数:5,代码来源:test_forms.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python forms.LoginForm类代码示例发布时间:2022-05-27
下一篇:
Python users.Users类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap