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


Python backends.DekiUserBackend类代码示例

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


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

示例1: profile_detail

def profile_detail(request, username):
    user = get_object_or_404(User, username=username)
    profile = UserProfile.objects.get(user=user)

    try:
        # HACK: This seems like a dirty violation of the DekiWiki auth package
        from dekicompat.backends import DekiUserBackend
        backend = DekiUserBackend()
        deki_user = backend.get_deki_user(profile.deki_user_id)
    except:
        deki_user = None

    sort_order = request.GET.get('sort', 'created')
    queryset = Submission.objects.all_sorted(sort_order)\
            .exclude(hidden=True)\
            .filter(creator=user)
    return object_list(request, queryset,
        extra_context=dict( 
            profile_user=user, 
            profile_deki_user=deki_user
        ),
        paginate_by=25, allow_empty=True,
        template_loader=template_loader,
        template_object_name='submission',
        template_name='demos/profile_detail.html') 
开发者ID:lmorchard,项目名称:mdn,代码行数:25,代码来源:views.py

示例2: test_deki_only_user

    def test_deki_only_user(self, get_current):
        if not settings.DEKIWIKI_ENDPOINT:
            # Skip, if MindTouch API unavailable
            raise SkipTest()

        get_current.return_value.domain = 'testserver.com'
        self.assertRaises(User.DoesNotExist, User.objects.get,
                          username='testaccount')

        if not getattr(settings, 'DEKIWIKI_MOCK', False):
            # HACK: Ensure that expected user details are in MindTouch when not
            # mocking the API
            mt_email = '[email protected]'
            user_xml = MINDTOUCH_USER_XML % dict(username="testaccount",
                    email=mt_email, fullname="None", status="active",
                    language="", timezone="-08:00", role="Contributor")
            DekiUserBackend.put_mindtouch_user(deki_user_id='=testaccount',
                                               user_xml=user_xml)
            passwd_url = '%s/@api/deki/users/%s/password?apikey=%s' % (
                settings.DEKIWIKI_ENDPOINT, '=testaccount',
                settings.DEKIWIKI_APIKEY)
            requests.put(passwd_url, data='theplanet')

        r = self.client.post(reverse('users.pw_reset'),
                             {'email': '[email protected]'})
        eq_(302, r.status_code)
        eq_('http://testserver/en-US/users/pwresetsent', r['location'])
        eq_(1, len(mail.outbox))
        assert mail.outbox[0].subject.find('Password reset') == 0

        u = User.objects.get(username='testaccount')
        assert mail.outbox[0].body.find('pwreset/%s' % int_to_base36(u.id)) > 0
开发者ID:LucianU,项目名称:kuma,代码行数:32,代码来源:test_templates.py

示例3: test_deki_only_user

    def test_deki_only_user(self, get_current):
        get_current.return_value.domain = "testserver.com"
        self.assertRaises(User.DoesNotExist, User.objects.get, username="testaccount")

        if not getattr(settings, "DEKIWIKI_MOCK", False):
            # HACK: Ensure that expected user details are in MindTouch when not
            # mocking the API
            mt_email = "[email protected]"
            user_xml = MINDTOUCH_USER_XML % dict(
                username="testaccount",
                email=mt_email,
                fullname="None",
                status="active",
                language="",
                timezone="-08:00",
                role="Contributor",
            )
            DekiUserBackend.put_mindtouch_user(deki_user_id="=testaccount", user_xml=user_xml)
            passwd_url = "%s/@api/deki/users/%s/password?apikey=%s" % (
                settings.DEKIWIKI_ENDPOINT,
                "=testaccount",
                settings.DEKIWIKI_APIKEY,
            )
            requests.put(passwd_url, data="theplanet")

        r = self.client.post(reverse("users.pw_reset"), {"email": "[email protected]"})
        eq_(302, r.status_code)
        eq_("http://testserver/en-US/users/pwresetsent", r["location"])
        eq_(1, len(mail.outbox))
        assert mail.outbox[0].subject.find("Password reset") == 0

        u = User.objects.get(username="testaccount")
        assert mail.outbox[0].body.find("pwreset/%s" % int_to_base36(u.id)) > 0
开发者ID:kaiquewdev,项目名称:kuma,代码行数:33,代码来源:test_templates.py

示例4: test_get_or_create_user_already_exists

    def test_get_or_create_user_already_exists(self):
        backend = DekiUserBackend()
        deki_user = DekiUser(13, 'hobo', 'Hobo McKee', '[email protected]', 'http://www.audienceoftwo.com/pics/upload/v1i6hobo.jpg')

        user = backend.get_or_create_user(deki_user)
        self.assertEquals(user.username, 'hobo')
        self.assertEquals(2, user.id)
        self.assertEquals(3, user.get_profile().id)
        self.assertEquals(13, user.get_profile().deki_user_id)
开发者ID:tantek,项目名称:kuma,代码行数:9,代码来源:tests.py

示例5: save

    def save(self, *args, **kwargs):
        skip_mindtouch_put = kwargs.get("skip_mindtouch_put", False)
        if "skip_mindtouch_put" in kwargs:
            del kwargs["skip_mindtouch_put"]
        super(UserProfile, self).save(*args, **kwargs)
        if skip_mindtouch_put:
            return
        from dekicompat.backends import DekiUserBackend

        DekiUserBackend.put_mindtouch_user(self.user)
开发者ID:kaiquewdev,项目名称:kuma,代码行数:10,代码来源:models.py

示例6: save

 def save(self, *args, **kwargs):
     skip_mindtouch_put = kwargs.get('skip_mindtouch_put', False)
     if 'skip_mindtouch_put' in kwargs:
         del kwargs['skip_mindtouch_put']
     super(UserProfile, self).save(*args, **kwargs)
     if skip_mindtouch_put:
         return
     if not settings.DEKIWIKI_ENDPOINT:
         # Skip if the MindTouch API is unavailable
         return
     from dekicompat.backends import DekiUserBackend
     DekiUserBackend.put_mindtouch_user(self.user)
开发者ID:GPHemsley,项目名称:kuma,代码行数:12,代码来源:models.py

示例7: clean_email

 def clean_email(self):
     try:
         return super(PasswordResetForm, self).clean_email()
     except forms.ValidationError as e:
         email = self.cleaned_data["email"]
         deki_user = DekiUserBackend.get_deki_user_by_email(email)
         if deki_user is None:
             raise e
         else:
             user = DekiUserBackend.get_or_create_user(deki_user)
             self.users_cache = User.objects.filter(email__iexact=email)
             return user.email
         raise e
开发者ID:kaiquewdev,项目名称:kuma,代码行数:13,代码来源:forms.py

示例8: browserid_verify

def browserid_verify(request):
    """Process a submitted BrowserID assertion.

    If valid, try to find either a Django or MindTouch user that matches the
    verified email address. If neither is found, we bounce to a profile
    creation page (ie. browserid_register)."""
    redirect_to = (_clean_next_url(request) or
            getattr(settings, 'LOGIN_REDIRECT_URL', reverse('home')))
    redirect_to_failure = (_clean_next_url(request) or
            getattr(settings, 'LOGIN_REDIRECT_URL_FAILURE', reverse('home')))

    failure_resp = set_browserid_explained(
        HttpResponseRedirect(redirect_to_failure))

    # If the form's not valid, then this is a failure.
    form = BrowserIDForm(data=request.POST)
    if not form.is_valid():
        return failure_resp

    # If the BrowserID assersion is not valid, then this is a failure.
    result = _verify_browserid(form, request)
    if not result:
        return failure_resp

    # So far, so good: We have a verified email address. But, no user, yet.
    email = result['email']
    user = None

    # Look for first most recently used Django account, use if found.
    user = _get_latest_user_with_email(email)
    # If no Django account, look for a MindTouch account by email. But, only if
    # there's a MindTouch API available. If found, auto-create the user.
    if not user and settings.DEKIWIKI_ENDPOINT:
        deki_user = DekiUserBackend.get_deki_user_by_email(email)
        if deki_user:
            user = DekiUserBackend.get_or_create_user(deki_user)

    # If we got a user from either the Django or MT paths, complete login for
    # Django and MT and redirect.
    if user:
        user.backend = 'django_browserid.auth.BrowserIDBackend'
        auth.login(request, user)
        return set_browserid_explained(
            _redirect_with_mindtouch_login(redirect_to, user.username))

    # Retain the verified email in a session, redirect to registration page.
    request.session[SESSION_VERIFIED_EMAIL] = email
    request.session[SESSION_REDIRECT_TO] = redirect_to
    return set_browserid_explained(
        HttpResponseRedirect(reverse('users.browserid_register')))
开发者ID:Web5design,项目名称:kuma,代码行数:50,代码来源:views.py

示例9: test_mindtouch_creds_create_user_and_profile

    def test_mindtouch_creds_create_user_and_profile(self, get_current):
        if not settings.DEKIWIKI_ENDPOINT:
            # Don't even bother with this test, if there's no MindTouch API
            raise SkipTest()

        get_current.return_value.domain = "dev.mo.org"

        if not getattr(settings, "DEKIWIKI_MOCK", False):
            # HACK: Ensure that expected user details are in MindTouch when not
            # mocking the API
            mt_email = "[email protected]"
            user_xml = MINDTOUCH_USER_XML % dict(
                username="testaccount",
                email=mt_email,
                fullname="None",
                status="active",
                language="",
                timezone="-08:00",
                role="Contributor",
            )
            DekiUserBackend.put_mindtouch_user(deki_user_id="=testaccount", user_xml=user_xml)
            passwd_url = "%s/@api/deki/users/%s/password?apikey=%s" % (
                settings.DEKIWIKI_ENDPOINT,
                "=testaccount",
                settings.DEKIWIKI_APIKEY,
            )
            requests.put(passwd_url, data="theplanet")

        self.assertRaises(User.DoesNotExist, User.objects.get, username="testaccount")

        # Try to log in as a MindTouch user
        response = self.client.post(
            reverse("users.login"), {"username": "testaccount", "password": "theplanet"}, follow=True
        )
        eq_(200, response.status_code)

        # Ensure there are no validation errors
        page = pq(response.content)
        eq_(0, page.find(".errorlist").length, "There should be no validation errors in login")

        # Login should have auto-created django user
        u = User.objects.get(username="testaccount")
        eq_(True, u.is_active)
        ok_(u.get_profile())

        # Login page should show welcome back
        doc = pq(response.content)
        eq_("testaccount", doc.find("ul.user-state a:first").text())
开发者ID:sylvesterwillis,项目名称:kuma,代码行数:48,代码来源:test_views.py

示例10: _redirect_with_mindtouch_login

def _redirect_with_mindtouch_login(next_url, username, password=None):
    resp = HttpResponseRedirect(next_url)
    authtoken = DekiUserBackend.mindtouch_login(username, password,
                                                force=True)
    if authtoken:
        resp.set_cookie('authtoken', authtoken)
    return resp
开发者ID:kaiquewdev,项目名称:kuma,代码行数:7,代码来源:views.py

示例11: clean_email

 def clean_email(self):
     try:
         return super(PasswordResetForm, self).clean_email()
     except forms.ValidationError as e:
         if not settings.DEKIWIKI_ENDPOINT:
             # Skip MindTouch API, if unavailable.
             raise e
         email = self.cleaned_data["email"]
         deki_user = DekiUserBackend.get_deki_user_by_email(email)
         if deki_user is None:
             raise e
         else:
             user = DekiUserBackend.get_or_create_user(deki_user)
             self.users_cache = User.objects.filter(email__iexact=email)
             return user.email
         raise e
开发者ID:gerv,项目名称:kuma,代码行数:16,代码来源:forms.py

示例12: clean_username

 def clean_username(self):
     username = self.cleaned_data.get('username')
     # check deki for existing user (it needs = in front of name)
     deki_user = DekiUserBackend.get_deki_user('='+username)
     if deki_user is not None:
         raise forms.ValidationError(_('The username you entered already exists.'))
     return username
开发者ID:pmclanahan,项目名称:kuma,代码行数:7,代码来源:forms.py

示例13: test_valid_assertion_with_mindtouch_user

    def test_valid_assertion_with_mindtouch_user(self, _verify_browserid):
        if not settings.DEKIWIKI_ENDPOINT:
            # Don't even bother with this test, if there's no MindTouch API
            raise SkipTest()

        mt_email = "[email protected]"
        _verify_browserid.return_value = {"email": mt_email}

        # Probably overkill but let's be sure we're testing the right thing.
        try:
            User.objects.get(email=mt_email)
            ok_(False, "The MindTouch user shouldn't exist in Django yet.")
        except User.DoesNotExist:
            pass

        if not getattr(settings, "DEKIWIKI_MOCK", False):
            # HACK: Ensure that expected user details are in MindTouch when not
            # mocking the API
            user_xml = MINDTOUCH_USER_XML % dict(
                username="testaccount",
                email=mt_email,
                fullname="None",
                status="active",
                language="",
                timezone="-08:00",
                role="Contributor",
            )
            DekiUserBackend.put_mindtouch_user(deki_user_id="=testaccount", user_xml=user_xml)

        deki_user = DekiUserBackend.get_deki_user_by_email(mt_email)
        ok_(deki_user is not None, "The MindTouch user should exist")

        # Posting the fake assertion to browserid_verify should work, with the
        # actual verification method mocked out.
        resp = self.client.post(reverse("users.browserid_verify", locale="en-US"), {"assertion": "PRETENDTHISISVALID"})
        eq_(302, resp.status_code)
        ok_("SUCCESS" in resp["Location"])

        # The session should look logged in, now.
        ok_("_auth_user_id" in self.client.session.keys())
        eq_("django_browserid.auth.BrowserIDBackend", self.client.session.get("_auth_user_backend", ""))

        # And, after all the above, there should be a Django user now.
        try:
            User.objects.get(email=mt_email)
        except User.DoesNotExist:
            ok_(False, "The MindTouch user should exist in Django now.")
开发者ID:sylvesterwillis,项目名称:kuma,代码行数:47,代码来源:test_views.py

示例14: clean_username

 def clean_username(self):
     username = self.cleaned_data.get("username")
     if settings.DEKIWIKI_ENDPOINT:
         # Check deki for existing user (it needs = in front of name), but
         # only if the API is available.
         deki_user = DekiUserBackend.get_deki_user("=" + username)
         if deki_user is not None:
             raise forms.ValidationError(_("The username you entered" " already exists."))
     return username
开发者ID:spratt,项目名称:kuma,代码行数:9,代码来源:forms.py

示例15: test_valid_assertion_with_mindtouch_user

    def test_valid_assertion_with_mindtouch_user(self, _verify_browserid):
        mt_email = '[email protected]'
        _verify_browserid.return_value = {'email': mt_email}

        # Probably overkill but let's be sure we're testing the right thing.
        try:
            User.objects.get(email=mt_email)
            ok_(False, "The MindTouch user shouldn't exist in Django yet.")
        except User.DoesNotExist:
            pass

        if not getattr(settings, 'DEKIWIKI_MOCK', False):
            # HACK: Ensure that expected user details are in MindTouch when not
            # mocking the API
            user_xml = MINDTOUCH_USER_XML % dict(username="testaccount",
                    email=mt_email, fullname="None", status="active",
                    language="", timezone="-08:00", role="Contributor")
            DekiUserBackend.put_mindtouch_user(deki_user_id='=testaccount',
                                               user_xml=user_xml)

        deki_user = DekiUserBackend.get_deki_user_by_email(mt_email)
        ok_(deki_user is not None, "The MindTouch user should exist")

        # Posting the fake assertion to browserid_verify should work, with the
        # actual verification method mocked out.
        resp = self.client.post(reverse('users.browserid_verify',
                                        locale='en-US'),
                                {'assertion': 'PRETENDTHISISVALID'})
        eq_(302, resp.status_code)
        ok_('SUCCESS' in resp['Location'])

        # The session should look logged in, now.
        ok_('_auth_user_id' in self.client.session.keys())
        eq_('django_browserid.auth.BrowserIDBackend',
            self.client.session.get('_auth_user_backend', ''))

        # And, after all the above, there should be a Django user now.
        try:
            User.objects.get(email=mt_email)
        except User.DoesNotExist:
            ok_(False, "The MindTouch user should exist in Django now.")
开发者ID:pmclanahan,项目名称:kuma,代码行数:41,代码来源:test_views.py


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