本文整理汇总了Python中social.apps.django_app.default.models.UserSocialAuth.create_social_auth方法的典型用法代码示例。如果您正苦于以下问题:Python UserSocialAuth.create_social_auth方法的具体用法?Python UserSocialAuth.create_social_auth怎么用?Python UserSocialAuth.create_social_auth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类social.apps.django_app.default.models.UserSocialAuth
的用法示例。
在下文中一共展示了UserSocialAuth.create_social_auth方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _post_save
# 需要导入模块: from social.apps.django_app.default.models import UserSocialAuth [as 别名]
# 或者: from social.apps.django_app.default.models.UserSocialAuth import create_social_auth [as 别名]
def _post_save(sender, instance, **kwargs):
if not hasattr(instance, "auth_identity"):
# not triggered by user.
return
original_instance = getattr(instance, "_original_instance") if hasattr(instance, "_original_instance") else None
auth_identity = getattr(instance, "auth_identity")
if auth_identity:
# add email to email identity and social auth if not exist
EmailIdentity.objects.get_or_create(email=instance.email, user=instance.user)
if not UserSocialAuth.objects.filter(user=instance.user, provider="email", uid=instance.email).exists():
user_social_auth = UserSocialAuth.create_social_auth(instance.user, instance.email, 'email')
user_social_auth.extra_data = {'email': [instance.email]}
user_social_auth.save()
if original_instance and (original_instance.email != instance.email or not auth_identity):
# delete the profile's email from email identity and social auth
EmailIdentity.objects.filter(email=original_instance.email, user=original_instance.user).delete()
UserSocialAuth.objects.filter(provider="email", uid=original_instance.email, user=original_instance.user).delete()
示例2: setUp
# 需要导入模块: from social.apps.django_app.default.models import UserSocialAuth [as 别名]
# 或者: from social.apps.django_app.default.models.UserSocialAuth import create_social_auth [as 别名]
def setUp(self):
user = EmailUser.objects.create(email=REGISTERED_USER_EMAIL)
UserSocialAuth.create_social_auth(user, user.email, 'email')
self.client = Client()
示例3: create_user
# 需要导入模块: from social.apps.django_app.default.models import UserSocialAuth [as 别名]
# 或者: from social.apps.django_app.default.models.UserSocialAuth import create_social_auth [as 别名]
def create_user(**kwargs):
user = EmailUser.objects.create(**kwargs)
UserSocialAuth.create_social_auth(user, user.email, "email")
return user
示例4: _post_save
# 需要导入模块: from social.apps.django_app.default.models import UserSocialAuth [as 别名]
# 或者: from social.apps.django_app.default.models.UserSocialAuth import create_social_auth [as 别名]
def _post_save(sender, instance, **kwargs):
if not hasattr(instance, "auth_identity"):
# not triggered by user.
return
original_instance = getattr(instance, "_original_instance") if hasattr(instance, "_original_instance") else None
auth_identity = getattr(instance, "auth_identity")
if auth_identity:
# add email to email identity and social auth if not exist
EmailIdentity.objects.get_or_create(email=instance.email, user=instance.user)
if not UserSocialAuth.objects.filter(user=instance.user, provider="email", uid=instance.email).exists():
user_social_auth = UserSocialAuth.create_social_auth(instance.user, instance.email, 'email')
user_social_auth.extra_data = {'email': [instance.email]}
user_social_auth.save()
if original_instance and (original_instance.email != instance.email or not auth_identity):
# delete the profile's email from email identity and social auth
EmailIdentity.objects.filter(email=original_instance.email, user=original_instance.user).delete()
UserSocialAuth.objects.filter(provider="email", uid=original_instance.email, user=original_instance.user).delete()
if not original_instance:
address = instance.postal_address
try:
# Check if the user has the same profile address
# Check if there is a user address
oscar_add = UserAddress.objects.get(
line1 = address.line1,
line2 = address.line2,
line3 = address.line3,
line4 = address.locality,
state = address.state,
postcode = address.postcode,
country = Country.objects.get(iso_3166_1_a2=address.country),
user = instance.user
)
if not address.oscar_address:
address.oscar_address = oscar_add
address.save()
elif address.oscar_address.id != oscar_add.id:
address.oscar_address = oscar_add
address.save()
except UserAddress.DoesNotExist:
oscar_address = UserAddress.objects.create(
line1 = address.line1,
line2 = address.line2,
line3 = address.line3,
line4 = address.locality,
state = address.state,
postcode = address.postcode,
country = Country.objects.get(iso_3166_1_a2=address.country),
user = instance.user
)
address.oscar_address = oscar_address
address.save()
# Clear out unused addresses
user = instance.user
user_addr = Address.objects.filter(user=user)
for u in user_addr:
if not u.profiles.all():
u.oscar_address.delete()
u.delete()
示例5: _create_user_social_auth
# 需要导入模块: from social.apps.django_app.default.models import UserSocialAuth [as 别名]
# 或者: from social.apps.django_app.default.models.UserSocialAuth import create_social_auth [as 别名]
def _create_user_social_auth(self, user):
user_social_auth = UserSocialAuth.create_social_auth(user, user.email, 'email')
user_social_auth.extra_data = {'email': [user.email]}
user_social_auth.save()
return user_social_auth