當前位置: 首頁>>代碼示例>>Python>>正文


Python models.SocialAccount方法代碼示例

本文整理匯總了Python中allauth.socialaccount.models.SocialAccount方法的典型用法代碼示例。如果您正苦於以下問題:Python models.SocialAccount方法的具體用法?Python models.SocialAccount怎麽用?Python models.SocialAccount使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在allauth.socialaccount.models的用法示例。


在下文中一共展示了models.SocialAccount方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _log_social_login

# 需要導入模塊: from allauth.socialaccount import models [as 別名]
# 或者: from allauth.socialaccount.models import SocialAccount [as 別名]
def _log_social_login(self, sociallogin: SocialLogin):
        # TODO: remove emails from log message
        emails = []
        if sociallogin.email_addresses:
            email: EmailAddress
            for email in sociallogin.email_addresses:
                if email.verified:
                    emails.append(f'{email.email} verified')
                else:
                    emails.append(f'{email.email} not-verified')
        emails = '[{}]'.format(', '.join(emails))
        if sociallogin.account:
            sa: SocialAccount = sociallogin.account
            account = f'[{sa.provider} pk={sa.pk}]'
        else:
            account = None
        if sociallogin.user:
            su: User = sociallogin.user
            user = f'[{su.username} email={su.email} pk={su.pk}]'
        else:
            user = None
        process = sociallogin.state.get('process')
        LOG.info(f'social-login account={account} user={user} emails={emails} process={process}') 
開發者ID:anyant,項目名稱:rssant,代碼行數:25,代碼來源:auth.py

示例2: post

# 需要導入模塊: from allauth.socialaccount import models [as 別名]
# 或者: from allauth.socialaccount.models import SocialAccount [as 別名]
def post(self, request, *args, **kwargs):
        accounts = self.get_queryset()
        account = accounts.filter(pk=kwargs['pk']).first()
        if not account:
            raise NotFound

        get_social_adapter(self.request).validate_disconnect(account, accounts)

        account.delete()
        signals.social_account_removed.send(
            sender=SocialAccount,
            request=self.request,
            socialaccount=account
        )

        return Response(self.get_serializer(account).data) 
開發者ID:Tivix,項目名稱:django-rest-auth,代碼行數:18,代碼來源:views.py

示例3: test_get_gravatar_url

# 需要導入模塊: from allauth.socialaccount import models [as 別名]
# 或者: from allauth.socialaccount.models import SocialAccount [as 別名]
def test_get_gravatar_url(self):
        user = mommy.make(User, email='fake@email.com')
        mommy.make(SocialAccount, user=user, uid="12345")

        self.assertEqual(
            user.get_gravatar_url(),
            'https://avatars3.githubusercontent.com/u/12345?v=3&s=96'
        ) 
開發者ID:codesy,項目名稱:codesy,代碼行數:10,代碼來源:model_tests.py

示例4: _create_social_user

# 需要導入模塊: from allauth.socialaccount import models [as 別名]
# 或者: from allauth.socialaccount.models import SocialAccount [as 別名]
def _create_social_user(self):
        u = get_user_model().objects.create(username='socialuser',
                                            email='test@test.org')
        u.set_unusable_password()
        u.save()
        sa = SocialAccount(user=u,
                           provider='facebook',
                           uid='12345',
                           extra_data='{}')
        sa.full_clean()
        sa.save()
        return u 
開發者ID:openwisp,項目名稱:django-freeradius,代碼行數:14,代碼來源:test_social.py

示例5: get_queryset

# 需要導入模塊: from allauth.socialaccount import models [as 別名]
# 或者: from allauth.socialaccount.models import SocialAccount [as 別名]
def get_queryset(self):
        return SocialAccount.objects.filter(user=self.request.user) 
開發者ID:Tivix,項目名稱:django-rest-auth,代碼行數:4,代碼來源:views.py

示例6: _create_social_user

# 需要導入模塊: from allauth.socialaccount import models [as 別名]
# 或者: from allauth.socialaccount.models import SocialAccount [as 別名]
def _create_social_user(self):
        u = User.objects.create(username='socialuser', email='test@test.org')
        u.set_unusable_password()
        u.save()
        sa = SocialAccount(user=u, provider='facebook', uid='12345', extra_data='{}')
        sa.full_clean()
        sa.save()
        return u 
開發者ID:openwisp,項目名稱:openwisp-radius,代碼行數:10,代碼來源:test_social.py

示例7: dispatch

# 需要導入模塊: from allauth.socialaccount import models [as 別名]
# 或者: from allauth.socialaccount.models import SocialAccount [as 別名]
def dispatch(self, request, *args, **kwargs):
        """
        Override allauth's dispatch method to transparently just login if
        the email already exists.  By doing this in dispatch, we can check for
        existing email, and if a match is found, associate the social account
        with that user and log them in.  Allauth does not provide a mechanism
        for doing precisely this.
        """
        ret = super().dispatch(request, *args, **kwargs)
        # By calling super().dispatch first, we set self.sociallogin
        try:
            # The email is contained in sociallogin.account.extra_data
            extra_data = self.sociallogin.account.extra_data
        except AttributeError:
            return ret
        # extract email
        email = extra_data["email"]
        if email_address_exists(email):
            # check that email exists.
            # If the email does exist, and there is a social account associated
            # with the user, then we don't have to do anything else
            if not self.sociallogin.is_existing:
                # However, if the email exists, and there isn't a social
                # account associated with that user, we need to associate the
                # social account
                # Allauth would perform this as part of the form.save step, but
                # we are entirely bypassing the form.
                account_emailaddress = EmailAddress.objects.get(email=email)
                self.sociallogin.user = account_emailaddress.user
                # allauth (and us) uses the sociallogin user as a temporary
                # holding space, and it already is largely filled out by
                # allauth; we just need to set the user.
                # This model does not get saved to the database.

                # We're trusting social provided emails already
                account_emailaddress.verified = True
                account_emailaddress.save()
                if not SocialAccount.objects.filter(
                    uid=self.sociallogin.account.uid,
                    provider=self.sociallogin.account.provider,
                ).exists():
                    # just to be on the safe side, double check that the account
                    # does not exist in the database and that the provider is
                    # valid.
                    socialaccount = SocialAccount()
                    socialaccount.uid = self.sociallogin.account.uid
                    socialaccount.provider = self.sociallogin.account.provider
                    socialaccount.extra_data = extra_data
                    socialaccount.user = self.sociallogin.user
                    socialaccount.save()
                return complete_social_login(request, self.sociallogin)

        return ret 
開發者ID:OpenHumans,項目名稱:open-humans,代碼行數:55,代碼來源:account_views.py


注:本文中的allauth.socialaccount.models.SocialAccount方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。