本文整理匯總了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}')
示例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)
示例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'
)
示例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
示例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)
示例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
示例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