本文整理汇总了Python中social.apps.django_app.default.models.UserSocialAuth.get_social_auth方法的典型用法代码示例。如果您正苦于以下问题:Python UserSocialAuth.get_social_auth方法的具体用法?Python UserSocialAuth.get_social_auth怎么用?Python UserSocialAuth.get_social_auth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类social.apps.django_app.default.models.UserSocialAuth
的用法示例。
在下文中一共展示了UserSocialAuth.get_social_auth方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: social_auth_user
# 需要导入模块: from social.apps.django_app.default.models import UserSocialAuth [as 别名]
# 或者: from social.apps.django_app.default.models.UserSocialAuth import get_social_auth [as 别名]
def social_auth_user(strategy, uid, user=None, *args, **kwargs):
"""
Allows user to create a new account and associate a social account,
even if that social account is already connected to a different
user. It effectively 'steals' the social association from the
existing user. This can be a useful option during the testing phase
of a project.
Return UserSocialAuth account for backend/uid pair or None if it
doesn't exist.
Delete UserSocialAuth if UserSocialAuth entry belongs to another
user.
"""
social = UserSocialAuth.get_social_auth(kwargs['backend'].name, uid)
if social:
if user and social.user != user:
# Delete UserSocialAuth pairing so this account can now connect
social.delete()
social = None
elif not user:
user = social.user
return {'social': social,
'user': user,
'is_new': user is None,
'new_association': False}
示例2: get_user_id
# 需要导入模块: from social.apps.django_app.default.models import UserSocialAuth [as 别名]
# 或者: from social.apps.django_app.default.models.UserSocialAuth import get_social_auth [as 别名]
def get_user_id(auth_data):
provider = auth_data['provider']
uid = auth_data['uid']
logger.debug('uid = {}'.format(uid))
user_social_auth = UserSocialAuth.get_social_auth(provider, uid)
if user_social_auth:
user = YMUser.objects.get(id=user_social_auth.user_id)
else:
user = YMUser()
if 'email' in auth_data:
user.email = auth_data['email']
if 'username' in auth_data:
user.username = auth_data['username']
if 'first_name' in auth_data:
user.first_name = auth_data['first_name']
if 'last_name' in auth_data:
user.last_name = auth_data['last_name']
if 'picture' in auth_data:
user.icon_url = auth_data['picture']
if 'locale' in auth_data:
user.locale = auth_data['locale']
# logger.debug('user save called...')
user.save()
if user_social_auth:
return (user.id, False)
user_social_auth = UserSocialAuth(user_id=user.id, provider=provider,
uid=uid, extra_data=auth_data)
user_social_auth.save()
return (user.id, True)
示例3: get_user_id
# 需要导入模块: from social.apps.django_app.default.models import UserSocialAuth [as 别名]
# 或者: from social.apps.django_app.default.models.UserSocialAuth import get_social_auth [as 别名]
def get_user_id(auth_data):
provider = auth_data['provider']
uid = auth_data['uid']
user = UserSocialAuth.get_social_auth(provider, uid)
if user: return user.id
user = YMUser()
if 'email' in auth_data: user.email = auth_data['email']
if 'username' in auth_data: user.username = auth_data['username']
if 'first_name' in auth_data: user.first_name = auth_data['first_name']
if 'last_name' in auth_data: user.last_name = auth_data['last_name']
user.save()
user_social_auth = UserSocialAuth(user_id = user.id, provider = provider,
uid = uid, extra_data = auth_data)
user_social_auth.save()
return user.id
示例4: social_auth_user
# 需要导入模块: from social.apps.django_app.default.models import UserSocialAuth [as 别名]
# 或者: from social.apps.django_app.default.models.UserSocialAuth import get_social_auth [as 别名]
def social_auth_user(strategy, uid, user=None, *args, **kwargs):
"""Return UserSocialAuth account for backend/uid pair or None if it
doesn't exists.
Delete UserSocialAuth if UserSocialAuth entry belongs to another
user.
"""
social = UserSocialAuth.get_social_auth(strategy.backend.name, uid)
if social:
if user and social.user != user:
# Delete UserSocialAuth pairing so this account can now connect
social.delete()
social = None
elif not user:
user = social.user
return {'social': social,
'user': user,
'is_new': user is None,
'new_association': False}
示例5: load_extra_data
# 需要导入模块: from social.apps.django_app.default.models import UserSocialAuth [as 别名]
# 或者: from social.apps.django_app.default.models.UserSocialAuth import get_social_auth [as 别名]
def load_extra_data(backend, details, response, uid, user, social_user=None, *args, **kwargs):
"""
Load extra data from provider and store it on current UserSocialAuth extra_data field.
"""
social_user = social_user or UserSocialAuth.get_social_auth(backend.name, uid)
# create verified email address
if kwargs['is_new'] and EMAIL_CONFIRMATION:
from ..models import EmailAddress
# check if email exist before creating it
# we might be associating an exisiting user
if EmailAddress.objects.filter(email=user.email).count() < 1:
EmailAddress.objects.create(user=user,
email=user.email,
verified=True,
primary=True)
if social_user:
extra_data = backend.extra_data(user, uid, response, details)
if kwargs.get('original_email') and 'email' not in extra_data:
extra_data['email'] = kwargs.get('original_email')
# update extra data if anything has changed
if extra_data and social_user.extra_data != extra_data:
if social_user.extra_data:
social_user.extra_data.update(extra_data)
else:
social_user.extra_data = extra_data
social_user.save()
# fetch additional data from facebook on creation
if backend.name == 'facebook' and kwargs['is_new']:
response = json.loads(requests.get('https://graph.facebook.com/%s?access_token=%s' % (extra_data['id'], extra_data['access_token'])).content)
try:
user.city, user.country = response.get('hometown').get('name').split(', ')
except AttributeError:
pass
try:
user.birth_date = datetime.strptime(response.get('birthday'), '%m/%d/%Y').date()
except AttributeError:
pass
user.save()
return {'social_user': social_user}
示例6: youtube_embed_url
# 需要导入模块: from social.apps.django_app.default.models import UserSocialAuth [as 别名]
# 或者: from social.apps.django_app.default.models.UserSocialAuth import get_social_auth [as 别名]
def youtube_embed_url(user):
try:
return UserSocialAuth.get_social_auth('google-oauth2',user.email).extra_data['image']['url']
except:
return '/static/global/images/placeholder/user.png'