本文整理汇总了Python中social_auth.models.UserSocialAuth.extra_data方法的典型用法代码示例。如果您正苦于以下问题:Python UserSocialAuth.extra_data方法的具体用法?Python UserSocialAuth.extra_data怎么用?Python UserSocialAuth.extra_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类social_auth.models.UserSocialAuth
的用法示例。
在下文中一共展示了UserSocialAuth.extra_data方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _googleAuth
# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import extra_data [as 别名]
def _googleAuth(user):
google_auth = UserSocialAuth()
google_auth.user = user
google_auth.provider = 'google'
google_auth.uid = user.email
google_auth.extra_data = '{}'
return google_auth
示例2: authenticate
# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import extra_data [as 别名]
def authenticate(self, *args, **kwargs):
"""Authenticate user using social credentials
Authentication is made if this is the correct backend, backend
verification is made by kwargs inspection for current backend
name presence.
"""
# Validate backend and arguments. Require that the Social Auth
# response be passed in as a keyword argument, to make sure we
# don't match the username/password calling conventions of
# authenticate.
if not (self.name and kwargs.get(self.name) and 'response' in kwargs):
return None
response = kwargs.get('response')
details = self.get_user_details(response)
uid = self.get_user_id(details, response)
is_new = False
user = kwargs.get('user')
try:
social_user = self.get_social_auth_user(uid)
except UserSocialAuth.DoesNotExist:
if user is None and HOLD_SOCIAL_USER and not CREATE_USERS:
# create fake user, and create social user in session
user = User()
user.is_fake = True
social_user = UserSocialAuth(user=user, uid=uid, provider=self.name)
user.social_user = social_user
if LOAD_EXTRA_DATA:
extra_data = self.extra_data(user, uid, response, details)
if extra_data and social_user.extra_data != extra_data:
social_user.extra_data = extra_data
# todo: get request
#self.request.session[SESSION_USER_NAME] = UserSocialAuth.objects.get(id=social_user.id)
#request.session['tmpUserProfile'] = user.get_profile()
# sending pre_update signal
self.update_user_details(user, response, details, is_new)
return user
if user is None: # new user
if not CREATE_USERS or not kwargs.get('create_user', True):
# Send signal for cases where tracking failed registering
# is useful.
socialauth_not_registered.send(sender=self.__class__,
uid=uid,
response=response,
details=details)
return None
email = details.get('email')
if email and ASSOCIATE_BY_MAIL:
# try to associate accounts registered with the same email
# address, only if it's a single object. ValueError is
# raised if multiple objects are returned
try:
user = User.objects.get(email=email)
except MultipleObjectsReturned:
raise ValueError('Not unique email address supplied')
except User.DoesNotExist:
user = None
if not user:
username = self.username(details)
user = User.objects.create_user(username=username,
email=email)
is_new = True
try:
social_user = self.associate_auth(user, uid, response, details)
except IntegrityError:
# Protect for possible race condition, those bastard with FTL
# clicking capabilities
social_user = self.get_social_auth_user(uid)
# Raise ValueError if this account was registered by another user.
if user and user != social_user.user:
raise ValueError('Account already in use.', social_user)
user = social_user.user
# Flag user "new" status
setattr(user, 'is_new', is_new)
# Update extra_data storage, unless disabled by setting
if LOAD_EXTRA_DATA:
extra_data = self.extra_data(user, uid, response, details)
if extra_data and social_user.extra_data != extra_data:
social_user.extra_data = extra_data
social_user.save()
user.social_user = social_user
# Update user account data.
self.update_user_details(user, response, details, is_new)
return user